mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-04 09:06:04 +02:00
Merge pull request #113 from dotnet/publish-27362
Merge master into live
This commit is contained in:
+7
-2
@@ -9,11 +9,13 @@ helpviewer_keywords:
|
||||
ms.assetid: 15abda8b-0527-47c7-aedb-77ab595f2bf1
|
||||
---
|
||||
# Additional Security Considerations in Windows Forms
|
||||
|
||||
.NET Framework security settings might cause your application to run differently in a partial trust environment than on your local computer. The .NET Framework restricts access to such critical local resources as the file system, network, and unmanaged APIs, among other things. The security settings affect the ability to call the Microsoft Windows API or other APIs that cannot be verified by the security system. Security also affects other aspects of your application, including file and data access, and printing. For more information about file and data access in a partial trust environment, see [More Secure File and Data Access in Windows Forms](more-secure-file-and-data-access-in-windows-forms.md). For more information about printing in a partial trust environment, see [More Secure Printing in Windows Forms](more-secure-printing-in-windows-forms.md).
|
||||
|
||||
The following sections discuss how to work with the Clipboard, perform window manipulation, and call the Windows API from applications that are running in a partial trust environment.
|
||||
|
||||
## Clipboard Access
|
||||
|
||||
The <xref:System.Security.Permissions.UIPermission> class controls access to the Clipboard, and the associated <xref:System.Security.Permissions.UIPermissionClipboard> enumeration value indicates the level of access. The following table shows the possible permission levels.
|
||||
|
||||
|UIPermissionClipboard value|Description|
|
||||
@@ -22,9 +24,10 @@ ms.assetid: 15abda8b-0527-47c7-aedb-77ab595f2bf1
|
||||
|<xref:System.Security.Permissions.UIPermissionClipboard.OwnClipboard>|The Clipboard can be used with some restrictions. The ability to put data on the Clipboard (Copy or Cut command operations) is unrestricted. Intrinsic controls that accept paste, such as a text box, can accept Clipboard data, but user controls cannot programmatically read from the Clipboard.|
|
||||
|<xref:System.Security.Permissions.UIPermissionClipboard.NoClipboard>|The Clipboard cannot be used.|
|
||||
|
||||
By default, the Local Intranet zone receives <xref:System.Security.Permissions.UIPermissionClipboard.AllClipboard> access and the Internet zone receives <xref:System.Security.Permissions.UIPermissionClipboard.OwnClipboard> access. This means that the application can copy data to the Clipboard, but the application cannot programmatically paste to or read from the Clipboard. These restrictions prevent programs without full trust from reading content copied to the Clipboard by another application. If your application requires full Clipboard access but you do not have the permissions, you will have to elevate the permissions for your application. For more information about elevating permissions, see [General Security Policy Administration](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ed5htz45(v=vs.100)).
|
||||
By default, the Local Intranet zone receives <xref:System.Security.Permissions.UIPermissionClipboard.AllClipboard> access and the Internet zone receives <xref:System.Security.Permissions.UIPermissionClipboard.OwnClipboard> access. This means that the application can copy data to the Clipboard, but the application cannot programmatically paste to or read from the Clipboard. These restrictions prevent programs without full trust from reading content copied to the Clipboard by another application. If your application requires full Clipboard access but you do not have the permissions, you will have to elevate the permissions for your application. For more information about elevating permissions, see [General Security Policy Administration](/previous-versions/dotnet/netframework-4.0/ed5htz45(v=vs.100)).
|
||||
|
||||
## Window Manipulation
|
||||
|
||||
The <xref:System.Security.Permissions.UIPermission> class also controls permission to perform window manipulation and other UI-related actions, and the associated <xref:System.Security.Permissions.UIPermissionWindow> enumeration value indicates the level of access. The following table shows the possible permission levels.
|
||||
|
||||
By default, the Local Intranet zone receives <xref:System.Security.Permissions.UIPermissionWindow.AllWindows> access and the Internet zone receives <xref:System.Security.Permissions.UIPermissionWindow.SafeTopLevelWindows> access. This means that in the Internet zone, the application can perform most windowing and UI actions, but the window's appearance will be modified. The modified window displays a balloon notification when first run, contains modified title bar text, and requires a close button on the title bar. The balloon notification and the title bar identify to the user of the application that the application is running under partial trust.
|
||||
@@ -59,11 +62,13 @@ ms.assetid: 15abda8b-0527-47c7-aedb-77ab595f2bf1
|
||||
|<xref:System.Windows.Forms.MessageBox>|- Calling the <xref:System.Windows.Forms.Form.Show%2A> method.|
|
||||
|
||||
### Hosting Third-Party Controls
|
||||
|
||||
Another kind of window manipulation can occur if your forms host third-party controls. A third-party control is any custom <xref:System.Windows.Forms.UserControl> that you have not developed and compiled yourself. Although the hosting scenario is hard to exploit, it is theoretically possible for a third-party control to expand its rendering surface to cover the entire area of your form. This control could then mimic a critical dialog box, and request information such as username/password combinations or bank account numbers from your users.
|
||||
|
||||
To limit this potential risk, use third-party controls only from vendors you can trust. If you use third-party controls you have downloaded from an unverifiable source, we recommend that you review the source code for potential exploits. After you've verified that the source is non-malicious, you should compile the assembly yourself to ensure that the source matches the assembly.
|
||||
|
||||
## Windows API Calls
|
||||
|
||||
If your application design requires calling a function from the Windows API, you are accessing unmanaged code. In this case the code's actions to the window or operating system cannot be determined when you are working with Windows API calls or values. The <xref:System.Security.Permissions.SecurityPermission> class and the <xref:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode> value of the <xref:System.Security.Permissions.SecurityPermissionFlag> enumeration control access to unmanaged code. An application can access unmanaged code only when it is granted the <xref:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode> permission. By default, only applications that are running locally can call unmanaged code.
|
||||
|
||||
Some Windows Forms members provide unmanaged access that requires the <xref:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode> permission. The following table lists the members in the <xref:System.Windows.Forms> namespace that require the permission. For more information about the permissions that are required for a member, see the .NET Framework class library documentation.
|
||||
@@ -80,7 +85,7 @@ ms.assetid: 15abda8b-0527-47c7-aedb-77ab595f2bf1
|
||||
|
||||
If your application does not have permission to call unmanaged code, your application must request <xref:System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode> permission, or you must consider alternative ways of implementing features; in many cases, Windows Forms provides a managed alternative to Windows API functions. If no alternative means exist and the application must access unmanaged code, you will have to elevate the permissions for the application.
|
||||
|
||||
Permission to call unmanaged code allows an application to perform most anything. Therefore, permission to call unmanaged code should only be granted for applications that come from a trusted source. Alternatively, depending on the application, the piece of application functionality that makes the call to unmanaged code could be optional, or enabled in the full trust environment only. For more information about dangerous permissions, see [Dangerous Permissions and Policy Administration](https://docs.microsoft.com/dotnet/framework/misc/dangerous-permissions-and-policy-administration). For more information about elevating permissions, see [General Security Policy Administration](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ed5htz45(v=vs.100)).
|
||||
Permission to call unmanaged code allows an application to perform most anything. Therefore, permission to call unmanaged code should only be granted for applications that come from a trusted source. Alternatively, depending on the application, the piece of application functionality that makes the call to unmanaged code could be optional, or enabled in the full trust environment only. For more information about dangerous permissions, see [Dangerous Permissions and Policy Administration](/dotnet/framework/misc/dangerous-permissions-and-policy-administration). For more information about elevating permissions, see [General Security Policy Administration](/previous-versions/dotnet/netframework-4.0/ed5htz45(v=vs.100)).
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+10
-2
@@ -9,6 +9,7 @@ helpviewer_keywords:
|
||||
ms.assetid: c8eb2ad0-fac6-4ea2-9140-675a4a44d562
|
||||
---
|
||||
# Application Settings Architecture
|
||||
|
||||
This topic describes how the Application Settings architecture works, and explores advanced features of the architecture, such as grouped settings and settings keys.
|
||||
|
||||
The application settings architecture supports defining strongly typed settings with either application or user scope, and persisting the settings between application sessions. The architecture provides a default persistence engine for saving settings to and loading them from the local file system. The architecture also defines interfaces for supplying a custom persistence engine.
|
||||
@@ -16,6 +17,7 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
Interfaces are provided that enable custom components to persist their own settings when they are hosted in an application. By using settings keys, components can keep settings for multiple instances of the component separate.
|
||||
|
||||
## Defining Settings
|
||||
|
||||
The application settings architecture is used within both ASP.NET and Windows Forms, and it contains a number of base classes that are shared across both environments. The most important is <xref:System.Configuration.SettingsBase>, which provides access to settings through a collection, and provides low-level methods for loading and saving settings. Each environment implements its own class derived from <xref:System.Configuration.SettingsBase> to provide additional settings functionality for that environment. In a Windows Forms-based application, all application settings must be defined on a class derived from the <xref:System.Configuration.ApplicationSettingsBase> class, which adds the following functionality to the base class:
|
||||
|
||||
- Higher-level loading and saving operations
|
||||
@@ -36,6 +38,7 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
[!code-vb[ApplicationSettings.Create#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/ApplicationSettings.Create/VB/MyAppSettings.vb#1)]
|
||||
|
||||
## Settings Persistence
|
||||
|
||||
The <xref:System.Configuration.ApplicationSettingsBase> class does not itself persist or load settings; this job falls to the settings provider, a class that derives from <xref:System.Configuration.SettingsProvider>. If a derived class of <xref:System.Configuration.ApplicationSettingsBase> does not specify a settings provider through the <xref:System.Configuration.SettingsProviderAttribute>, then the default provider, <xref:System.Configuration.LocalFileSettingsProvider>, is used.
|
||||
|
||||
The configuration system that was originally released with the .NET Framework supports providing static application configuration data through either the local computer's machine.config file or within an `app.`exe.config file that you deploy with your application. The <xref:System.Configuration.LocalFileSettingsProvider> class expands this native support in the following ways:
|
||||
@@ -82,9 +85,10 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
</configuration>
|
||||
```
|
||||
|
||||
For a definition of the elements within the application settings section of a configuration file, see [Application Settings Schema](https://docs.microsoft.com/dotnet/framework/configure-apps/file-schema/application-settings-schema).
|
||||
For a definition of the elements within the application settings section of a configuration file, see [Application Settings Schema](/dotnet/framework/configure-apps/file-schema/application-settings-schema).
|
||||
|
||||
### Settings Bindings
|
||||
|
||||
Application settings uses the Windows Forms data binding architecture to provide two-way communication of settings updates between the settings object and components. If you use Visual Studio to create application settings and assign them to component properties, these bindings are generated automatically.
|
||||
|
||||
You can only bind an application setting to a component that supports the <xref:System.Windows.Forms.IBindableComponent> interface. Also, the component must implement a change event for a specific bound property, or notify application settings that the property has changed through the <xref:System.ComponentModel.INotifyPropertyChanged> interface. If the component does not implement <xref:System.Windows.Forms.IBindableComponent> and you are binding through Visual Studio, the bound properties will be set the first time, but will not update. If the component implements <xref:System.Windows.Forms.IBindableComponent> but does not support property change notifications, the binding will not update in the settings file when the property is changed.
|
||||
@@ -92,6 +96,7 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
Some Windows Forms components, such as <xref:System.Windows.Forms.ToolStripItem>, do not support settings bindings.
|
||||
|
||||
### Settings Serialization
|
||||
|
||||
When <xref:System.Configuration.LocalFileSettingsProvider> must save settings to disk, it performs the following actions:
|
||||
|
||||
1. Uses reflection to examine all of the properties defined on your <xref:System.Configuration.ApplicationSettingsBase> derived class, finding those that are applied with either <xref:System.Configuration.ApplicationScopedSettingAttribute> or <xref:System.Configuration.UserScopedSettingAttribute>.
|
||||
@@ -103,6 +108,7 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
If you implement your own settings class, you can use the <xref:System.Configuration.SettingsSerializeAsAttribute> to mark a setting for either binary or custom serialization using the <xref:System.Configuration.SettingsSerializeAs> enumeration. For more information on creating your own settings class in code, see [How to: Create Application Settings](how-to-create-application-settings.md).
|
||||
|
||||
### Settings File Locations
|
||||
|
||||
The location of the `app`.exe.config and *user*.config files will differ based on how the application is installed. For a Windows Forms-based application copied onto the local computer, `app`.exe.config will reside in the same directory as the base directory of the application's main executable file, and *user*.config will reside in the location specified by the <xref:System.Windows.Forms.Application.LocalUserAppDataPath%2A?displayProperty=nameWithType> property. For an application installed by means of ClickOnce, both of these files will reside in the ClickOnce Data Directory underneath %InstallRoot%\Documents and Settings\\*username*\Local Settings.
|
||||
|
||||
The storage location of these files is slightly different if a user has enabled roaming profiles, which enables a user to define different Windows and application settings when they are using other computers within a domain. In that case, both ClickOnce applications and non-ClickOnce applications will have their `app`.exe.config and *user*.config files stored under %InstallRoot%\Documents and Settings\\*username*\Application Data.
|
||||
@@ -110,11 +116,13 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
For more information about how the Application Settings feature works with the new deployment technology, see [ClickOnce and Application Settings](/visualstudio/deployment/clickonce-and-application-settings). For more information about the ClickOnce Data Directory, see [Accessing Local and Remote Data in ClickOnce Applications](/visualstudio/deployment/accessing-local-and-remote-data-in-clickonce-applications).
|
||||
|
||||
## Application Settings and Security
|
||||
|
||||
Application settings are designed to work in partial trust, a restricted environment that is the default for Windows Forms applications hosted over the Internet or an intranet. No special permissions beyond partial trust are needed to use application settings with the default settings provider.
|
||||
|
||||
When application settings are used in a ClickOnce application, the `user`.config file is stored in the ClickOnce data directory. The size of the application's `user`.config file cannot exceed the data directory quota set by ClickOnce. For more information, see [ClickOnce and Application Settings](/visualstudio/deployment/clickonce-and-application-settings).
|
||||
|
||||
## Custom Settings Providers
|
||||
|
||||
In the Application Settings architecture, there is a loose coupling between the applications settings wrapper class, derived from <xref:System.Configuration.ApplicationSettingsBase>, and the associated settings provider or providers, derived from <xref:System.Configuration.SettingsProvider>. This association is defined only by the <xref:System.Configuration.SettingsProviderAttribute> applied to the wrapper class or its individual properties. If a settings provider is not explicitly specified, the default provider, <xref:System.Configuration.LocalFileSettingsProvider>, is used. As a result, this architecture supports creating and using custom settings providers.
|
||||
|
||||
For example, suppose that you want to develop and use `SqlSettingsProvider`, a provider that will store all settings data in a Microsoft SQL Server database. Your <xref:System.Configuration.SettingsProvider>-derived class would receive this information in its `Initialize` method as a parameter of type <xref:System.Collections.Specialized.NameValueCollection?displayProperty=nameWithType>. You would then implement the <xref:System.Configuration.SettingsProvider.GetPropertyValues%2A> method to retrieve your settings from the data store, and <xref:System.Configuration.SettingsProvider.SetPropertyValues%2A> to save them. Your provider can use the <xref:System.Configuration.SettingsPropertyCollection> supplied to <xref:System.Configuration.SettingsProvider.GetPropertyValues%2A> to determine the property's name, type, and scope, as well as any other settings attributes defined for that property.
|
||||
@@ -148,4 +156,4 @@ This topic describes how the Application Settings architecture works, and explor
|
||||
- [Application Settings Overview](application-settings-overview.md)
|
||||
- [Application Settings for Custom Controls](application-settings-for-custom-controls.md)
|
||||
- [ClickOnce and Application Settings](/visualstudio/deployment/clickonce-and-application-settings)
|
||||
- [Application Settings Schema](https://docs.microsoft.com/dotnet/framework/configure-apps/file-schema/application-settings-schema)
|
||||
- [Application Settings Schema](/dotnet/framework/configure-apps/file-schema/application-settings-schema)
|
||||
|
||||
+3
-1
@@ -9,9 +9,11 @@ helpviewer_keywords:
|
||||
ms.assetid: 64090a34-8556-4904-8ea0-20efe9f8c886
|
||||
---
|
||||
# Application Settings for Windows Forms
|
||||
|
||||
The Applications Settings feature of Windows Forms makes it easy to create, store, and maintain custom application and user preferences on the client. With Application Settings, you can store not only application data such as database connection strings, but also user-specific data, such as toolbar positions and most-recently used lists.
|
||||
|
||||
## In This Section
|
||||
|
||||
[Application Settings Overview](application-settings-overview.md)
|
||||
Discusses how to create and store settings data on behalf of your application and your users.
|
||||
|
||||
@@ -32,7 +34,7 @@ The Applications Settings feature of Windows Forms makes it easy to create, stor
|
||||
|
||||
## Related topics
|
||||
|
||||
[Windows Forms Configuration Section](https://docs.microsoft.com/dotnet/framework/configure-apps/file-schema/winforms/index)
|
||||
[Windows Forms Configuration Section](/dotnet/framework/configure-apps/file-schema/winforms/index)
|
||||
Documents the settings to enable High DPI support in Windows Forms Application starting with the .NET Framework 4.7.
|
||||
|
||||
## See also
|
||||
|
||||
@@ -18,7 +18,8 @@ This article discusses how to create and store settings data on behalf of your a
|
||||
|
||||
Application settings enables developers to save state in their application using very little custom code, and is a replacement for dynamic properties in previous versions of the .NET Framework. Application settings contains many improvements over dynamic properties, which are read-only, late-bound, and require more custom programming. The dynamic property classes have been retained in .NET Framework 2.0, but they are just shell classes that thinly wrap the application settings classes.
|
||||
|
||||
## What Are Application Settings?
|
||||
## What Are Application Settings
|
||||
|
||||
Your Windows Forms applications will often require data that's critical to running the application, but which you don't want to include directly in the application's code. If your application uses a Web Service or a database server, you may want to store this information in a separate file, so that you can change it in the future without recompiling. Similarly, your applications may require storing data that is specific to the current user. Most applications, for example, have user preferences that customize the application's appearance and behavior.
|
||||
|
||||
Application settings addresses both needs by providing an easy way to store both application-scoped and user-scoped settings on the client computer. Using Visual Studio or a code editor, you define a setting for a given property by specifying its name, data type, and scope (application or user). You can even place related settings into named groups for easier use and readability. Once defined, these settings are persisted and read back into memory automatically at run time. A pluggable architecture enables the persistence mechanism to be changed, but by default, the local file system is used.
|
||||
@@ -30,13 +31,15 @@ This article discusses how to create and store settings data on behalf of your a
|
||||
Custom controls can also save their own settings by implementing the <xref:System.Configuration.IPersistComponentSettings> interface, which exposes the <xref:System.Configuration.IPersistComponentSettings.SaveSettings%2A> method. The Windows Forms <xref:System.Windows.Forms.ToolStrip> control implements this interface to save the position of toolbars and toolbar items between application sessions. For more information about custom controls and application settings, see [Application Settings for Custom Controls](application-settings-for-custom-controls.md).
|
||||
|
||||
## Limitations of Application Settings
|
||||
|
||||
You cannot use application settings in an unmanaged application that hosts the .NET Framework. Settings will not work in such environments as Visual Studio add-ins, C++ for Microsoft Office, control hosting in Internet Explorer, or Microsoft Outlook add-ins and projects.
|
||||
|
||||
You currently cannot bind to some properties in Windows Forms. The most notable example is the <xref:System.Windows.Forms.Form.ClientSize%2A> property, as binding to this property would cause unpredictable behavior at run time. You can usually work around these issues by saving and loading these settings programmatically.
|
||||
|
||||
Application settings has no built-in facility for encrypting information automatically. You should never store security-related information, such as database passwords, in clear text. If you want to store such sensitive information, you as the application developer are responsible for making sure it is secure. If you want to store connection strings, we recommend that you use Windows Integrated Security and not resort to hard-coding passwords into the URL. For more information, see [Code Access Security and ADO.NET](https://docs.microsoft.com/dotnet/framework/data/adonet/code-access-security).
|
||||
Application settings has no built-in facility for encrypting information automatically. You should never store security-related information, such as database passwords, in clear text. If you want to store such sensitive information, you as the application developer are responsible for making sure it is secure. If you want to store connection strings, we recommend that you use Windows Integrated Security and not resort to hard-coding passwords into the URL. For more information, see [Code Access Security and ADO.NET](/dotnet/framework/data/adonet/code-access-security).
|
||||
|
||||
## Getting Started with Application Settings
|
||||
|
||||
If you use Visual Studio, you can define settings within the Windows Forms Designer using the **(ApplicationSettings)** property in the **Properties** window. When you define settings this way, Visual Studio automatically creates a custom managed wrapper class that associates each setting with a class property. Visual Studio also takes care of binding the setting to a property on a form or control so that the control's settings are restored automatically when its form is displayed, and saved automatically when the form is closed.
|
||||
|
||||
If you want more detailed control over your settings, you can define your own custom applications settings wrapper class. This is accomplished by deriving a class from <xref:System.Configuration.ApplicationSettingsBase>, adding a property that corresponds to each setting, and applying special attributes to these properties. For details about creating wrapper classes, see [Application Settings Architecture](application-settings-architecture.md).
|
||||
|
||||
+10
-2
@@ -9,13 +9,16 @@ helpviewer_keywords:
|
||||
- "Windows Forms, bi-directional support"
|
||||
---
|
||||
# Bi-Directional Support for Windows Forms Applications
|
||||
|
||||
You can use Visual Studio to create Windows-based applications that support bi-directional (right-to-left) languages such as Arabic and Hebrew. This includes standard forms, dialog boxes, MDI forms, and all the controls you can work with in these forms—that is, all the objects in the <xref:System.Windows.Forms.Control> namespace.
|
||||
|
||||
## Culture Support
|
||||
|
||||
Culture and UI culture settings determine how an application works with dates, times, currency, and other information. Support for culture and UI culture is the same for bi-directional languages as it is for any other languages. For more information, see [Culture-specific classes for global Windows forms and web forms](/visualstudio/ide/globalizing-and-localizing-applications).
|
||||
|
||||
## RightToLeft and RightToLeftLayout Properties
|
||||
The base <xref:System.Windows.Forms.Control> class, from which forms derive, includes a <xref:System.Windows.Forms.Control.RightToLeft%2A> property that you can set to change the reading order of a form and its controls. If you set the form's <xref:System.Windows.Forms.Control.RightToLeft%2A> property, by default controls on the form inherit this setting. However, you can also set the <xref:System.Windows.Forms.Control.RightToLeft%2A> property individually on most controls. Also see [How to: Display Right-to-Left Text in Windows Forms for Globalization](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/7d3337xw(v=vs.100)).
|
||||
|
||||
The base <xref:System.Windows.Forms.Control> class, from which forms derive, includes a <xref:System.Windows.Forms.Control.RightToLeft%2A> property that you can set to change the reading order of a form and its controls. If you set the form's <xref:System.Windows.Forms.Control.RightToLeft%2A> property, by default controls on the form inherit this setting. However, you can also set the <xref:System.Windows.Forms.Control.RightToLeft%2A> property individually on most controls. Also see [How to: Display Right-to-Left Text in Windows Forms for Globalization](/previous-versions/visualstudio/visual-studio-2010/7d3337xw(v=vs.100)).
|
||||
|
||||
The effect of the <xref:System.Windows.Forms.Control.RightToLeft%2A> property can differ from one control to another. In some controls the property only sets the reading order, as in the <xref:System.Windows.Forms.Button>, <xref:System.Windows.Forms.TreeView> and <xref:System.Windows.Forms.ToolTip> controls. In other controls, the <xref:System.Windows.Forms.Control.RightToLeft%2A> property changes both reading order and layout. This includes the <xref:System.Windows.Forms.RadioButton>, <xref:System.Windows.Forms.ComboBox> and <xref:System.Windows.Forms.CheckBox> controls. Other controls require that the <xref:System.Windows.Forms.Form.RightToLeftLayout%2A> property be applied to mirror its layout from right to left. The following table provides details on how the <xref:System.Windows.Forms.Control.RightToLeft%2A> and <xref:System.Windows.Forms.Form.RightToLeftLayout%2A> properties affect individual Windows Forms controls.
|
||||
|
||||
@@ -71,22 +74,27 @@ You can use Visual Studio to create Windows-based applications that support bi-d
|
||||
|<xref:System.Windows.Forms.VScrollBar>|Displayed on the left side instead of right side of scrollable controls|No effect|No|
|
||||
|
||||
## Encoding
|
||||
|
||||
Windows Forms support Unicode, so you can include any character set when you create your bi-directional applications. However, not all Windows Forms controls support Unicode on all platforms.
|
||||
|
||||
## GDI+
|
||||
|
||||
You can use GDI+ to draw text with right-to-left reading order. The <xref:System.Drawing.Graphics.DrawString%2A> method, which is used to draw text, supports a `StringFormat` parameter that you can set to the <xref:System.Drawing.StringFormatFlags.DirectionRightToLeft> member of the <xref:System.Drawing.StringFormatFlags> enumeration in order to reverse the point of origin for the text.
|
||||
|
||||
## Common Dialog Boxes
|
||||
|
||||
System tools such as the File Open dialog box are under the control of Windows. They inherit language elements from the operating system. If you are using a version of Windows with the correct language settings, these dialog boxes will work correctly with bi-directional languages.
|
||||
|
||||
Similarly, message boxes go through the operating system and support bi-directional text. The captions on message box buttons are based on the current language setting. By default, message boxes do not use right-to-left reading order, but you can specify a parameter to change the reading order when the message boxes are displayed.
|
||||
|
||||
## RightToLeft, Scrollbars, and ScrollableControl
|
||||
|
||||
There is currently a limitation in Windows Forms that prevents all classes derived from <xref:System.Windows.Forms.ScrollableControl> from acting properly when both <xref:System.Windows.Forms.Control.RightToLeft%2A> is enabled and <xref:System.Windows.Forms.ScrollableControl.AutoScroll%2A> is set to <xref:System.Windows.Forms.RightToLeft.Yes>. For example, let's say that you place a control such as <xref:System.Windows.Forms.Panel>—or a container class derived from <xref:System.Windows.Forms.Panel> (such as <xref:System.Windows.Forms.FlowLayoutPanel> or <xref:System.Windows.Forms.TableLayoutPanel>)—on your form. If you set <xref:System.Windows.Forms.ScrollableControl.AutoScroll%2A> on the container to <xref:System.Windows.Forms.RightToLeft.Yes> and then set the <xref:System.Windows.Forms.Control.Anchor%2A> property on one or more of the controls inside of the container to <xref:System.Windows.Forms.AnchorStyles.Right>, then no scrollbar ever appears. The class derived from <xref:System.Windows.Forms.ScrollableControl> acts as if <xref:System.Windows.Forms.ScrollableControl.AutoScroll%2A> were set to <xref:System.Windows.Forms.RightToLeft.No>.
|
||||
|
||||
Currently, the only workaround is to nest the <xref:System.Windows.Forms.ScrollableControl> inside another <xref:System.Windows.Forms.ScrollableControl>. For instance, if you need <xref:System.Windows.Forms.TableLayoutPanel> to work in this situation, you can place it inside of a <xref:System.Windows.Forms.Panel> control and set <xref:System.Windows.Forms.ScrollableControl.AutoScroll%2A> on the <xref:System.Windows.Forms.Panel> to <xref:System.Windows.Forms.RightToLeft.Yes>.
|
||||
|
||||
## Mirroring
|
||||
|
||||
*Mirroring* refers to reversing the layout of UI elements so that they flow from right to left. In a mirrored Windows Form, for example, the Minimize, Maximize, and Close buttons appear left-most on the title bar, not right-most.
|
||||
|
||||
Setting a form or control's <xref:System.Windows.Forms.Control.RightToLeft%2A> property to `true` reverses the reading order of elements on a form, but this setting does not reverse the layout to be right-to-left— that is, it does not cause mirroring. For example, setting this property does not move the **Minimize**, **Maximize**, and **Close** buttons in the form's title bar to the left side of the form. Similarly, some controls, such as the <xref:System.Windows.Forms.TreeView> control, require mirroring in order to change their display to be appropriate for Arabic or Hebrew. You can mirror these controls by settings the <xref:System.Windows.Forms.Form.RightToLeftLayout%2A> property.
|
||||
@@ -111,4 +119,4 @@ You can use Visual Studio to create Windows-based applications that support bi-d
|
||||
|
||||
## See also
|
||||
|
||||
- [Bidirectional Support for ASP.NET Web Applications](https://docs.microsoft.com/previous-versions/aspnet/6eedwbtt(v=vs.100))
|
||||
- [Bidirectional Support for ASP.NET Web Applications](/previous-versions/aspnet/6eedwbtt(v=vs.100))
|
||||
|
||||
+3
-1
@@ -10,6 +10,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 87aac8ad-3c04-43b3-9b0c-d0b00df9ee74
|
||||
---
|
||||
# How to: Support COM Interop by Displaying a Windows Form with the ShowDialog Method
|
||||
|
||||
You can resolve Component Object Model (COM) interoperability problems by displaying your Windows Form on a .NET Framework message loop, which is created by using the <xref:System.Windows.Forms.Application.Run%2A?displayProperty=nameWithType> method.
|
||||
|
||||
To make a form work correctly from a COM client application, you must run it on a Windows Forms message loop. To do this, use one of the following approaches:
|
||||
@@ -19,6 +20,7 @@ You can resolve Component Object Model (COM) interoperability problems by displa
|
||||
- Display each Windows Form on a separate thread. For more information, see [How to: Support COM Interop by Displaying Each Windows Form on Its Own Thread](how-to-support-com-interop-by-displaying-each-windows-form-on-its-own-thread.md).
|
||||
|
||||
## Procedure
|
||||
|
||||
Using the <xref:System.Windows.Forms.Form.ShowDialog%2A?displayProperty=nameWithType> method can be the easiest way to display a form on a .NET Framework message loop because, of all the approaches, it requires the least code to implement.
|
||||
|
||||
The <xref:System.Windows.Forms.Form.ShowDialog%2A?displayProperty=nameWithType> method suspends the unmanaged application's message loop and displays the form as a dialog box. Because the host application's message loop has been suspended, the <xref:System.Windows.Forms.Form.ShowDialog%2A?displayProperty=nameWithType> method creates a new .NET Framework message loop to process the form's messages.
|
||||
@@ -33,6 +35,6 @@ You can resolve Component Object Model (COM) interoperability problems by displa
|
||||
|
||||
## See also
|
||||
|
||||
- [Exposing .NET Framework Components to COM](https://docs.microsoft.com/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
- [Exposing .NET Framework Components to COM](/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
- [How to: Support COM Interop by Displaying Each Windows Form on Its Own Thread](how-to-support-com-interop-by-displaying-each-windows-form-on-its-own-thread.md)
|
||||
- [Windows Forms and Unmanaged Applications](windows-forms-and-unmanaged-applications.md)
|
||||
|
||||
+1
-1
@@ -19,6 +19,6 @@ Modifications made to the base form at run time have no affect on inherited form
|
||||
|
||||
## See also
|
||||
|
||||
- [base](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/base)
|
||||
- [base](/dotnet/csharp/language-reference/keywords/base)
|
||||
- [How to: Inherit Windows Forms](how-to-inherit-windows-forms.md)
|
||||
- [Windows Forms Visual Inheritance](windows-forms-visual-inheritance.md)
|
||||
|
||||
@@ -27,7 +27,7 @@ Introduces the `ImeMode` property, which is used to control the type of input a
|
||||
|
||||
## Related sections
|
||||
|
||||
- [Globalizing and localizing .NET applications](https://docs.microsoft.com/dotnet/standard/globalization-localization/index)
|
||||
- [Globalizing and localizing .NET applications](/dotnet/standard/globalization-localization/index)
|
||||
|
||||
- [Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API Using the Designer](/visualstudio/deployment/walkthrough-downloading-satellite-assemblies-on-demand-with-the-clickonce-deployment-api-using-the-designer)
|
||||
|
||||
@@ -35,12 +35,12 @@ Introduces the `ImeMode` property, which is used to control the type of input a
|
||||
|
||||
- [Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API](/visualstudio/deployment/walkthrough-downloading-satellite-assemblies-on-demand-with-the-clickonce-deployment-api)
|
||||
|
||||
- [How to: Set the Culture and UI Culture for Windows Forms Globalization](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/b28bx3bh(v=vs.100))
|
||||
- [How to: Set the Culture and UI Culture for Windows Forms Globalization](/previous-versions/visualstudio/visual-studio-2010/b28bx3bh(v=vs.100))
|
||||
|
||||
- [How to: Create Mirrored Windows Forms and Controls](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/xwbz5ws0(v=vs.100))
|
||||
- [How to: Create Mirrored Windows Forms and Controls](/previous-versions/visualstudio/visual-studio-2010/xwbz5ws0(v=vs.100))
|
||||
|
||||
- [How to: Support Localization on Windows Forms Using AutoSize and the TableLayoutPanel Control](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/1zkt8b33(v=vs.100))
|
||||
- [How to: Support Localization on Windows Forms Using AutoSize and the TableLayoutPanel Control](/previous-versions/visualstudio/visual-studio-2010/1zkt8b33(v=vs.100))
|
||||
|
||||
- [Walkthrough: Localizing Windows Forms](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/y99d1cd3(v=vs.100))
|
||||
- [Walkthrough: Localizing Windows Forms](/previous-versions/visualstudio/visual-studio-2010/y99d1cd3(v=vs.100))
|
||||
|
||||
- [Walkthrough: Creating a Layout That Adjusts Proportion for Localization](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/7k9fa71y(v=vs.100))
|
||||
- [Walkthrough: Creating a Layout That Adjusts Proportion for Localization](/previous-versions/visualstudio/visual-studio-2010/7k9fa71y(v=vs.100))
|
||||
|
||||
+1
-1
@@ -39,6 +39,6 @@ This procedure shows you how to copy a Windows Presentation Foundation (WPF) con
|
||||
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [Migration and Interoperability](https://docs.microsoft.com/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Migration and Interoperability](/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Using WPF Controls](using-wpf-controls.md)
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
|
||||
+3
-1
@@ -10,11 +10,12 @@ helpviewer_keywords:
|
||||
ms.assetid: 1e7aa347-af75-41e5-89ca-f53cab704f72
|
||||
---
|
||||
# How to: Create Application Settings
|
||||
|
||||
Using managed code, you can create new application settings and bind them to properties on your form or your form's controls, so that these settings are loaded and saved automatically at run time.
|
||||
|
||||
In the following procedure, you manually create a wrapper class that derives from <xref:System.Configuration.ApplicationSettingsBase>. To this class you add a publicly accessible property for each application setting that you want to expose.
|
||||
|
||||
You can also perform this procedure using minimal code in the Visual Studio designer. Also see [How to: Create Application Settings Using the Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/wabtadw6(v=vs.100)).
|
||||
You can also perform this procedure using minimal code in the Visual Studio designer. Also see [How to: Create Application Settings Using the Designer](/previous-versions/visualstudio/visual-studio-2010/wabtadw6(v=vs.100)).
|
||||
|
||||
### To create new Application Settings programmatically
|
||||
|
||||
@@ -38,6 +39,7 @@ Using managed code, you can create new application settings and bind them to pro
|
||||
You have now successfully created a new application setting and bound it to the specified property.
|
||||
|
||||
## .NET Framework Security
|
||||
|
||||
The default settings provider, <xref:System.Configuration.LocalFileSettingsProvider>, persists information to configuration files as plain text. This limits security to the file access security provided by the operating system for the current user. Because of this, care must be taken with the information stored in configuration files. For example, one common use for application settings is to store connection strings that point to the application's data store. However, because of security concerns, such strings should not include passwords. For more information about connection strings, see <xref:System.Configuration.SpecialSetting>.
|
||||
|
||||
## See also
|
||||
|
||||
+2
-2
@@ -51,7 +51,7 @@ The easiest way to inherit a form or other object is to use the **Inheritance Pi
|
||||
|
||||
## See also
|
||||
|
||||
- [Inherits Statement](https://docs.microsoft.com/dotnet/visual-basic/language-reference/statements/inherits-statement)
|
||||
- [using](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/using)
|
||||
- [Inherits Statement](/dotnet/visual-basic/language-reference/statements/inherits-statement)
|
||||
- [using](/dotnet/csharp/language-reference/keywords/using)
|
||||
- [Effects of Modifying a Base Form's Appearance](effects-of-modifying-base-form-appearance.md)
|
||||
- [Windows Forms Visual Inheritance](windows-forms-visual-inheritance.md)
|
||||
|
||||
@@ -34,12 +34,12 @@ For more information about inheriting forms at design time using the **Inheritan
|
||||
public class Form2 : Namespace1.Form1
|
||||
```
|
||||
|
||||
When inheriting forms, keep in mind that issues may arise with regard to event handlers being called twice, because each event is being handled by both the base class and the inherited class. For more information on how to avoid this problem, see [Troubleshooting Inherited Event Handlers in Visual Basic](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers).
|
||||
When inheriting forms, keep in mind that issues may arise with regard to event handlers being called twice, because each event is being handled by both the base class and the inherited class. For more information on how to avoid this problem, see [Troubleshooting Inherited Event Handlers in Visual Basic](/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers).
|
||||
|
||||
## See also
|
||||
|
||||
- [Inherits Statement](https://docs.microsoft.com/dotnet/visual-basic/language-reference/statements/inherits-statement)
|
||||
- [Imports Statement (.NET Namespace and Type)](https://docs.microsoft.com/dotnet/visual-basic/language-reference/statements/imports-statement-net-namespace-and-type)
|
||||
- [using](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/using)
|
||||
- [Inherits Statement](/dotnet/visual-basic/language-reference/statements/inherits-statement)
|
||||
- [Imports Statement (.NET Namespace and Type)](/dotnet/visual-basic/language-reference/statements/imports-statement-net-namespace-and-type)
|
||||
- [using](/dotnet/csharp/language-reference/keywords/using)
|
||||
- [Effects of Modifying a Base Form's Appearance](effects-of-modifying-base-form-appearance.md)
|
||||
- [Windows Forms Visual Inheritance](windows-forms-visual-inheritance.md)
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 362427f8-03d4-4826-b49f-60ab066ad322
|
||||
---
|
||||
# How to: Print a Multi-Page Text File in Windows Forms
|
||||
|
||||
It is very common for Windows-based applications to print text. The <xref:System.Drawing.Graphics> class provides methods for drawing objects (graphics or text) to a device, such as a screen or printer.
|
||||
|
||||
> [!NOTE]
|
||||
@@ -42,17 +43,19 @@ It is very common for Windows-based applications to print text. The <xref:System
|
||||
[!code-vb[System.Drawing.Printing.PrintExamples#5](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.Printing.PrintExamples/VB/Form1.vb#5)]
|
||||
|
||||
## Example
|
||||
|
||||
[!code-csharp[System.Drawing.Printing.PrintExamples#0](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.Printing.PrintExamples/CS/Form1.cs#0)]
|
||||
[!code-vb[System.Drawing.Printing.PrintExamples#0](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.Printing.PrintExamples/VB/Form1.vb#0)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- A text file named testPage.txt containing the text to print, located in the root of drive C:\\. Edit the code to print a different file.
|
||||
|
||||
- References to the System, System.Windows.Forms, System.Drawing assemblies.
|
||||
|
||||
- For information about building this example from the command line for Visual Basic or Visual C#, see [Building from the Command Line](https://docs.microsoft.com/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line) or [Command-line Building With csc.exe](https://docs.microsoft.com/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe). You can also build this example in Visual Studio by pasting the code into a new project.
|
||||
- For information about building this example from the command line for Visual Basic or Visual C#, see [Building from the Command Line](/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line) or [Command-line Building With csc.exe](/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe). You can also build this example in Visual Studio by pasting the code into a new project.
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+5
-5
@@ -23,7 +23,7 @@ To make a Windows Form work correctly from a COM client application, you must ru
|
||||
|
||||
There is extensive support for this feature in Visual Studio.
|
||||
|
||||
Also see [Walkthrough: Supporting COM Interop by Displaying Each Windows Form on Its Own Thread](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms233639(v=vs.100)).
|
||||
Also see [Walkthrough: Supporting COM Interop by Displaying Each Windows Form on Its Own Thread](/previous-versions/visualstudio/visual-studio-2010/ms233639(v=vs.100)).
|
||||
|
||||
## Example
|
||||
|
||||
@@ -39,12 +39,12 @@ This approach requires that each instance of a form runs on its own thread by us
|
||||
|
||||
## Compile the code
|
||||
|
||||
Compile the `COMForm`, `Form1`, and `FormManager` types into an assembly called `COMWinform.dll`. Register the assembly for COM interop by using one of the methods described in [Packaging an Assembly for COM](https://docs.microsoft.com/dotnet/framework/interop/packaging-an-assembly-for-co). You can now use the assembly and its corresponding type library (.tlb) file in unmanaged applications. For example, you can use the type library as a reference in a Visual Basic 6.0 executable project.
|
||||
Compile the `COMForm`, `Form1`, and `FormManager` types into an assembly called `COMWinform.dll`. Register the assembly for COM interop by using one of the methods described in [Packaging an Assembly for COM](/dotnet/framework/interop/packaging-an-assembly-for-co). You can now use the assembly and its corresponding type library (.tlb) file in unmanaged applications. For example, you can use the type library as a reference in a Visual Basic 6.0 executable project.
|
||||
|
||||
## See also
|
||||
|
||||
- [Exposing .NET Framework Components to COM](https://docs.microsoft.com/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
- [Packaging an Assembly for COM](https://docs.microsoft.com/dotnet/framework/interop/packaging-an-assembly-for-co)
|
||||
- [Registering Assemblies with COM](https://docs.microsoft.com/dotnet/framework/interop/registering-assemblies-with-co)
|
||||
- [Exposing .NET Framework Components to COM](/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
- [Packaging an Assembly for COM](/dotnet/framework/interop/packaging-an-assembly-for-co)
|
||||
- [Registering Assemblies with COM](/dotnet/framework/interop/registering-assemblies-with-co)
|
||||
- [How to: Support COM Interop by Displaying a Windows Form with the ShowDialog Method](com-interop-by-displaying-a-windows-form-shadow.md)
|
||||
- [Windows Forms and Unmanaged Applications Overview](windows-forms-and-unmanaged-applications-overview.md)
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ The following procedures show how to test for a valid birth date using either th
|
||||
|
||||
-or-
|
||||
|
||||
- If you are a Visual Basic developer and you created your application settings using the Project Designer, you can retrieve your settings by using the [My.Settings Object](https://docs.microsoft.com/dotnet/visual-basic/language-reference/objects/my-settings-object).
|
||||
- If you are a Visual Basic developer and you created your application settings using the Project Designer, you can retrieve your settings by using the [My.Settings Object](/dotnet/visual-basic/language-reference/objects/my-settings-object).
|
||||
|
||||
-or-
|
||||
|
||||
|
||||
+4
-1
@@ -7,9 +7,11 @@ helpviewer_keywords:
|
||||
ms.assetid: babf8af3-8000-46e2-8c68-a42127efabba
|
||||
---
|
||||
# Networking in Windows Forms Applications
|
||||
|
||||
The .NET Framework provides classes for displaying Web pages, downloading Web content, interacting with file transfer protocol (FTP) sites, and consuming Web Services, making it easy to build network functionality into your application. The following resources will help you understand the networking technologies of the .NET Framework and how you can integrate them into Windows Forms.
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.Net>
|
||||
The root namespace for classes in the .NET Framework that handle network connectivity.
|
||||
|
||||
@@ -23,7 +25,8 @@ The .NET Framework provides classes for displaying Web pages, downloading Web co
|
||||
A managed wrapper class for the `WebBrowser` control that is included with Windows.
|
||||
|
||||
## Related Sections
|
||||
[Network Programming in the .NET Framework](https://docs.microsoft.com/dotnet/framework/network-programming/index)
|
||||
|
||||
[Network Programming in the .NET Framework](/dotnet/framework/network-programming/index)
|
||||
An introduction to networking in the .NET Framework.
|
||||
|
||||
[Windows Forms Data Binding](../windows-forms-data-binding.md)
|
||||
|
||||
@@ -19,4 +19,4 @@ You can also use Windows Forms controls in WPF-based applications. For more info
|
||||
|
||||
## See also
|
||||
|
||||
- [WPF and Windows Forms interoperation](https://docs.microsoft.com/dotnet/framework/wpf/advanced/wpf-and-windows-forms-interoperation)
|
||||
- [WPF and Windows Forms interoperation](/dotnet/framework/wpf/advanced/wpf-and-windows-forms-interoperation)
|
||||
|
||||
+1
-1
@@ -130,6 +130,6 @@ A WPF control hosted on a form has the same anchoring and docking behavior as ot
|
||||
- [How to: Anchor and Dock Child Controls in a TableLayoutPanel Control](../controls/how-to-anchor-and-dock-child-controls-in-a-tablelayoutpanel-control.md)
|
||||
- [How to: Align a Control to the Edges of Forms at Design Time](../controls/how-to-align-a-control-to-the-edges-of-forms-at-design-time.md)
|
||||
- [Walkthrough: Arranging Controls on Windows Forms Using Snaplines](../controls/walkthrough-arranging-controls-on-windows-forms-using-snaplines.md)
|
||||
- [Migration and Interoperability](https://docs.microsoft.com/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Migration and Interoperability](/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Using WPF Controls](using-wpf-controls.md)
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
|
||||
+1
-1
@@ -83,6 +83,6 @@ You can assign different WPF content to an <xref:System.Windows.Forms.Integratio
|
||||
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [Migration and Interoperability](https://docs.microsoft.com/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Migration and Interoperability](/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Using WPF Controls](using-wpf-controls.md)
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ This walkthrough will address the five accessibility requirements for the Certif
|
||||
|
||||
For more information, see [Resources for Designing Accessible Applications](/visualstudio/ide/reference/resources-for-designing-accessible-applications).
|
||||
|
||||
For information on supporting varying keyboard layouts, see [Best Practices for Developing World-Ready Applications](https://docs.microsoft.com/dotnet/standard/globalization-localization/best-practices-for-developing-world-ready-apps).
|
||||
For information on supporting varying keyboard layouts, see [Best Practices for Developing World-Ready Applications](/dotnet/standard/globalization-localization/best-practices-for-developing-world-ready-apps).
|
||||
|
||||
## Creating the Project
|
||||
|
||||
@@ -285,7 +285,7 @@ In this application, no information is conveyed by sound alone. If you use sound
|
||||
|
||||
#### To supply information by some other means than sound
|
||||
|
||||
1. Make the title bar flash by using the Windows API function FlashWindow. For an example of how to call Windows API functions, see [Walkthrough: Calling Windows APIs](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/com-interop/walkthrough-calling-windows-apis).
|
||||
1. Make the title bar flash by using the Windows API function FlashWindow. For an example of how to call Windows API functions, see [Walkthrough: Calling Windows APIs](/dotnet/visual-basic/programming-guide/com-interop/walkthrough-calling-windows-apis).
|
||||
|
||||
> [!NOTE]
|
||||
> The user may have the Windows SoundSentry service enabled, which will also cause the window to flash when the system sounds are played through the computer's built-in speaker.
|
||||
|
||||
+3
-3
@@ -90,9 +90,9 @@ To add a WPF control to a Windows Form:
|
||||
|
||||
Windows Forms and WPF are different technologies, but they are designed to interoperate closely. To provide richer appearance and behavior in your applications, try the following:
|
||||
|
||||
- Host a Windows Forms control in a WPF page. For more information, see [Walkthrough: Hosting a Windows Forms Control in WPF](https://docs.microsoft.com/dotnet/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf).
|
||||
- Host a Windows Forms control in a WPF page. For more information, see [Walkthrough: Hosting a Windows Forms Control in WPF](/dotnet/framework/wpf/advanced/walkthrough-hosting-a-windows-forms-control-in-wpf).
|
||||
|
||||
- Apply Windows Forms visual styles to your WPF content. For more information, see [How to: Enable Visual Styles in a Hybrid Application](https://docs.microsoft.com/dotnet/framework/wpf/advanced/how-to-enable-visual-styles-in-a-hybrid-application).
|
||||
- Apply Windows Forms visual styles to your WPF content. For more information, see [How to: Enable Visual Styles in a Hybrid Application](/dotnet/framework/wpf/advanced/how-to-enable-visual-styles-in-a-hybrid-application).
|
||||
|
||||
- Change the style of your WPF content. For more information, see [Walkthrough: Styling WPF Content](walkthrough-styling-wpf-content.md).
|
||||
|
||||
@@ -100,6 +100,6 @@ Windows Forms and WPF are different technologies, but they are designed to inter
|
||||
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [Migration and Interoperability](https://docs.microsoft.com/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Migration and Interoperability](/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Using WPF Controls](using-wpf-controls.md)
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
|
||||
@@ -55,7 +55,7 @@ You can apply different styling to a WPF control to change its appearance and be
|
||||
|
||||
`UserControl1` opens in the WPF Designer.
|
||||
|
||||
1. In XAML view, insert the following XAML after the `<UserControl>` opening tag. This XAML creates a gradient with a contrasting gradient border. When the control is clicked, the gradients are changed to generate a pressed button look. For more information, see [Styling and Templating](https://docs.microsoft.com/dotnet/desktop-wpf/fundamentals/styles-templates-overview).
|
||||
1. In XAML view, insert the following XAML after the `<UserControl>` opening tag. This XAML creates a gradient with a contrasting gradient border. When the control is clicked, the gradients are changed to generate a pressed button look. For more information, see [Styling and Templating](/dotnet/desktop-wpf/fundamentals/styles-templates-overview).
|
||||
|
||||
```xaml
|
||||
<UserControl.Resources>
|
||||
@@ -132,8 +132,8 @@ You can apply different styling to a WPF control to change its appearance and be
|
||||
|
||||
- <xref:System.Windows.Forms.Integration.ElementHost>
|
||||
- <xref:System.Windows.Forms.Integration.WindowsFormsHost>
|
||||
- [Migration and Interoperability](https://docs.microsoft.com/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Migration and Interoperability](/dotnet/framework/wpf/advanced/migration-and-interoperability)
|
||||
- [Using WPF Controls](using-wpf-controls.md)
|
||||
- [Design XAML in Visual Studio](/visualstudio/xaml-tools/designing-xaml-in-visual-studio)
|
||||
- [XAML Overview (WPF)](https://docs.microsoft.com/dotnet/desktop-wpf/fundamentals/xaml)
|
||||
- [Styling and Templating](https://docs.microsoft.com/dotnet/desktop-wpf/fundamentals/styles-templates-overview)
|
||||
- [XAML Overview (WPF)](/dotnet/desktop-wpf/fundamentals/xaml)
|
||||
- [Styling and Templating](/dotnet/desktop-wpf/fundamentals/styles-templates-overview)
|
||||
|
||||
+13
-8
@@ -10,14 +10,16 @@ helpviewer_keywords:
|
||||
ms.assetid: 0a26d99d-8135-4895-8760-c9a2b5f67f14
|
||||
---
|
||||
# Windows Forms and Unmanaged Applications Overview
|
||||
|
||||
Windows Forms applications and controls can interoperate with unmanaged applications, with some caveats. The following sections describe the scenarios and configurations that Windows Forms applications and controls support and those that they do not support.
|
||||
|
||||
## Windows Forms Controls and ActiveX Applications
|
||||
|
||||
With the exception of Microsoft Internet Explorer and Microsoft Foundation Classes (MFC), Windows Forms controls are not supported in applications designed to host ActiveX controls. Other applications and development tools that are capable of hosting ActiveX controls, including the ActiveX test containers from versions of Visual Studio that are earlier than Visual Studio .NET 2003, are not supported hosts for Windows Forms controls.
|
||||
|
||||
These constraints also apply to the use of Windows Forms controls through Component Object Model COM interop. The use of a Windows Forms control through a COM callable wrapper (CCW) is supported only in Internet Explorer. For more information about COM interop, see
|
||||
|
||||
[COM Interop](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/com-interop/index).
|
||||
[COM Interop](/dotnet/visual-basic/programming-guide/com-interop/index).
|
||||
|
||||
The following table shows the available ActiveX hosting support for Windows Forms controls.
|
||||
|
||||
@@ -27,6 +29,7 @@ Windows Forms applications and controls can interoperate with unmanaged applicat
|
||||
|.NET Framework version 1.1 and later|Internet Explorer 5.01 and later versions<br /><br /> Microsoft Foundation Classes (MFC) 7.0 and later|
|
||||
|
||||
## Hosting Windows Forms components as ActiveX controls
|
||||
|
||||
In the .NET Framework 1.1, support was extended to include MFC 7.0 and later versions. This support includes any container that is fully compatible with the MFC 7.0 and later ActiveX control container.
|
||||
|
||||
However, registration of Windows Forms controls as ActiveX controls is not supported. Also, calling the `com.ms.win32.Ole32.CoCreateInstance` method for Windows Forms controls is not supported. Only managed activation of Windows Forms controls is supported. Once you create a Windows Forms control, you can host it in an MFC application just as with an ActiveX control.
|
||||
@@ -34,6 +37,7 @@ Windows Forms applications and controls can interoperate with unmanaged applicat
|
||||
To use Windows Forms controls in your unmanaged application, you must either host the CLR using the unmanaged CLR hosting APIs or use the C++ interop features. Using the C++ interop features is the recommended solution.
|
||||
|
||||
## Windows Forms in COM client applications
|
||||
|
||||
When you open a Windows Form from a COM client application, such as a Visual Basic 6.0 application or an MFC application, the form may behave unexpectedly. For example, when you press the TAB key, the focus does not change from one control to another control. When you press the ENTER key while a command button has focus, the button's <xref:System.Windows.Forms.Control.Click> event is not raised. You may also experience unexpected behavior for keystrokes or mouse activity.
|
||||
|
||||
This behavior occurs because the unmanaged application does not implement the message loop support that Windows Forms requires to work correctly. The message loop provided by the COM client application is fundamentally different from the Windows Forms message loop.
|
||||
@@ -41,6 +45,7 @@ Windows Forms applications and controls can interoperate with unmanaged applicat
|
||||
An application's message loop is an internal program loop that retrieves messages from a thread's message queue, translates them, and then sends them to the application to be handled. The message loop for a Windows Form does not have the same architecture as message loops that earlier applications, such as Visual Basic 6.0 applications and MFC applications, provide. The window messages that are posted to the message loop may be handled differently than the Windows Form expects. Therefore, unexpected behavior may occur. Some keystroke combinations may not work, some mouse activity may not work, or some events may not be raised as expected.
|
||||
|
||||
## Resolving Interoperability Issues
|
||||
|
||||
You can resolve these problems by displaying the form on a .NET Framework message loop, which is created by using the <xref:System.Windows.Forms.Application.Run%2A?displayProperty=nameWithType> method.
|
||||
|
||||
To make a Windows Form work correctly from a COM client application, you must run it on a Windows Forms message loop. To do this, use one of the following approaches:
|
||||
@@ -52,12 +57,12 @@ Windows Forms applications and controls can interoperate with unmanaged applicat
|
||||
## See also
|
||||
|
||||
- [Windows Forms and Unmanaged Applications](windows-forms-and-unmanaged-applications.md)
|
||||
- [COM Interop](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/com-interop/index)
|
||||
- [COM Interoperability in .NET Framework Applications](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/com-interop/com-interoperability-in-net-framework-applications)
|
||||
- [COM Interoperability Samples](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2008/cxcz83xf(v=vs.90))
|
||||
- [Aximp.exe (Windows Forms ActiveX Control Importer)](https://docs.microsoft.com/dotnet/framework/tools/aximp-exe-windows-forms-activex-control-importer)
|
||||
- [Exposing .NET Framework Components to COM](https://docs.microsoft.com/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
- [Packaging an Assembly for COM](https://docs.microsoft.com/dotnet/framework/interop/packaging-an-assembly-for-co)
|
||||
- [Registering Assemblies with COM](https://docs.microsoft.com/dotnet/framework/interop/registering-assemblies-with-co)
|
||||
- [COM Interop](/dotnet/visual-basic/programming-guide/com-interop/index)
|
||||
- [COM Interoperability in .NET Framework Applications](/dotnet/visual-basic/programming-guide/com-interop/com-interoperability-in-net-framework-applications)
|
||||
- [COM Interoperability Samples](/previous-versions/visualstudio/visual-studio-2008/cxcz83xf(v=vs.90))
|
||||
- [Aximp.exe (Windows Forms ActiveX Control Importer)](/dotnet/framework/tools/aximp-exe-windows-forms-activex-control-importer)
|
||||
- [Exposing .NET Framework Components to COM](/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
- [Packaging an Assembly for COM](/dotnet/framework/interop/packaging-an-assembly-for-co)
|
||||
- [Registering Assemblies with COM](/dotnet/framework/interop/registering-assemblies-with-co)
|
||||
- [How to: Support COM Interop by Displaying a Windows Form with the ShowDialog Method](com-interop-by-displaying-a-windows-form-shadow.md)
|
||||
- [How to: Support COM Interop by Displaying Each Windows Form on Its Own Thread](how-to-support-com-interop-by-displaying-each-windows-form-on-its-own-thread.md)
|
||||
|
||||
+6
-2
@@ -10,9 +10,11 @@ helpviewer_keywords:
|
||||
ms.assetid: 81bc100c-fa49-4614-85a6-0f7ab59eac8a
|
||||
---
|
||||
# Windows Forms and Unmanaged Applications
|
||||
|
||||
Windows Forms applications and controls can interoperate with unmanaged applications, with some caveats. The following sections describe the scenarios and configurations that Windows Forms applications and controls support and those that they do not support.
|
||||
|
||||
## In This Section
|
||||
|
||||
[Windows Forms and Unmanaged Applications Overview](windows-forms-and-unmanaged-applications-overview.md)
|
||||
Offers general information about how to use and implement Windows Forms controls that work with unmanaged applications.
|
||||
|
||||
@@ -22,9 +24,10 @@ Windows Forms applications and controls can interoperate with unmanaged applicat
|
||||
[How to: Support COM Interop by Displaying Each Windows Form on Its Own Thread](how-to-support-com-interop-by-displaying-each-windows-form-on-its-own-thread.md)
|
||||
Provides a code example that shows how to run a Windows Form on its own thread.
|
||||
|
||||
Also see [Walkthrough: Supporting COM Interop by Displaying Each Windows Form on Its Own Thread](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms233639(v=vs.100)).
|
||||
Also see [Walkthrough: Supporting COM Interop by Displaying Each Windows Form on Its Own Thread](/previous-versions/visualstudio/visual-studio-2010/ms233639(v=vs.100)).
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.Windows.Forms.Form.ShowDialog%2A?displayProperty=nameWithType>
|
||||
Used to create a separate thread for a Windows Form.
|
||||
|
||||
@@ -35,5 +38,6 @@ Windows Forms applications and controls can interoperate with unmanaged applicat
|
||||
Marshals calls from an unmanaged application to a form.
|
||||
|
||||
## Related Sections
|
||||
[Exposing .NET Framework Components to COM](https://docs.microsoft.com/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
|
||||
[Exposing .NET Framework Components to COM](/dotnet/framework/interop/exposing-dotnet-components-to-co)
|
||||
Offers general information about how to use .NET Framework types in unmanaged applications.
|
||||
|
||||
+6
-3
@@ -12,11 +12,13 @@ helpviewer_keywords:
|
||||
ms.assetid: 857eb737-3602-4d49-bd8b-f70d33ace345
|
||||
---
|
||||
# Windows Forms Visual Inheritance
|
||||
|
||||
Occasionally, you may decide that a project calls for a form similar to one that you have created in a previous project. Or, you may want to create a basic form with settings such as a watermark or certain control layout that you will then use again within a project, with each iteration containing modifications to the original form template. Form inheritance enables you to create a base form and then inherit from it and make modifications while preserving whatever original settings you need.
|
||||
|
||||
You can create derived-class forms programmatically or by using the Visual Inheritance picker.
|
||||
|
||||
## In This Section
|
||||
|
||||
[How to: Inherit Windows Forms](how-to-inherit-windows-forms.md)
|
||||
Gives directions for creating inherited forms in code.
|
||||
|
||||
@@ -33,11 +35,12 @@ Occasionally, you may decide that a project calls for a form similar to one that
|
||||
Gives directions for using the `GenerateMember` and `Modifiers` properties, which are relevant when the Windows Forms Designer generates a member variable for a component.
|
||||
|
||||
## Related Sections
|
||||
[Inheritance basics (Visual Basic)](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/inheritance-basics)
|
||||
|
||||
[Inheritance basics (Visual Basic)](/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/inheritance-basics)
|
||||
Describes how to define Visual Basic classes that serve as the basis for other classes.
|
||||
|
||||
[class](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/class)
|
||||
[class](/dotnet/csharp/language-reference/keywords/class)
|
||||
Describes the C# approach of classes, in which single inheritance is allowed.
|
||||
|
||||
[Troubleshooting Inherited Event Handlers in Visual Basic](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
[Troubleshooting Inherited Event Handlers in Visual Basic](/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
Lists common issues that arise with event handlers in inherited components
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 68be11de-1d5b-430e-901f-cfbe48d14b19
|
||||
---
|
||||
# How to: Add Custom Information to a TreeView or ListView Control (Windows Forms)
|
||||
|
||||
You can create a derived node in a Windows Forms <xref:System.Windows.Forms.TreeView> control or a derived item in a <xref:System.Windows.Forms.ListView> control. Derivation allows you to add any fields you require, as well as custom methods and constructors for handling them. One use of this feature is to attach a Customer object to each tree node or list item. The examples here are for a <xref:System.Windows.Forms.TreeView> control, but the same approach can be used for a <xref:System.Windows.Forms.ListView> control.
|
||||
|
||||
### To derive a tree node
|
||||
@@ -94,7 +95,7 @@ You can create a derived node in a Windows Forms <xref:System.Windows.Forms.Tree
|
||||
"\\TextFile.txt")));
|
||||
```
|
||||
|
||||
2. If you are passed the tree node and it is typed as a <xref:System.Windows.Forms.TreeNode> class, then you will need to cast to your derived class. Casting is an explicit conversion from one type of object to another. For more information on casting, see [Implicit and Explicit Conversions](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions) (Visual Basic), [Casting and type conversions](https://docs.microsoft.com/dotnet/csharp/programming-guide/types/casting-and-type-conversions) (Visual C#), or [Cast Operator: ()](/cpp/cpp/cast-operator-parens) (Visual C++).
|
||||
2. If you are passed the tree node and it is typed as a <xref:System.Windows.Forms.TreeNode> class, then you will need to cast to your derived class. Casting is an explicit conversion from one type of object to another. For more information on casting, see [Implicit and Explicit Conversions](/dotnet/visual-basic/programming-guide/language-features/data-types/implicit-and-explicit-conversions) (Visual Basic), [Casting and type conversions](/dotnet/csharp/programming-guide/types/casting-and-type-conversions) (Visual C#), or [Cast Operator: ()](/cpp/cpp/cast-operator-parens) (Visual C++).
|
||||
|
||||
```vb
|
||||
Public Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ ms.assetid: 4a6d1b34-b696-476b-bf8a-57c6230aa9e1
|
||||
|
||||
You can display data in the Windows Forms <xref:System.Windows.Forms.DataGrid> control in tables and columns by creating <xref:System.Windows.Forms.DataGridTableStyle> objects and adding them to the <xref:System.Windows.Forms.GridTableStylesCollection> object, which is accessed through the <xref:System.Windows.Forms.DataGrid> control's <xref:System.Windows.Forms.DataGrid.TableStyles%2A> property. Each table style displays the contents of whatever data table is specified in the <xref:System.Windows.Forms.DataGridTableStyle.MappingName%2A> property of the <xref:System.Windows.Forms.DataGridTableStyle>. By default, a table style without column styles specified will display all the columns within that data table. You can restrict which columns from the table appear by adding <xref:System.Windows.Forms.DataGridColumnStyle> objects to the <xref:System.Windows.Forms.GridColumnStylesCollection>, which is accessed through the <xref:System.Windows.Forms.DataGridTableStyle.GridColumnStyles%2A> property of each <xref:System.Windows.Forms.DataGridTableStyle>.
|
||||
|
||||
The following procedures require a **Windows Application** project with a form that contains a <xref:System.Windows.Forms.DataGrid> control. For information about how to set up such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). By default in Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox**. For information about adding it, see [How to: Add Items to the Toolbox](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)).
|
||||
The following procedures require a **Windows Application** project with a form that contains a <xref:System.Windows.Forms.DataGrid> control. For information about how to set up such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). By default in Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox**. For information about adding it, see [How to: Add Items to the Toolbox](/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)).
|
||||
|
||||
### To add a table to the DataGrid control in the designer
|
||||
|
||||
|
||||
+5
-1
@@ -9,9 +9,11 @@ helpviewer_keywords:
|
||||
ms.assetid: 2c5640e9-6c6c-49d7-a5e4-a768f6be7853
|
||||
---
|
||||
# Attributes in Windows Forms Controls
|
||||
|
||||
The .NET Framework provides a variety of attributes you can apply to the members of your custom controls and components. Some of these attributes affect the run-time behavior of a class, and others affect the design-time behavior.
|
||||
|
||||
## Attributes for Control and Component Properties
|
||||
|
||||
The following table shows the attributes you can apply to properties or other members of your custom controls and components. For an example that uses many of these attributes, see [How to: Apply Attributes in Windows Forms Controls](how-to-apply-attributes-in-windows-forms-controls.md).
|
||||
|
||||
|Attribute|Description|
|
||||
@@ -32,6 +34,7 @@ The .NET Framework provides a variety of attributes you can apply to the members
|
||||
|<xref:System.ComponentModel.TypeConverterAttribute>|Specifies what type to use as a converter for the object this attribute is bound to.|
|
||||
|
||||
## Attributes for Data Binding Properties
|
||||
|
||||
The following table shows the attributes you can apply to specify how your custom controls and components interact with data binding.
|
||||
|
||||
|Attribute|Description|
|
||||
@@ -43,6 +46,7 @@ The .NET Framework provides a variety of attributes you can apply to the members
|
||||
|<xref:System.ComponentModel.AttributeProviderAttribute>|Enables attribute redirection.|
|
||||
|
||||
## Attributes for Classes
|
||||
|
||||
The following table shows the attributes you can apply to specify the behavior of your custom controls and components at design time.
|
||||
|
||||
|Attribute|Description|
|
||||
@@ -58,5 +62,5 @@ The .NET Framework provides a variety of attributes you can apply to the members
|
||||
|
||||
- <xref:System.Attribute>
|
||||
- [How to: Apply Attributes in Windows Forms Controls](how-to-apply-attributes-in-windows-forms-controls.md)
|
||||
- [Extending Design-Time Support](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120))
|
||||
- [Extending Design-Time Support](/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120))
|
||||
- [Developing Custom Windows Forms Controls with the .NET Framework](developing-custom-windows-forms-controls.md)
|
||||
|
||||
+5
-4
@@ -19,6 +19,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 64e9b3ab-7443-4a77-ab17-b8b8c0cb3f62
|
||||
---
|
||||
# BackgroundWorker Component Overview
|
||||
|
||||
There are many commonly performed operations that can take a long time to execute. For example:
|
||||
|
||||
- Image downloads
|
||||
@@ -47,15 +48,15 @@ There are many commonly performed operations that can take a long time to execut
|
||||
[!code-csharp[System.ComponentModel.BackgroundWorker#5](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CS/fibonacciform.cs#5)]
|
||||
[!code-vb[System.ComponentModel.BackgroundWorker#5](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/VB/fibonacciform.vb#5)]
|
||||
|
||||
For more information on using event handlers, see [Events](https://docs.microsoft.com/dotnet/standard/events/index).
|
||||
For more information on using event handlers, see [Events](/dotnet/standard/events/index).
|
||||
|
||||
> [!CAUTION]
|
||||
> When using multithreading of any sort, you potentially expose yourself to very serious and complex bugs. Consult the [Managed Threading Best Practices](https://docs.microsoft.com/dotnet/standard/threading/managed-threading-best-practices) before implementing any solution that uses multithreading.
|
||||
> When using multithreading of any sort, you potentially expose yourself to very serious and complex bugs. Consult the [Managed Threading Best Practices](/dotnet/standard/threading/managed-threading-best-practices) before implementing any solution that uses multithreading.
|
||||
|
||||
For more information on using the <xref:System.ComponentModel.BackgroundWorker> class, see [How to: Run an Operation in the Background](how-to-run-an-operation-in-the-background.md).
|
||||
|
||||
## See also
|
||||
|
||||
- [Managed Threading](https://docs.microsoft.com/dotnet/standard/threading/index)
|
||||
- [Event-based Asynchronous Pattern Overview](https://docs.microsoft.com/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
- [Managed Threading](/dotnet/standard/threading/index)
|
||||
- [Event-based Asynchronous Pattern Overview](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
- [How to: Implement a Form That Uses a Background Operation](how-to-implement-a-form-that-uses-a-background-operation.md)
|
||||
|
||||
@@ -13,9 +13,11 @@ helpviewer_keywords:
|
||||
ms.assetid: bef7b0ab-ce57-475a-a2d6-fb8a702a9417
|
||||
---
|
||||
# BackgroundWorker Component
|
||||
|
||||
The `BackgroundWorker` component enables your form or control to run an operation asynchronously.
|
||||
|
||||
## In This Section
|
||||
|
||||
[BackgroundWorker Component Overview](backgroundworker-component-overview.md)
|
||||
Describes the `BackgroundWorker` component, which gives you the ability to execute time-consuming operations asynchronously ("in the background"), on a thread different from your application's main UI thread.
|
||||
|
||||
@@ -35,6 +37,7 @@ The `BackgroundWorker` component enables your form or control to run an operatio
|
||||
Demonstrates how to use the `BackgroundWorker` component to download a file on a separate thread.
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.ComponentModel.BackgroundWorker>
|
||||
Describes this class and has links to all its members.
|
||||
|
||||
@@ -45,5 +48,6 @@ The `BackgroundWorker` component enables your form or control to run an operatio
|
||||
Describes the type that holds data for the <xref:System.ComponentModel.BackgroundWorker.ProgressChanged> event.
|
||||
|
||||
## Related Sections
|
||||
[Event-based Asynchronous Pattern Overview](https://docs.microsoft.com/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
|
||||
[Event-based Asynchronous Pattern Overview](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
Describes how the asynchronous pattern makes available the advantages of multithreaded applications while hiding many of the complex issues inherent in multithreaded design.
|
||||
|
||||
+7
-6
@@ -8,11 +8,12 @@ helpviewer_keywords:
|
||||
ms.assetid: f4f46009-cec2-441b-8668-6b5af057558b
|
||||
---
|
||||
# How to: Bind Data to the Windows Forms DataGridView Control Using the Designer
|
||||
|
||||
You can use the designer to connect a <xref:System.Windows.Forms.DataGridView> control to data sources of several different varieties, including databases, business objects, or Web services. When you bind the control to a data source using the designer, the control is automatically bound to a <xref:System.Windows.Forms.BindingSource> component that represents the data source. Additionally, columns are automatically generated in the control to match the schema information provided by the data source.
|
||||
|
||||
After columns have been generated, you can modify them to meet your needs. For example, you can remove or hide columns you are not interested in displaying, you can rearrange the columns, or you can modify the column types. For more information about modifying columns, see the topics listed in the See Also section.
|
||||
|
||||
You can also bind multiple <xref:System.Windows.Forms.DataGridView> controls to related tables to create master/detail relationships. In this configuration, one control displays a parent table and another control displays only those rows from a child table that are related to the current row in the parent table. For more information, see [How to: Display Related Data in a Windows Forms Application](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/57tx3hhe(v=vs.120)).
|
||||
You can also bind multiple <xref:System.Windows.Forms.DataGridView> controls to related tables to create master/detail relationships. In this configuration, one control displays a parent table and another control displays only those rows from a child table that are related to the current row in the parent table. For more information, see [How to: Display Related Data in a Windows Forms Application](/previous-versions/visualstudio/visual-studio-2013/57tx3hhe(v=vs.120)).
|
||||
|
||||
The following procedure requires a **Windows Application** project with a form that contains a <xref:System.Windows.Forms.DataGridView> control or two controls for a master/detail relationship. For information about starting such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md).
|
||||
|
||||
@@ -24,7 +25,7 @@ You can use the designer to connect a <xref:System.Windows.Forms.DataGridView> c
|
||||
|
||||
3. If your project does not already have a data source, click **Add Project Data Source** and follow the steps indicated by the wizard.
|
||||
|
||||
For more information, see [Data Source Configuration Wizard](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/w4dd7z6t(v=vs.120)). Your new data source will appear in the **Choose Data Source** drop-down window. If your new data source contains only one member, such as a single database table, the control will automatically bind to that member. Otherwise, continue to the next step.
|
||||
For more information, see [Data Source Configuration Wizard](/previous-versions/visualstudio/visual-studio-2013/w4dd7z6t(v=vs.120)). Your new data source will appear in the **Choose Data Source** drop-down window. If your new data source contains only one member, such as a single database table, the control will automatically bind to that member. Otherwise, continue to the next step.
|
||||
|
||||
4. Expand the **Other Data Sources** and **Project Data Sources** nodes if they are not already expanded, and then select the data source to bind the control to.
|
||||
|
||||
@@ -33,7 +34,7 @@ You can use the designer to connect a <xref:System.Windows.Forms.DataGridView> c
|
||||
6. To create a master/detail relationship, in the **Choose Data Source** drop-down window for a second <xref:System.Windows.Forms.DataGridView> control, expand the <xref:System.Windows.Forms.BindingSource> created for the parent table, and then select the related child table from the list shown.
|
||||
|
||||
> [!NOTE]
|
||||
> If your project already has a data source, you can also use the **Data Sources** window to create a data form. For more information, see [Data Sources Window](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120)).
|
||||
> If your project already has a data source, you can also use the **Data Sources** window to create a data form. For more information, see [Data Sources Window](/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120)).
|
||||
|
||||
## See also
|
||||
|
||||
@@ -41,7 +42,7 @@ You can use the designer to connect a <xref:System.Windows.Forms.DataGridView> c
|
||||
- <xref:System.Windows.Forms.BindingSource>
|
||||
- <xref:System.Windows.Forms.DataGridView.DataMember%2A?displayProperty=nameWithType>
|
||||
- <xref:System.Windows.Forms.DataGridView.DataSource%2A?displayProperty=nameWithType>
|
||||
- [How to: Connect to Data in a Database](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/fxk9yw1t(v=vs.120))
|
||||
- [How to: Connect to Data in a Database](/previous-versions/visualstudio/visual-studio-2013/fxk9yw1t(v=vs.120))
|
||||
- [How to: Add and Remove Columns in the Windows Forms DataGridView Control Using the Designer](add-and-remove-columns-in-the-datagrid-using-the-designer.md)
|
||||
- [How to: Change the Order of Columns in the Windows Forms DataGridView Control Using the Designer](change-the-order-of-columns-in-the-datagrid-using-the-designer.md)
|
||||
- [How to: Change the Type of a Windows Forms DataGridView Column Using the Designer](change-the-type-of-a-wf-datagridview-column-using-the-designer.md)
|
||||
@@ -50,5 +51,5 @@ You can use the designer to connect a <xref:System.Windows.Forms.DataGridView> c
|
||||
- [How to: Make Columns Read-Only in the Windows Forms DataGridView Control Using the Designer](make-columns-read-only-in-the-datagrid-using-the-designer.md)
|
||||
- [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project)
|
||||
- [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md)
|
||||
- [Data Sources Window](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120))
|
||||
- [How to: Display Related Data in a Windows Forms Application](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/57tx3hhe(v=vs.120))
|
||||
- [Data Sources Window](/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120))
|
||||
- [How to: Display Related Data in a Windows Forms Application](/previous-versions/visualstudio/visual-studio-2013/57tx3hhe(v=vs.120))
|
||||
|
||||
+2
-1
@@ -8,6 +8,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 391ae170-de5c-40f8-8233-91cb2ee4683a
|
||||
---
|
||||
# How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer
|
||||
|
||||
After you have added controls to your form and determined the user interface for your application, you can bind the controls to a data source, so that, at run time, users can alter and save data related to the application.
|
||||
|
||||
Binding a control or series of controls in Windows Forms is most easily accomplished using the <xref:System.Windows.Forms.BindingSource> control as a bridge between the controls on the form and the data source.
|
||||
@@ -55,4 +56,4 @@ After you have added controls to your form and determined the user interface for
|
||||
- <xref:System.Windows.Forms.BindingSource>
|
||||
- <xref:System.Windows.Forms.BindingNavigator>
|
||||
- [Add new data sources](/visualstudio/data-tools/add-new-data-sources)
|
||||
- [Data Sources Window](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120))
|
||||
- [Data Sources Window](/previous-versions/visualstudio/visual-studio-2013/6ckyxa83(v=vs.120))
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ ms.assetid: 4e96e3d0-b1cc-4de1-8774-bc9970ec4554
|
||||
|
||||
You can also bind the grid programmatically, at run time. This is useful when you want to set a data source based on information you get at run time. For example, the application might let the user specify the name of a table to view. It is also necessary in situations where the data source does not exist at design time. This includes data sources such as arrays, collections, untyped datasets, and data readers.
|
||||
|
||||
The following procedure requires a **Windows Application** project with a form containing a <xref:System.Windows.Forms.DataGrid> control. For information about setting up such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). In Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox** by default. For information about adding it, see [How to: Add Items to the Toolbox](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)). Additionally in Visual Studio 2005, you can use the **Data Sources** window for design-time data binding. For more information see [Bind controls to data in Visual Studio](/visualstudio/data-tools/bind-controls-to-data-in-visual-studio).
|
||||
The following procedure requires a **Windows Application** project with a form containing a <xref:System.Windows.Forms.DataGrid> control. For information about setting up such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). In Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox** by default. For information about adding it, see [How to: Add Items to the Toolbox](/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)). Additionally in Visual Studio 2005, you can use the **Data Sources** window for design-time data binding. For more information see [Bind controls to data in Visual Studio](/visualstudio/data-tools/bind-controls-to-data-in-visual-studio).
|
||||
|
||||
## To data-bind the DataGrid control to a single table in the designer
|
||||
|
||||
|
||||
@@ -7,9 +7,11 @@ helpviewer_keywords:
|
||||
ms.assetid: d38bc40c-8040-4f19-9e88-2c665b0ab80b
|
||||
---
|
||||
# Button Control (Windows Forms)
|
||||
|
||||
The Windows Forms `Button` control allows the user to click it to perform an action. The `Button` control can display both text and images. When the button is clicked, it looks as if it is being pushed in and released.
|
||||
|
||||
## In This Section
|
||||
|
||||
[Button Control Overview](button-control-overview-windows-forms.md)
|
||||
Explains what this control is and its key features and properties.
|
||||
|
||||
@@ -28,11 +30,13 @@ The Windows Forms `Button` control allows the user to click it to perform an act
|
||||
Also see [How to: Designate a Windows Forms Button as the Accept Button Using the Designer](designate-a-wf-button-as-the-accept-button-using-the-designer.md) and [How to: Designate a Windows Forms Button as the Cancel Button Using the Designer](designate-a-wf-button-as-the-cancel-button-using-the-designer.md).
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.Windows.Forms.Button> class
|
||||
Describes this class and has links to all its members.
|
||||
|
||||
## Related Sections
|
||||
|
||||
[Controls to Use on Windows Forms](controls-to-use-on-windows-forms.md)
|
||||
Provides a complete list of Windows Forms controls, with links to information on their use.
|
||||
|
||||
Also see [User Input to Dialog Boxes](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/1s9ws53w(v=vs.100)) and [How to: Close Dialog Boxes and Retain User Input](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/65ad5907(v=vs.100)).
|
||||
Also see [User Input to Dialog Boxes](/previous-versions/visualstudio/visual-studio-2010/1s9ws53w(v=vs.100)) and [How to: Close Dialog Boxes and Retain User Input](/previous-versions/visualstudio/visual-studio-2010/65ad5907(v=vs.100)).
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 0c7a6d00-30de-416e-8223-0a81ddb4c1f8
|
||||
---
|
||||
# How to: Change Displayed Data at Run Time in the Windows Forms DataGrid Control
|
||||
|
||||
> [!NOTE]
|
||||
> The <xref:System.Windows.Forms.DataGridView> control replaces and adds functionality to the <xref:System.Windows.Forms.DataGrid> control; however, the <xref:System.Windows.Forms.DataGrid> control is retained for both backward compatibility and future use, if you choose. For more information, see [Differences Between the Windows Forms DataGridView and DataGrid Controls](differences-between-the-windows-forms-datagridview-and-datagrid-controls.md).
|
||||
|
||||
@@ -89,7 +90,7 @@ ms.assetid: 0c7a6d00-30de-416e-8223-0a81ddb4c1f8
|
||||
|
||||
## See also
|
||||
|
||||
- [ADO.NET DataSets](https://docs.microsoft.com/dotnet/framework/data/adonet/ado-net-datasets)
|
||||
- [ADO.NET DataSets](/dotnet/framework/data/adonet/ado-net-datasets)
|
||||
- [How to: Delete or Hide Columns in the Windows Forms DataGrid Control](how-to-delete-or-hide-columns-in-the-windows-forms-datagrid-control.md)
|
||||
- [How to: Add Tables and Columns to the Windows Forms DataGrid Control](how-to-add-tables-and-columns-to-the-windows-forms-datagrid-control.md)
|
||||
- [How to: Bind the Windows Forms DataGrid Control to a Data Source](how-to-bind-the-windows-forms-datagrid-control-to-a-data-source.md)
|
||||
|
||||
+4
-4
@@ -10,6 +10,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 2509302d-a74e-484f-9890-2acdbfa67a68
|
||||
---
|
||||
# Considerations When Hosting an ActiveX Control on a Windows Form
|
||||
|
||||
Although Windows Forms have been optimized to host Windows Forms controls, you can still use ActiveX controls. Keep the following considerations in mind when planning an application that uses ActiveX controls:
|
||||
|
||||
- **Security** The common language runtime has been enhanced with regard to code access security. Applications featuring Windows Forms can run in a fully trusted environment without issue and in a semi-trusted environment with most of the functionality accessible. Windows Forms controls can be hosted in a browser with no complications. However, ActiveX controls on Windows Forms cannot take advantage of these security enhancements. Running an ActiveX control requires unmanaged code permission, which is set with the <xref:System.Security.Permissions.SecurityPermissionAttribute.UnmanagedCode%2A?displayProperty=nameWithType> property. For more information about security and unmanaged code permission, see <xref:System.Security.Permissions.SecurityPermissionAttribute>.
|
||||
@@ -17,15 +18,14 @@ Although Windows Forms have been optimized to host Windows Forms controls, you c
|
||||
- **Total Cost of Ownership** ActiveX controls added to a Windows Form are deployed with that Windows Form in their entirety, which can add significantly to the size of the file(s) created. Additionally, using ActiveX controls on Windows Forms requires writing to the registry. This is more invasive to a user's computer than Windows Forms controls, which do not require this.
|
||||
|
||||
> [!NOTE]
|
||||
> Working with an ActiveX control requires the use of a COM interop wrapper. For more information, see [COM Interoperability in Visual Basic and Visual C#](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/com-interop/com-interoperability-in-net-framework-applications).
|
||||
|
||||
> Working with an ActiveX control requires the use of a COM interop wrapper. For more information, see [COM Interoperability in Visual Basic and Visual C#](/dotnet/visual-basic/programming-guide/com-interop/com-interoperability-in-net-framework-applications).
|
||||
> [!NOTE]
|
||||
> If the name of a member of the ActiveX control matches a name defined in the .NET Framework, then the ActiveX Control Importer will prefix the member name with **Ctl** when it creates the <xref:System.Windows.Forms.AxHost> derived class. For example, if your ActiveX control has a member named **Layout**, it is renamed **CtlLayout** in the AxHost-derived class because the **Layout** event is defined within the .NET Framework.
|
||||
|
||||
## See also
|
||||
|
||||
- [How to: Add ActiveX Controls to Windows Forms](how-to-add-activex-controls-to-windows-forms.md)
|
||||
- [Code Access Security](https://docs.microsoft.com/dotnet/framework/misc/code-access-security)
|
||||
- [Controls and Programmable Objects Compared in Various Languages and Libraries](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/0061wezk(v=vs.100))
|
||||
- [Code Access Security](/dotnet/framework/misc/code-access-security)
|
||||
- [Controls and Programmable Objects Compared in Various Languages and Libraries](/previous-versions/visualstudio/visual-studio-2010/0061wezk(v=vs.100))
|
||||
- [Putting Controls on Windows Forms](putting-controls-on-windows-forms.md)
|
||||
- [Windows Forms Controls](index.md)
|
||||
|
||||
@@ -8,9 +8,11 @@ helpviewer_keywords:
|
||||
ms.assetid: 76e070b2-65d7-457f-8300-d104e4e01e5e
|
||||
---
|
||||
# ContextMenuStrip Control
|
||||
|
||||
The <xref:System.Windows.Forms.ContextMenuStrip> control provides a shortcut menu that you associate with a control.
|
||||
|
||||
## In This Section
|
||||
|
||||
[ContextMenuStrip Control Overview](contextmenustrip-control-overview.md)
|
||||
Explains what the control is and its key features and properties.
|
||||
|
||||
@@ -29,9 +31,10 @@ The <xref:System.Windows.Forms.ContextMenuStrip> control provides a shortcut men
|
||||
[How to: Handle the ContextMenuStrip Opening Event](how-to-handle-the-contextmenustrip-opening-event.md)
|
||||
Describes how to customize the behavior of a <xref:System.Windows.Forms.ContextMenuStrip> control by handling the <xref:System.Windows.Forms.ToolStripDropDown.Opening> event.
|
||||
|
||||
Also see [ContextMenuStrip Tasks Dialog Box](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms233646(v=vs.100)) or [ContextMenuStrip Items Collection Editor](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms233641(v=vs.100)).
|
||||
Also see [ContextMenuStrip Tasks Dialog Box](/previous-versions/visualstudio/visual-studio-2010/ms233646(v=vs.100)) or [ContextMenuStrip Items Collection Editor](/previous-versions/visualstudio/visual-studio-2010/ms233641(v=vs.100)).
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.Windows.Forms.MenuStrip>
|
||||
Describes the features of the <xref:System.Windows.Forms.MenuStrip> class, which provides a menu system for a form.
|
||||
|
||||
@@ -42,5 +45,6 @@ The <xref:System.Windows.Forms.ContextMenuStrip> control provides a shortcut men
|
||||
Describes the features of the <xref:System.Windows.Forms.ToolStripMenuItem> class, which represents a selectable option displayed on a <xref:System.Windows.Forms.MenuStrip> or <xref:System.Windows.Forms.ContextMenuStrip>.
|
||||
|
||||
## Related Sections
|
||||
|
||||
[Controls to Use on Windows Forms](controls-to-use-on-windows-forms.md)
|
||||
Provides a complete list of Windows Forms controls, with links to information on their use.
|
||||
|
||||
@@ -13,7 +13,7 @@ ms.assetid: 5235fe9d-c36a-4c08-ae76-6cb90b50085e
|
||||
The .NET Framework gives you power to develop and implement new controls. In addition to the familiar user control, you will now find that you are able to write custom controls that perform their own painting, and are even able to extend the functionality of existing controls through inheritance. Deciding which type of control to create can be confusing. This section highlights the differences between the various types of controls from which you can inherit, and gives considerations regarding the type to choose for your project.
|
||||
|
||||
> [!NOTE]
|
||||
> If you want to author a control to use on Web Forms, see [Developing Custom ASP.NET Server Controls](https://docs.microsoft.com/previous-versions/aspnet/zt27tfhy(v=vs.100)).
|
||||
> If you want to author a control to use on Web Forms, see [Developing Custom ASP.NET Server Controls](/previous-versions/aspnet/zt27tfhy(v=vs.100)).
|
||||
|
||||
## Inheriting from a Windows Forms Control
|
||||
|
||||
@@ -73,7 +73,7 @@ Inherit from the <xref:System.Windows.Forms.Control> class if:
|
||||
|
||||
- [Walkthrough: Creating a Windows Forms Control That Takes Advantage of Visual Studio Design-Time Features](creating-a-wf-control-design-time-features.md)
|
||||
|
||||
- [How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120))
|
||||
- [How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120))
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+4
-1
@@ -8,12 +8,14 @@ helpviewer_keywords:
|
||||
ms.assetid: dec51976-eae0-4398-a537-20bca7974722
|
||||
---
|
||||
# Controls to Use on Windows Forms
|
||||
|
||||
The following is an alphabetic list of controls and components that can be used on Windows Forms. In addition to the Windows Forms controls covered in this section, you can add ActiveX and custom controls to Windows Forms. If you do not find the control you need listed here, you can also create your own. For details, see [Developing Windows Forms Controls at Design Time](developing-windows-forms-controls-at-design-time.md). For more information about choosing the control you need, see [Windows Forms Controls by Function](windows-forms-controls-by-function.md).
|
||||
|
||||
> [!NOTE]
|
||||
> Visual Basic controls are based on classes provided by the .NET Framework.
|
||||
|
||||
## In This Section
|
||||
|
||||
[Windows Forms Controls by Function](windows-forms-controls-by-function.md)
|
||||
Lists and describes Windows Forms controls based on the .NET Framework.
|
||||
|
||||
@@ -219,13 +221,14 @@ The following is an alphabetic list of controls and components that can be used
|
||||
Describes a set of controls used to provide users with a list of options to choose from.
|
||||
|
||||
## Related Sections
|
||||
|
||||
[Windows Forms Controls](index.md)
|
||||
Explains the use of Windows Forms controls, and describes important concepts for working with them.
|
||||
|
||||
[Developing Windows Forms Controls at Design Time](developing-windows-forms-controls-at-design-time.md)
|
||||
Provides links to step-by-step topics, recommendations for which kind of control to create, and other information about creating your own control.
|
||||
|
||||
[Controls and Programmable Objects Compared in Various Languages and Libraries](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/0061wezk(v=vs.100))
|
||||
[Controls and Programmable Objects Compared in Various Languages and Libraries](/previous-versions/visualstudio/visual-studio-2010/0061wezk(v=vs.100))
|
||||
Provides a table that maps controls in Visual Basic 6.0 to the corresponding control in Visual Basic .NET. Note that controls are now classes in the .NET Framework.
|
||||
|
||||
[How to: Add ActiveX Controls to Windows Forms](how-to-add-activex-controls-to-windows-forms.md)
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 4ce35f12-1f4e-4317-92d1-af8686a8cfaa
|
||||
---
|
||||
# How to: Create a Lookup Table for a Windows Forms ComboBox, ListBox, or CheckedListBox Control
|
||||
|
||||
Sometimes it is useful to display data in a user-friendly format on a Windows Form, but store the data in a format that is more meaningful to your program. For example, an order form for food might display the menu items by name in a list box. However, the data table recording the order would contain the unique ID numbers representing the food. The following tables show an example of how to store and display order-form data for food.
|
||||
|
||||
### OrderDetailsTable
|
||||
@@ -44,7 +45,7 @@ Sometimes it is useful to display data in a user-friendly format on a Windows Fo
|
||||
|
||||
2. Connect to your data source.
|
||||
|
||||
3. Establish a data relation between the two tables. See [Introduction to DataRelation Objects](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/0k21zcyx(v=vs.120)).
|
||||
3. Establish a data relation between the two tables. See [Introduction to DataRelation Objects](/previous-versions/visualstudio/visual-studio-2013/0k21zcyx(v=vs.120)).
|
||||
|
||||
4. Set the following properties. They can be set in code or in the designer.
|
||||
|
||||
|
||||
+6
-2
@@ -11,6 +11,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 99f6e876-3f7f-4139-9063-e36587c95b02
|
||||
---
|
||||
# How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls
|
||||
|
||||
The following code example creates a master/detail form using two <xref:System.Windows.Forms.DataGridView> controls bound to two <xref:System.Windows.Forms.BindingSource> components. The data source is a <xref:System.Data.DataSet> that contains the `Customers` and `Orders` tables from the Northwind SQL Server sample database along with a <xref:System.Data.DataRelation> that relates the two through the `CustomerID` column.
|
||||
|
||||
One <xref:System.Windows.Forms.BindingSource> is bound to the parent `Customers` table in the data set. This data is displayed in the master <xref:System.Windows.Forms.DataGridView> control. The other <xref:System.Windows.Forms.BindingSource> is bound to the first data connector. The <xref:System.Windows.Forms.BindingSource.DataMember%2A> property of the second <xref:System.Windows.Forms.BindingSource> is set to the <xref:System.Data.DataRelation> name. This causes the associated detail <xref:System.Windows.Forms.DataGridView> control to display the rows of the child `Orders` table that correspond to the current row in the master <xref:System.Windows.Forms.DataGridView> control.
|
||||
@@ -18,16 +19,19 @@ The following code example creates a master/detail form using two <xref:System.W
|
||||
For a complete explanation of this code example, see [Walkthrough: Creating a Master/Detail Form Using Two Windows Forms DataGridView Controls](creating-a-master-detail-form-using-two-datagridviews.md).
|
||||
|
||||
## Example
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridViewMasterDetails#00](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMasterDetails/CS/masterdetails.cs#00)]
|
||||
[!code-vb[System.Windows.Forms.DataGridViewMasterDetails#00](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMasterDetails/VB/masterdetails.vb#00)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
References to the System, System.Data, System.Windows.Forms, and System.XML assemblies.
|
||||
|
||||
## .NET Framework Security
|
||||
Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
## See also
|
||||
|
||||
@@ -35,4 +39,4 @@ The following code example creates a master/detail form using two <xref:System.W
|
||||
- <xref:System.Windows.Forms.BindingSource>
|
||||
- [Walkthrough: Creating a Master/Detail Form Using Two Windows Forms DataGridView Controls](creating-a-master-detail-form-using-two-datagridviews.md)
|
||||
- [Displaying Data in the Windows Forms DataGridView Control](displaying-data-in-the-windows-forms-datagridview-control.md)
|
||||
- [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
+2
-2
@@ -18,10 +18,10 @@ ms.assetid: 19438ba2-f687-4417-a2fb-ab1cd69d4ded
|
||||
|
||||
## To create a master-details list in the designer
|
||||
|
||||
1. Add two <xref:System.Windows.Forms.DataGrid> controls to the form. For more information, see [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). In Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox** by default. For more information, see [How to: Add Items to the Toolbox](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)).
|
||||
1. Add two <xref:System.Windows.Forms.DataGrid> controls to the form. For more information, see [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). In Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox** by default. For more information, see [How to: Add Items to the Toolbox](/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)).
|
||||
|
||||
> [!NOTE]
|
||||
> The following steps are not applicable to Visual Studio 2005, which uses the **Data Sources** window for design-time data binding. For more information, see [Bind controls to data in Visual Studio](/visualstudio/data-tools/bind-controls-to-data-in-visual-studio) and [How to: Display Related Data in a Windows Forms Application](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/57tx3hhe(v=vs.120)).
|
||||
> The following steps are not applicable to Visual Studio 2005, which uses the **Data Sources** window for design-time data binding. For more information, see [Bind controls to data in Visual Studio](/visualstudio/data-tools/bind-controls-to-data-in-visual-studio) and [How to: Display Related Data in a Windows Forms Application](/previous-versions/visualstudio/visual-studio-2013/57tx3hhe(v=vs.120)).
|
||||
|
||||
2. Drag two or more tables from **Server Explorer** to the form.
|
||||
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ In order to complete this walkthrough, you will need:
|
||||
2. Implement a method in your form's class definition for handling the detail of connecting to the database. This example uses a `GetData` method that populates a <xref:System.Data.DataSet> object, adds a <xref:System.Data.DataRelation> object to the data set, and binds the <xref:System.Windows.Forms.BindingSource> components. Be sure to set the `connectionString` variable to a value that is appropriate for your database.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridViewMasterDetails#20](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMasterDetails/CS/masterdetails.cs#20)]
|
||||
[!code-vb[System.Windows.Forms.DataGridViewMasterDetails#20](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMasterDetails/VB/masterdetails.vb#20)]
|
||||
@@ -79,4 +79,4 @@ This application gives you a basic understanding of the <xref:System.Windows.For
|
||||
- <xref:System.Windows.Forms.BindingSource>
|
||||
- [Displaying Data in the Windows Forms DataGridView Control](displaying-data-in-the-windows-forms-datagridview-control.md)
|
||||
- [How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls](create-a-master-detail-form-using-two-datagridviews.md)
|
||||
- [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ When you're finished with this walkthrough, your custom control will look someth
|
||||
|
||||

|
||||
|
||||
For the complete code listing, see [How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120)).
|
||||
For the complete code listing, see [How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120)).
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@@ -601,7 +601,7 @@ The `MarqueeControlLibrary` demonstrates a simple implementation of custom contr
|
||||
|
||||
- License the `MarqueeControl`.
|
||||
|
||||
- Control how your controls are serialized and how code is generated for them. For more information, see [Dynamic Source Code Generation and Compilation](https://docs.microsoft.com/dotnet/framework/reflection-and-codedom/dynamic-source-code-generation-and-compilation).
|
||||
- Control how your controls are serialized and how code is generated for them. For more information, see [Dynamic Source Code Generation and Compilation](/dotnet/framework/reflection-and-codedom/dynamic-source-code-generation-and-compilation).
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+4
-1
@@ -8,14 +8,17 @@ helpviewer_keywords:
|
||||
ms.assetid: 07bf558d-3748-42ba-8ba0-37fdef924081
|
||||
---
|
||||
# Data Formatting in the Windows Forms DataGridView Control
|
||||
|
||||
The <xref:System.Windows.Forms.DataGridView> control provides automatic conversion between cell values and the data types that the parent columns display. Text box columns, for example, display string representations of date, time, number, and enumeration values, and convert user-entered string values to the types required by the data store.
|
||||
|
||||
## Formatting with the DataGridViewCellStyle class
|
||||
The <xref:System.Windows.Forms.DataGridView> control provides basic data formatting of cell values through the <xref:System.Windows.Forms.DataGridViewCellStyle> class. You can use the <xref:System.Windows.Forms.DataGridViewCellStyle.Format%2A> property to format date, time, number, and enumeration values for the current default culture using the format specifiers described in [Formatting Types](https://docs.microsoft.com/dotnet/standard/base-types/formatting-types). You can also format these values for specific cultures using the <xref:System.Windows.Forms.DataGridViewCellStyle.FormatProvider%2A> property. The specified format is used both to display data and to parse data that the user enters in the specified format.
|
||||
|
||||
The <xref:System.Windows.Forms.DataGridView> control provides basic data formatting of cell values through the <xref:System.Windows.Forms.DataGridViewCellStyle> class. You can use the <xref:System.Windows.Forms.DataGridViewCellStyle.Format%2A> property to format date, time, number, and enumeration values for the current default culture using the format specifiers described in [Formatting Types](/dotnet/standard/base-types/formatting-types). You can also format these values for specific cultures using the <xref:System.Windows.Forms.DataGridViewCellStyle.FormatProvider%2A> property. The specified format is used both to display data and to parse data that the user enters in the specified format.
|
||||
|
||||
The <xref:System.Windows.Forms.DataGridViewCellStyle> class provides additional formatting properties for wordwrap, text alignment, and the custom display of null database values. For more information, see [How to: Format Data in the Windows Forms DataGridView Control](how-to-format-data-in-the-windows-forms-datagridview-control.md).
|
||||
|
||||
## Formatting with the CellFormatting Event
|
||||
|
||||
If the basic formatting does not meet your needs, you can provide custom data formatting in a handler for the <xref:System.Windows.Forms.DataGridView.CellFormatting?displayProperty=nameWithType> event. The <xref:System.Windows.Forms.DataGridViewCellFormattingEventArgs> passed to the handler has a <xref:System.Windows.Forms.ConvertEventArgs.Value%2A> property that initially contains the cell value. Normally, this value is automatically converted to the display type. To convert the value yourself, set the <xref:System.Windows.Forms.ConvertEventArgs.Value%2A> property to a value of the display type.
|
||||
|
||||
> [!NOTE]
|
||||
|
||||
+9
-1
@@ -7,22 +7,27 @@ helpviewer_keywords:
|
||||
ms.assetid: 094498c3-a126-4a3f-83fe-f69e96c7717b
|
||||
---
|
||||
# DataGridView Control Technology Summary (Windows Forms)
|
||||
|
||||
This topic summarizes information about the `DataGridView` control and the classes that support its use.
|
||||
|
||||
Displaying data in a tabular format is a task you are likely to perform frequently. The `DataGridView` control is designed to be a complete solution for presenting data in a grid.
|
||||
|
||||
## Keywords
|
||||
|
||||
DataGridView, BindingSource, table, cell, data binding, virtual mode
|
||||
|
||||
## Namespaces
|
||||
|
||||
<xref:System.Windows.Forms?displayProperty=nameWithType>
|
||||
|
||||
<xref:System.Data?displayProperty=nameWithType>
|
||||
|
||||
## Related Technologies
|
||||
|
||||
`BindingSource`
|
||||
|
||||
## Background
|
||||
|
||||
User interface (UI) designers frequently find it necessary to display tabular data to users. The .NET Framework provides several ways to show data in a table or grid. The `DataGridView` control represents the latest evolution of this technology for Windows Forms applications.
|
||||
|
||||
The `DataGridView` control can display rows of data from a data store. Many types of data stores are supported. The data store can hold simple, untyped data, such as a one-dimensional array, or it can hold typed data, such as a <xref:System.Data.DataSet>. For more information, see [How to: Bind Data to the Windows Forms DataGridView Control](how-to-bind-data-to-the-windows-forms-datagridview-control.md).
|
||||
@@ -32,6 +37,7 @@ This topic summarizes information about the `DataGridView` control and the class
|
||||
You can extend the `DataGridView` control in several ways to build custom behavior into your applications. For example, you can programmatically specify your own sorting algorithms, and you can create your own types of cells. You can easily customize the appearance of the `DataGridView` control by choosing among several properties. Many types of data stores can be used as a data source, or the `DataGridView` control can operate without a data source bound to it.
|
||||
|
||||
## Implementing DataGridView Classes
|
||||
|
||||
There are several ways for you to take advantage of the `DataGridView` control's extensibility features. You can customize many aspects of the control through events and properties, but some customizations require you to create new classes derived from existing `DataGridView` classes.
|
||||
|
||||
The most typically used base classes are `DataGridViewCell` and `DataGridViewColumn`. You can derive your own cell class from `DataGridViewCell` or any of its child classes. Although you can add any cell type to any column, you will typically also derive a companion column class from `DataGridViewColumn` that hosts cells of your custom cell type by default.
|
||||
@@ -41,6 +47,7 @@ This topic summarizes information about the `DataGridView` control and the class
|
||||
For more information, see [How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance](customize-cells-and-columns-in-the-datagrid-by-extending-behavior.md) and [How to: Host Controls in Windows Forms DataGridView Cells](how-to-host-controls-in-windows-forms-datagridview-cells.md).
|
||||
|
||||
## DataGridView Classes at a Glance
|
||||
|
||||
<xref:System.Windows.Forms>
|
||||
|
||||
|Technology Area|Classes/interfaces/configuration elements|
|
||||
@@ -50,6 +57,7 @@ This topic summarizes information about the `DataGridView` control and the class
|
||||
|<xref:System.Windows.Forms.DataGridView> Extensibility|<xref:System.Windows.Forms.DataGridViewCell> and derived classes<br /><br /> <xref:System.Windows.Forms.DataGridViewColumn> and derived classes<br /><br /> <xref:System.Windows.Forms.IDataGridViewEditingCell><br /><br /> <xref:System.Windows.Forms.IDataGridViewEditingControl>|
|
||||
|
||||
## What's New
|
||||
|
||||
The <xref:System.Windows.Forms.DataGridView> control is designed to be a complete solution for displaying tabular data with Windows Forms. You should consider using the <xref:System.Windows.Forms.DataGridView> control before other solutions, such as <xref:System.Windows.Forms.DataGrid>, when you are authoring a new application. For more information, see [Differences Between the Windows Forms DataGridView and DataGrid Controls](differences-between-the-windows-forms-datagridview-and-datagrid-controls.md).
|
||||
|
||||
The <xref:System.Windows.Forms.DataGridView> control can work in close conjunction with the <xref:System.Windows.Forms.BindingSource> component. This component is designed to be the primary data source of a form. It can manage the interaction between a <xref:System.Windows.Forms.DataGridView> control and its data source, regardless of the data source type.
|
||||
@@ -58,4 +66,4 @@ This topic summarizes information about the `DataGridView` control and the class
|
||||
|
||||
- [DataGridView Control Overview](datagridview-control-overview-windows-forms.md)
|
||||
- [DataGridView Control Architecture](datagridview-control-architecture-windows-forms.md)
|
||||
- [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
+4
-3
@@ -10,16 +10,17 @@ helpviewer_keywords:
|
||||
ms.assetid: c2eb8277-a842-4d99-89a9-647b901a0434
|
||||
---
|
||||
# Defining a Property in Windows Forms Controls
|
||||
For an overview of properties, see [Properties Overview](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/65zdfbdt(v=vs.120)). There are a few important considerations when defining a property:
|
||||
|
||||
For an overview of properties, see [Properties Overview](/previous-versions/visualstudio/visual-studio-2013/65zdfbdt(v=vs.120)). There are a few important considerations when defining a property:
|
||||
|
||||
- You must apply attributes to the properties you define. Attributes specify how the designer should display a property. For details, see [Design-Time Attributes for Components](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/tk67c2t8(v=vs.120)).
|
||||
- You must apply attributes to the properties you define. Attributes specify how the designer should display a property. For details, see [Design-Time Attributes for Components](/previous-versions/visualstudio/visual-studio-2013/tk67c2t8(v=vs.120)).
|
||||
|
||||
- If changing the property affects the visual display of the control, call the <xref:System.Windows.Forms.Control.Invalidate%2A> method (that your control inherits from <xref:System.Windows.Forms.Control>) from the `set` accessor. <xref:System.Windows.Forms.Control.Invalidate%2A> in turn calls the <xref:System.Windows.Forms.Control.OnPaint%2A> method, which redraws the control. Multiple calls to <xref:System.Windows.Forms.Control.Invalidate%2A> result in a single call to <xref:System.Windows.Forms.Control.OnPaint%2A> for efficiency.
|
||||
|
||||
- The .NET Framework class library provides type converters for common data types such as integers, decimal numbers, Boolean values, and others. The purpose of a type converter is generally to provide string-to-value conversion (from string data to other data types). Common data types are associated with default type converters that convert values into strings and strings into the appropriate data types. If you define a property that is a custom (that is, nonstandard) data type, you will have to apply an attribute that specifies the type converter to associate with that property. You can also use an attribute to associate a custom UI type editor with a property. A UI type editor provides a user interface for editing a property or data type. A color picker is an example of a UI type editor. Examples of attributes are given at the end of this topic.
|
||||
|
||||
> [!NOTE]
|
||||
> If a type converter or a UI type editor is not available for your custom property, you can implement one as described in [Extending Design-Time Support](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120)).
|
||||
> If a type converter or a UI type editor is not available for your custom property, you can implement one as described in [Extending Design-Time Support](/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120)).
|
||||
|
||||
The following code fragment defines a custom property named `EndColor` for the custom control `FlashTrackBar`.
|
||||
|
||||
|
||||
+3
-2
@@ -10,7 +10,8 @@ helpviewer_keywords:
|
||||
ms.assetid: d89f1096-8061-42e2-a855-a1f053f1940a
|
||||
---
|
||||
# Defining an Event in Windows Forms Controls
|
||||
For details about defining custom events, see [Events](https://docs.microsoft.com/dotnet/standard/events/index). If you define an event that does not have any associated data, use the base type for event data, <xref:System.EventArgs>, and use <xref:System.EventHandler> as the event delegate. All that remains to do is to define an event member and a protected `On`*EventName* method that raises the event.
|
||||
|
||||
For details about defining custom events, see [Events](/dotnet/standard/events/index). If you define an event that does not have any associated data, use the base type for event data, <xref:System.EventArgs>, and use <xref:System.EventHandler> as the event delegate. All that remains to do is to define an event member and a protected `On`*EventName* method that raises the event.
|
||||
|
||||
The following code fragment shows how the `FlashTrackBar` custom control defines a custom event, `ValueChanged`. For the complete code for the `FlashTrackBar` sample, see the [How to: Create a Windows Forms Control That Shows Progress](how-to-create-a-windows-forms-control-that-shows-progress.md).
|
||||
|
||||
@@ -73,4 +74,4 @@ public class FlashTrackBar : Control {
|
||||
## See also
|
||||
|
||||
- [Events in Windows Forms Controls](events-in-windows-forms-controls.md)
|
||||
- [Events](https://docs.microsoft.com/dotnet/standard/events/index)
|
||||
- [Events](/dotnet/standard/events/index)
|
||||
|
||||
+4
-4
@@ -169,7 +169,7 @@ Visual Studio attempted to wire up an event-handling method and could not find o
|
||||
|
||||
The templates for inherited forms in Visual Studio are not available. If you see this error, please log an issue by using [Report a Problem](/visualstudio/ide/how-to-report-a-problem-with-visual-studio).
|
||||
|
||||
### Delegate class '\<class name>' has no invoke method. Is this class a delegate?
|
||||
### Delegate class '\<class name>' has no invoke method. Is this class a delegate
|
||||
|
||||
Visual Studio has tried to create an event handler, but there is something wrong with the event type. This can happen if the event was created by a non-CLS-compliant language. Contact the component vendor.
|
||||
|
||||
@@ -209,7 +209,7 @@ You've tried to rename a component to an invalid value for that language. To cor
|
||||
|
||||
### The type '\<class name>' is made of several partial classes in the same file
|
||||
|
||||
When you define a class in multiple files by using the [partial](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/partial-type) keyword, you can only have one partial definition in each file.
|
||||
When you define a class in multiple files by using the [partial](/dotnet/csharp/language-reference/keywords/partial-type) keyword, you can only have one partial definition in each file.
|
||||
|
||||
To correct this error, remove all but one of the partial definitions of your class from the file.
|
||||
|
||||
@@ -257,7 +257,7 @@ Visual Studio could not load the designer for the class. If you see this error,
|
||||
|
||||
### The designer must create an instance of type '\<type name>', but it can't because the type is declared as abstract
|
||||
|
||||
This error occurred because the base class of the object being passed to the designer is [abstract](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/abstract), which is not allowed.
|
||||
This error occurred because the base class of the object being passed to the designer is [abstract](/dotnet/csharp/language-reference/keywords/abstract), which is not allowed.
|
||||
|
||||
### The file could not be loaded in the designer
|
||||
|
||||
@@ -359,7 +359,7 @@ This message is similar to "The language for this file does not support the nece
|
||||
|
||||
### Type '\<type name\>' does not have a constructor with parameters of types '\<parameter type names>'
|
||||
|
||||
Visual Studio could not find a [constructor](https://docs.microsoft.com/dotnet/csharp/programming-guide/classes-and-structs/constructors) that had matching parameters. This may be the result of supplying a constructor with types other than those that are required. For example, a **Point** constructor might take two integers. If you provided floats, this error is raised.
|
||||
Visual Studio could not find a [constructor](/dotnet/csharp/programming-guide/classes-and-structs/constructors) that had matching parameters. This may be the result of supplying a constructor with types other than those that are required. For example, a **Point** constructor might take two integers. If you provided floats, this error is raised.
|
||||
|
||||
To correct this error, use a different constructor or explicitly cast the parameter types such that they match those provided by the constructor.
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ The Windows Forms designer in Visual Studio provides rich design-time support fo
|
||||
|
||||
- [Walkthrough: Creating a Windows Forms Control That Takes Advantage of Visual Studio Design-Time Features](creating-a-wf-control-design-time-features.md)
|
||||
|
||||
- [How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120))
|
||||
- [How to: Create a Windows Forms Control That Takes Advantage of Design-Time Features](/previous-versions/visualstudio/visual-studio-2013/307hck25(v=vs.120))
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+7
-3
@@ -8,9 +8,11 @@ helpviewer_keywords:
|
||||
ms.assetid: 236cebc0-bd71-4f18-9fd6-5d0e592375df
|
||||
---
|
||||
# Developing Custom Windows Forms Controls with the .NET Framework
|
||||
|
||||
Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side Windows-based applications. Not only does Windows Forms provide many ready-to-use controls, it also provides the infrastructure for developing your own controls. You can combine existing controls, extend existing controls, or author your own custom controls. This section provides background information and samples to help you develop Windows Forms controls.
|
||||
|
||||
## In This Section
|
||||
|
||||
[Overview of Using Controls in Windows Forms](overview-of-using-controls-in-windows-forms.md)
|
||||
Highlights the essential elements of using controls in Windows Forms applications.
|
||||
|
||||
@@ -39,6 +41,7 @@ Windows Forms controls are reusable components that encapsulate user interface f
|
||||
Shows how to implement multithreaded controls.
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.Windows.Forms.Control?displayProperty=nameWithType>
|
||||
Describes this class and has links to all of its members.
|
||||
|
||||
@@ -46,13 +49,14 @@ Windows Forms controls are reusable components that encapsulate user interface f
|
||||
Describes this class and has links to all of its members.
|
||||
|
||||
## Related Sections
|
||||
[Design-Time Attributes for Components](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/tk67c2t8(v=vs.120))
|
||||
|
||||
[Design-Time Attributes for Components](/previous-versions/visualstudio/visual-studio-2013/tk67c2t8(v=vs.120))
|
||||
Lists metadata attributes to apply to components and controls so that they are displayed correctly at design time in visual designers.
|
||||
|
||||
[Extending Design-Time Support](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120))
|
||||
[Extending Design-Time Support](/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120))
|
||||
Describes how to implement classes such as editors and designers that provide design-time support.
|
||||
|
||||
[How to: License Components and Controls](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/fe8b1eh9(v=vs.120))
|
||||
[How to: License Components and Controls](/previous-versions/visualstudio/visual-studio-2013/fe8b1eh9(v=vs.120))
|
||||
Describes how to implement licensing in your control or component.
|
||||
|
||||
Also see [Developing Windows Forms Controls at Design Time](developing-windows-forms-controls-at-design-time.md).
|
||||
|
||||
+3
-3
@@ -18,9 +18,9 @@ manager: jillfra
|
||||
For control authors, the .NET Framework provides a wealth of control authoring technology. Authors are no longer limited to designing composite controls that act as a collection of preexisting controls. Through inheritance, you can create your own controls from preexisting composite controls or preexisting Windows Forms controls. You can also design your own controls that implement custom painting. These options enable a great deal of flexibility to the design and functionality of the visual interface. To take advantage of these features, you should be familiar with object-based programming concepts.
|
||||
|
||||
> [!NOTE]
|
||||
> It is not necessary to have a thorough understanding of inheritance, but you may find it useful to refer to [Inheritance basics (Visual Basic)](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/inheritance-basics).
|
||||
> It is not necessary to have a thorough understanding of inheritance, but you may find it useful to refer to [Inheritance basics (Visual Basic)](/dotnet/visual-basic/programming-guide/language-features/objects-and-classes/inheritance-basics).
|
||||
|
||||
If you want to create custom controls to use on Web Forms, see [Developing Custom ASP.NET Server Controls](https://docs.microsoft.com/previous-versions/aspnet/zt27tfhy(v=vs.100)).
|
||||
If you want to create custom controls to use on Web Forms, see [Developing Custom ASP.NET Server Controls](/previous-versions/aspnet/zt27tfhy(v=vs.100)).
|
||||
|
||||
## In this section
|
||||
|
||||
@@ -86,7 +86,7 @@ Shows how to diagnose and fix common issues that can occur when you author a cus
|
||||
[Developing Custom Windows Forms Controls with the .NET Framework](developing-custom-windows-forms-controls.md)\
|
||||
Discusses how to create your own custom controls with the .NET Framework.
|
||||
|
||||
[Language Independence and Language-Independent Components](https://docs.microsoft.com/dotnet/standard/language-independence-and-language-independent-components)\
|
||||
[Language Independence and Language-Independent Components](/dotnet/standard/language-independence-and-language-independent-components)\
|
||||
Introduces the common language runtime, which is designed to simplify the creation and use of components. An important aspect of this simplification is enhanced interoperability between components written using different programming languages. The Common Language Specification (CLS) makes it possible to create tools and components that work with multiple programming languages.
|
||||
|
||||
[Walkthrough: Automatically Populating the Toolbox with Custom Components](walkthrough-automatically-populating-the-toolbox-with-custom-components.md)\
|
||||
|
||||
+3
-2
@@ -7,13 +7,14 @@ helpviewer_keywords:
|
||||
ms.assetid: 7e3d1379-87aa-437c-afce-c99454eff30e
|
||||
---
|
||||
# Events in Windows Forms Controls
|
||||
|
||||
A Windows Forms control inherits more than sixty events from <xref:System.Windows.Forms.Control?displayProperty=nameWithType>. These include the <xref:System.Windows.Forms.Control.Paint> event, which causes a control to be drawn, events related to displaying a window, such as the <xref:System.Windows.Forms.Control.Resize> and <xref:System.Windows.Forms.Control.Layout> events, and low-level mouse and keyboard events. Some low-level events are synthesized by <xref:System.Windows.Forms.Control> into semantic events such as <xref:System.Windows.Forms.Control.Click> and <xref:System.Windows.Forms.Control.DoubleClick>. For details about inherited events, see <xref:System.Windows.Forms.Control>.
|
||||
|
||||
If your custom control needs to override inherited event functionality, override the inherited `On`*EventName* method instead of attaching a delegate. If you are not familiar with the event model in the .NET Framework, see [Raising Events from a Component](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/sh2e3k5z(v=vs.120)).
|
||||
If your custom control needs to override inherited event functionality, override the inherited `On`*EventName* method instead of attaching a delegate. If you are not familiar with the event model in the .NET Framework, see [Raising Events from a Component](/previous-versions/visualstudio/visual-studio-2013/sh2e3k5z(v=vs.120)).
|
||||
|
||||
## See also
|
||||
|
||||
- [Overriding the OnPaint Method](overriding-the-onpaint-method.md)
|
||||
- [Handling User Input](handling-user-input.md)
|
||||
- [Defining an Event](defining-an-event-in-windows-forms-controls.md)
|
||||
- [Events](https://docs.microsoft.com/dotnet/standard/events/index)
|
||||
- [Events](/dotnet/standard/events/index)
|
||||
|
||||
+2
-1
@@ -9,6 +9,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 87412dd2-478f-4751-af87-dafc591fc215
|
||||
---
|
||||
# How to: Freeze Columns in the Windows Forms DataGridView Control Using the Designer
|
||||
|
||||
When users view data displayed in a Windows Forms <xref:System.Windows.Forms.DataGridView> control, they sometimes need to refer to a single column or set of columns frequently. For example, when you display a table of customer information that contains many columns, it is useful for you to display the customer name at all times while enabling other columns to scroll outside the visible region.
|
||||
|
||||
To achieve this behavior, you can freeze columns in the control. When you freeze a column, all the columns to its left (or to its right in right-to-left language scripts) are frozen as well. Frozen columns remain in place while all other columns can scroll. If column reordering is enabled, the frozen columns are treated as a group distinct from the unfrozen columns. Users can reposition columns in either group, but they cannot move a column from one group to the other.
|
||||
@@ -32,6 +33,6 @@ When users view data displayed in a Windows Forms <xref:System.Windows.Forms.Dat
|
||||
- <xref:System.Windows.Forms.DataGridViewColumn.Frozen%2A?displayProperty=nameWithType>
|
||||
- [How to: Add and Remove Columns in the Windows Forms DataGridView Control Using the Designer](add-and-remove-columns-in-the-datagrid-using-the-designer.md)
|
||||
- [How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer](enable-column-reordering-in-the-datagrid-using-the-designer.md)
|
||||
- [How to: Display Right-to-Left Text in Windows Forms for Globalization](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/7d3337xw(v=vs.100))
|
||||
- [How to: Display Right-to-Left Text in Windows Forms for Globalization](/previous-versions/visualstudio/visual-studio-2010/7d3337xw(v=vs.100))
|
||||
- [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project)
|
||||
- [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md)
|
||||
|
||||
+6
-2
@@ -13,21 +13,25 @@ helpviewer_keywords:
|
||||
ms.assetid: 9004e72f-fdec-4264-a37d-2c99764efc13
|
||||
---
|
||||
# How to: Handle Errors That Occur During Data Entry in the Windows Forms DataGridView Control
|
||||
|
||||
The following code example demonstrates how to use the <xref:System.Windows.Forms.DataGridView> control to report data entry errors to the user.
|
||||
|
||||
For a complete explanation of this code example, see [Walkthrough: Handling Errors that Occur During Data Entry in the Windows Forms DataGridView Control](handling-errors-that-occur-during-data-entry-in-the-datagrid.md).
|
||||
|
||||
## Example
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridView.DataError#00](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.DataError/CS/errorhandling.cs#00)]
|
||||
[!code-vb[System.Windows.Forms.DataGridView.DataError#00](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.DataError/VB/errorhandling.vb#00)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- References to the System, System.Data, System.Windows.Forms, and System.XML assemblies.
|
||||
|
||||
## .NET Framework Security
|
||||
Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
## See also
|
||||
|
||||
@@ -36,4 +40,4 @@ The following code example demonstrates how to use the <xref:System.Windows.Form
|
||||
- [Walkthrough: Handling Errors that Occur During Data Entry in the Windows Forms DataGridView Control](handling-errors-that-occur-during-data-entry-in-the-datagrid.md)
|
||||
- [Data Entry in the Windows Forms DataGridView Control](data-entry-in-the-windows-forms-datagridview-control.md)
|
||||
- [Walkthrough: Validating Data in the Windows Forms DataGridView Control](walkthrough-validating-data-in-the-windows-forms-datagridview-control.md)
|
||||
- [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ In order to complete this walkthrough, you will need:
|
||||
This code example uses a `GetData` method that returns a populated <xref:System.Data.DataTable> object. Be sure that you set the `connectionString` variable to a value that is appropriate for your database.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridView.DataError#30](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.DataError/CS/errorhandling.cs#30)]
|
||||
[!code-vb[System.Windows.Forms.DataGridView.DataError#30](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.DataError/VB/errorhandling.vb#30)]
|
||||
@@ -93,4 +93,4 @@ This application gives you a basic understanding of the <xref:System.Windows.For
|
||||
- [Data Entry in the Windows Forms DataGridView Control](data-entry-in-the-windows-forms-datagridview-control.md)
|
||||
- [How to: Handle Errors That Occur During Data Entry in the Windows Forms DataGridView Control](handle-errors-that-occur-during-data-entry-in-the-datagrid.md)
|
||||
- [Walkthrough: Validating Data in the Windows Forms DataGridView Control](walkthrough-validating-data-in-the-windows-forms-datagridview-control.md)
|
||||
- [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
@@ -11,12 +11,14 @@ helpviewer_keywords:
|
||||
ms.assetid: d9b12787-86f6-4022-8e0f-e12d312c4af2
|
||||
---
|
||||
# Handling User Input
|
||||
This topic describes the main keyboard and mouse events provided by <xref:System.Windows.Forms.Control?displayProperty=nameWithType>. When handling an event, control authors should override the protected `On`*EventName* method rather than attaching a delegate to the event. For a review of events, see [Raising Events from a Component](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/sh2e3k5z(v=vs.120)).
|
||||
|
||||
This topic describes the main keyboard and mouse events provided by <xref:System.Windows.Forms.Control?displayProperty=nameWithType>. When handling an event, control authors should override the protected `On`*EventName* method rather than attaching a delegate to the event. For a review of events, see [Raising Events from a Component](/previous-versions/visualstudio/visual-studio-2013/sh2e3k5z(v=vs.120)).
|
||||
|
||||
> [!NOTE]
|
||||
> If there is no data associated with an event, an instance of the base class <xref:System.EventArgs> is passed as an argument to the `On`*EventName* method.
|
||||
|
||||
## Keyboard Events
|
||||
|
||||
The common keyboard events that your control can handle are <xref:System.Windows.Forms.Control.KeyDown>, <xref:System.Windows.Forms.Control.KeyPress>, and <xref:System.Windows.Forms.Control.KeyUp>.
|
||||
|
||||
|Event Name|Method to Override|Description of Event|
|
||||
@@ -29,6 +31,7 @@ This topic describes the main keyboard and mouse events provided by <xref:System
|
||||
> Handling keyboard input is considerably more complex than overriding the events in the preceding table and is beyond the scope of this topic. For more information, see [User Input in Windows Forms](../user-input-in-windows-forms.md).
|
||||
|
||||
## Mouse Events
|
||||
|
||||
The mouse events that your control can handle are <xref:System.Windows.Forms.Control.MouseDown>, <xref:System.Windows.Forms.Control.MouseEnter>, <xref:System.Windows.Forms.Control.MouseHover>, <xref:System.Windows.Forms.Control.MouseLeave>, <xref:System.Windows.Forms.Control.MouseMove>, and <xref:System.Windows.Forms.Control.MouseUp>.
|
||||
|
||||
|Event Name|Method to Override|Description of Event|
|
||||
@@ -61,5 +64,5 @@ This topic describes the main keyboard and mouse events provided by <xref:System
|
||||
|
||||
- [Events in Windows Forms Controls](events-in-windows-forms-controls.md)
|
||||
- [Defining an Event](defining-an-event-in-windows-forms-controls.md)
|
||||
- [Events](https://docs.microsoft.com/dotnet/standard/events/index)
|
||||
- [Events](/dotnet/standard/events/index)
|
||||
- [User Input in Windows Forms](../user-input-in-windows-forms.md)
|
||||
|
||||
+3
-1
@@ -10,6 +10,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 53db79fa-8a5e-448e-88c2-f54ace3860b6
|
||||
---
|
||||
# How to: Access the HTML Source in the Managed HTML Document Object Model
|
||||
|
||||
The <xref:System.Windows.Forms.WebBrowser.DocumentStream%2A> and <xref:System.Windows.Forms.WebBrowser.DocumentText%2A> properties on the <xref:System.Windows.Forms.WebBrowser> control return the HTML of the current document as it existed when it was first displayed. However, if you modify the page using method and property calls such as <xref:System.Windows.Forms.HtmlElement.AppendChild%2A> and <xref:System.Windows.Forms.HtmlElement.InnerHtml%2A>, these changes will not appear when you call <xref:System.Windows.Forms.WebBrowser.DocumentStream%2A> and <xref:System.Windows.Forms.WebBrowser.DocumentText%2A>. To obtain the most up-to-date HTML source for the DOM, you must call the <xref:System.Windows.Forms.HtmlElement.OuterHtml%2A> property on the HTML element.
|
||||
|
||||
The following procedure shows how to retrieve the dynamic source and display it in a separate shortcut menu.
|
||||
@@ -29,7 +30,7 @@ The <xref:System.Windows.Forms.WebBrowser.DocumentStream%2A> and <xref:System.Wi
|
||||
[!code-csharp[DisplayWebBrowserCode#1](~/samples/snippets/csharp/VS_Snippets_Winforms/DisplayWebBrowserCode/CS/CodeForm.cs#1)]
|
||||
[!code-vb[DisplayWebBrowserCode#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/DisplayWebBrowserCode/VB/CodeForm.vb#1)]
|
||||
|
||||
6. Add a <xref:System.Windows.Forms.Button> control named `Button1` to your <xref:System.Windows.Forms.Form>, and monitor for the <xref:System.Windows.Forms.Control.Click> event. For details on monitoring events, see [Events](https://docs.microsoft.com/dotnet/standard/events/index).
|
||||
6. Add a <xref:System.Windows.Forms.Button> control named `Button1` to your <xref:System.Windows.Forms.Form>, and monitor for the <xref:System.Windows.Forms.Control.Click> event. For details on monitoring events, see [Events](/dotnet/standard/events/index).
|
||||
|
||||
7. Add the following code to the <xref:System.Windows.Forms.Control.Click> event handler.
|
||||
|
||||
@@ -37,6 +38,7 @@ The <xref:System.Windows.Forms.WebBrowser.DocumentStream%2A> and <xref:System.Wi
|
||||
[!code-vb[DisplayWebBrowserCode#2](~/samples/snippets/visualbasic/VS_Snippets_Winforms/DisplayWebBrowserCode/VB/Form1.vb#2)]
|
||||
|
||||
## Robust Programming
|
||||
|
||||
Always test the value of <xref:System.Windows.Forms.WebBrowser.Document%2A> before attempting to retrieve it. If the current page is not finished loading, <xref:System.Windows.Forms.WebBrowser.Document%2A> or one or more of its child objects may not be initialized.
|
||||
|
||||
## See also
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 40fa5cd5-1ed8-42f6-a93f-9ac01608bbeb
|
||||
---
|
||||
# How to: Access the Managed HTML Document Object Model
|
||||
|
||||
You can access the managed HTML Document Object Model (DOM) from two types of applications:
|
||||
|
||||
- A Windows Forms application (.exe) that hosted the managed <xref:System.Windows.Forms.WebBrowser> control. These two technologies complement one another, with the <xref:System.Windows.Forms.WebBrowser> control displaying the page to the user and the HTML DOM representing the document's logical structure.
|
||||
@@ -18,7 +19,7 @@ You can access the managed HTML Document Object Model (DOM) from two types of ap
|
||||
|
||||
### To access DOM from a Windows Forms application
|
||||
|
||||
1. Host a <xref:System.Windows.Forms.WebBrowser> control within your Windows Forms application and monitor for the <xref:System.Windows.Forms.WebBrowser.DocumentCompleted> event. For details on hosting controls and monitoring for events, see [Events](https://docs.microsoft.com/dotnet/standard/events/index).
|
||||
1. Host a <xref:System.Windows.Forms.WebBrowser> control within your Windows Forms application and monitor for the <xref:System.Windows.Forms.WebBrowser.DocumentCompleted> event. For details on hosting controls and monitoring for events, see [Events](/dotnet/standard/events/index).
|
||||
|
||||
2. Retrieve the <xref:System.Windows.Forms.HtmlDocument> for the current page by accessing the <xref:System.Windows.Forms.WebBrowser.Document%2A> property of the <xref:System.Windows.Forms.WebBrowser> control.
|
||||
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ While the Windows Forms Designer in Visual Studio is optimized to host Windows F
|
||||
> [!CAUTION]
|
||||
> There are performance limitations for Windows Forms when ActiveX controls are added to them.
|
||||
|
||||
Before you add ActiveX controls to your form, you must add them to the Toolbox. For more information, see [COM Components, Customize Toolbox Dialog Box](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/cby6tzh5(v=vs.100)).
|
||||
Before you add ActiveX controls to your form, you must add them to the Toolbox. For more information, see [COM Components, Customize Toolbox Dialog Box](/previous-versions/visualstudio/visual-studio-2010/cby6tzh5(v=vs.100)).
|
||||
|
||||
## Add an ActiveX control to your Windows Form
|
||||
|
||||
@@ -23,12 +23,12 @@ To add an ActiveX control to your Windows Form, double-click the control on the
|
||||
Visual Studio adds all references to the control in your project. For more information about things to keep in mind when using ActiveX controls on Windows Forms, see [Considerations When Hosting an ActiveX Control on a Windows Form](considerations-when-hosting-an-activex-control-on-a-windows-form.md).
|
||||
|
||||
> [!NOTE]
|
||||
> The Windows Forms ActiveX Control Importer (AxImp.exe) creates event arguments of a different type than expected upon importation of ActiveX dynamic link libraries. The arguments created by AxImp.exe are similar to the following: `Invoke(object sender, DWebBrowserEvents2_ProgressChangeEvent e)`, when `Invoke(object sender, DWebBrowserEvents2_ProgressChangeEventArgs e)` is expected. Be aware that this irregularity does not prevent code from functioning normally. For details, see [Windows Forms ActiveX Control Importer (Aximp.exe)](https://docs.microsoft.com/dotnet/framework/tools/aximp-exe-windows-forms-activex-control-importer).
|
||||
> The Windows Forms ActiveX Control Importer (AxImp.exe) creates event arguments of a different type than expected upon importation of ActiveX dynamic link libraries. The arguments created by AxImp.exe are similar to the following: `Invoke(object sender, DWebBrowserEvents2_ProgressChangeEvent e)`, when `Invoke(object sender, DWebBrowserEvents2_ProgressChangeEventArgs e)` is expected. Be aware that this irregularity does not prevent code from functioning normally. For details, see [Windows Forms ActiveX Control Importer (Aximp.exe)](/dotnet/framework/tools/aximp-exe-windows-forms-activex-control-importer).
|
||||
|
||||
## See also
|
||||
|
||||
- [Windows Forms Controls](index.md)
|
||||
- [Controls and Programmable Objects Compared in Various Languages and Libraries](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/0061wezk(v=vs.100))
|
||||
- [Controls and Programmable Objects Compared in Various Languages and Libraries](/previous-versions/visualstudio/visual-studio-2010/0061wezk(v=vs.100))
|
||||
- [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md)
|
||||
- [Labeling Individual Windows Forms Controls and Providing Shortcuts to Them](labeling-individual-windows-forms-controls-and-providing-shortcuts-to-them.md)
|
||||
- [Controls to Use on Windows Forms](controls-to-use-on-windows-forms.md)
|
||||
|
||||
+2
-3
@@ -17,7 +17,7 @@ Most forms are designed by adding controls to the surface of the form to define
|
||||
|
||||
## To draw a control on a form
|
||||
|
||||
1. Open the form. For more information, see [How to: Display Windows Forms in the Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/w5yd62ts(v=vs.100)).
|
||||
1. Open the form. For more information, see [How to: Display Windows Forms in the Designer](/previous-versions/visualstudio/visual-studio-2010/w5yd62ts(v=vs.100)).
|
||||
|
||||
2. In the **Toolbox**, click the control you want to add to your form.
|
||||
|
||||
@@ -30,7 +30,7 @@ Most forms are designed by adding controls to the surface of the form to define
|
||||
|
||||
## To drag a control to a form
|
||||
|
||||
1. Open the form. For more information, see [How to: Display Windows Forms in the Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/w5yd62ts(v=vs.100)).
|
||||
1. Open the form. For more information, see [How to: Display Windows Forms in the Designer](/previous-versions/visualstudio/visual-studio-2010/w5yd62ts(v=vs.100)).
|
||||
|
||||
2. In the **Toolbox**, click the control you want and drag it to your form.
|
||||
|
||||
@@ -78,7 +78,6 @@ Most forms are designed by adding controls to the surface of the form to define
|
||||
|
||||
> [!NOTE]
|
||||
> You can also add code to initialize other properties of the control.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> You might expose your local computer to a security risk through the network by referencing a malicious `UserControl`. This would only be a concern in the case of a malicious person creating a damaging custom control, followed by you mistakenly adding it to your project.
|
||||
|
||||
|
||||
+2
-2
@@ -21,13 +21,13 @@ A nonvisual control (or component) provides functionality to your application. U
|
||||
|
||||
## Add a component to a Windows Form
|
||||
|
||||
1. Open the form in Visual Studio. For details, see [How to: Display Windows Forms in the Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/w5yd62ts(v=vs.100)).
|
||||
1. Open the form in Visual Studio. For details, see [How to: Display Windows Forms in the Designer](/previous-versions/visualstudio/visual-studio-2010/w5yd62ts(v=vs.100)).
|
||||
|
||||
2. In the **Toolbox**, click a component and drag it to your form.
|
||||
|
||||
Your component appears in the component tray.
|
||||
|
||||
Furthermore, components can be added to a form at run time. This is a common scenario, especially because components do not have a visual expression, unlike controls that have a user interface. In the example below, a <xref:System.Windows.Forms.Timer> component is added at run time. (Note that Visual Studio contains a number of different timers; in this case, use a Windows Forms <xref:System.Windows.Forms.Timer> component. For more information about the different timers in Visual Studio, see [Introduction to Server-Based Timers](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2008/tb9yt5e6(v=vs.90)).)
|
||||
Furthermore, components can be added to a form at run time. This is a common scenario, especially because components do not have a visual expression, unlike controls that have a user interface. In the example below, a <xref:System.Windows.Forms.Timer> component is added at run time. (Note that Visual Studio contains a number of different timers; in this case, use a Windows Forms <xref:System.Windows.Forms.Timer> component. For more information about the different timers in Visual Studio, see [Introduction to Server-Based Timers](/previous-versions/visualstudio/visual-studio-2008/tb9yt5e6(v=vs.90)).)
|
||||
|
||||
> [!CAUTION]
|
||||
> Components often have control-specific properties that must be set for the component to function effectively. In the case of the <xref:System.Windows.Forms.Timer> component below, you set the `Interval` property. Be sure, when adding components to your project, that you set the properties necessary for that component.
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 835e3902-288c-4c38-9d69-0696d8695009
|
||||
---
|
||||
# How to: Add Panels to a StatusBar Control
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The <xref:System.Windows.Forms.StatusStrip> and <xref:System.Windows.Forms.ToolStripStatusLabel> controls replace and add functionality to the <xref:System.Windows.Forms.StatusBar> and <xref:System.Windows.Forms.StatusBarPanel> controls; however, the <xref:System.Windows.Forms.StatusBar> and <xref:System.Windows.Forms.StatusBarPanel> controls are retained for both backward compatibility and future use, if you choose.
|
||||
|
||||
@@ -118,7 +119,7 @@ ms.assetid: 835e3902-288c-4c38-9d69-0696d8695009
|
||||
|
||||
- <xref:System.Windows.Forms.StatusBar>
|
||||
- <xref:System.Windows.Forms.ToolStripStatusLabel>
|
||||
- [Collection Editor Dialog Box](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/xc4yyekt(v=vs.100))
|
||||
- [Collection Editor Dialog Box](/previous-versions/visualstudio/visual-studio-2010/xc4yyekt(v=vs.100))
|
||||
- [How to: Set the Size of Status-Bar Panels](how-to-set-the-size-of-status-bar-panels.md)
|
||||
- [Walkthrough: Updating Status Bar Information at Run Time](walkthrough-updating-status-bar-information-at-run-time.md)
|
||||
- [How to: Determine Which Panel in the Windows Forms StatusBar Control Was Clicked](determine-which-panel-wf-statusbar-control-was-clicked.md)
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 771bf895-3d5f-469b-a324-3528f343657e
|
||||
---
|
||||
# How to: Add to or Remove from a Collection of Controls at Run Time
|
||||
|
||||
Common tasks in application development are adding controls to and removing controls from any container control on your forms (such as the <xref:System.Windows.Forms.Panel> or <xref:System.Windows.Forms.GroupBox> control, or even the form itself). At design time, controls can be dragged directly onto a panel or group box. At run time, these controls maintain a `Controls` collection, which keeps track of what controls are placed on them.
|
||||
|
||||
> [!NOTE]
|
||||
@@ -61,7 +62,7 @@ Common tasks in application development are adding controls to and removing cont
|
||||
|
||||
### To remove controls from a collection programmatically
|
||||
|
||||
1. Remove the event handler from the event. In Visual Basic, use the [RemoveHandler Statement](https://docs.microsoft.com/dotnet/visual-basic/language-reference/statements/removehandler-statement) keyword; in C#, use the [-= operator](https://docs.microsoft.com/dotnet/csharp/language-reference/operators/subtraction-operator).
|
||||
1. Remove the event handler from the event. In Visual Basic, use the [RemoveHandler Statement](/dotnet/visual-basic/language-reference/statements/removehandler-statement) keyword; in C#, use the [-= operator](/dotnet/csharp/language-reference/operators/subtraction-operator).
|
||||
|
||||
2. Use the `Remove` method to delete the desired control from the panel's `Controls` collection.
|
||||
|
||||
|
||||
+8
-1
@@ -11,9 +11,11 @@ helpviewer_keywords:
|
||||
ms.assetid: af0a3f7f-155b-4ba1-83c4-9cf721331a06
|
||||
---
|
||||
# How to: Apply Attributes in Windows Forms Controls
|
||||
|
||||
To develop components and controls that interact correctly with the design environment and execute correctly at run time, you need to apply attributes correctly to classes and members.
|
||||
|
||||
## Example
|
||||
|
||||
The following code example demonstrates how to use several attributes on a custom control. The control demonstrates a simple logging capability. When the control is bound to a data source, it displays the values sent by the data source in a <xref:System.Windows.Forms.DataGridView> control. If a value exceeds the value specified by the `Threshold` property, a `ThresholdExceeded` event is raised.
|
||||
|
||||
The `AttributesDemoControl` logs values with a `LogEntry` class. The `LogEntry` class is a template class, which means it is parameterized on the type that it logs. For example, if the `AttributesDemoControl` is logging values of type `float`, each `LogEntry` instance is declared and used as follows.
|
||||
@@ -35,30 +37,35 @@ To develop components and controls that interact correctly with the design envir
|
||||
The first code example is the `AttributesDemoControl` implementation. The second code example demonstrates a form that uses the `AttributesDemoControl`.
|
||||
|
||||
## Class-level Attributes
|
||||
|
||||
Some attributes are applied at the class level. The following code example shows the attributes that are commonly applied to a Windows Forms control.
|
||||
|
||||
[!code-csharp[System.ComponentModel.AttributesDemoControl#20](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/CS/attributesdemocontrol.cs#20)]
|
||||
[!code-vb[System.ComponentModel.AttributesDemoControl#20](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/VB/attributesdemocontrol.vb#20)]
|
||||
|
||||
### TypeConverter Attribute
|
||||
|
||||
<xref:System.ComponentModel.TypeConverterAttribute> is another commonly used class-level attribute. The following code example shows its use for the `LogEntry` class. This example also shows an implementation of a <xref:System.ComponentModel.TypeConverter> for the `LogEntry` type, called `LogEntryTypeConverter`.
|
||||
|
||||
[!code-csharp[System.ComponentModel.AttributesDemoControl#5](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/CS/attributesdemocontrol.cs#5)]
|
||||
[!code-vb[System.ComponentModel.AttributesDemoControl#5](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/VB/attributesdemocontrol.vb#5)]
|
||||
|
||||
## Member-level Attributes
|
||||
|
||||
Some attributes are applied at the member level. The following code examples show some attributes that are commonly applied to properties of Windows Forms controls.
|
||||
|
||||
[!code-csharp[System.ComponentModel.AttributesDemoControl#21](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/CS/attributesdemocontrol.cs#21)]
|
||||
[!code-vb[System.ComponentModel.AttributesDemoControl#21](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/VB/attributesdemocontrol.vb#21)]
|
||||
|
||||
### AmbientValue Attribute
|
||||
|
||||
The following example demonstrates the <xref:System.ComponentModel.AmbientValueAttribute> and shows code that supports its interaction with the design environment. This interaction is called *ambience*.
|
||||
|
||||
[!code-csharp[System.ComponentModel.AttributesDemoControl#23](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/CS/attributesdemocontrol.cs#23)]
|
||||
[!code-vb[System.ComponentModel.AttributesDemoControl#23](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/VB/attributesdemocontrol.vb#23)]
|
||||
|
||||
### Databinding Attributes
|
||||
|
||||
The following examples demonstrate an implementation of complex data binding. The class-level <xref:System.ComponentModel.ComplexBindingPropertiesAttribute>, shown previously, specifies the `DataSource` and `DataMember` properties to use for data binding. The <xref:System.ComponentModel.AttributeProviderAttribute> specifies the type to which the `DataSource` property will bind.
|
||||
|
||||
[!code-csharp[System.ComponentModel.AttributesDemoControl#25](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.AttributesDemoControl/CS/attributesdemocontrol.cs#25)]
|
||||
@@ -77,4 +84,4 @@ To develop components and controls that interact correctly with the design envir
|
||||
- <xref:System.Windows.Forms.DataGridView>
|
||||
- [Developing Custom Windows Forms Controls with the .NET Framework](developing-custom-windows-forms-controls.md)
|
||||
- [Attributes in Windows Forms Controls](attributes-in-windows-forms-controls.md)
|
||||
- [How to: Serialize Collections of Standard Types with the DesignerSerializationVisibilityAttribute](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/ms171833(v=vs.120))
|
||||
- [How to: Serialize Collections of Standard Types with the DesignerSerializationVisibilityAttribute](/previous-versions/visualstudio/visual-studio-2013/ms171833(v=vs.120))
|
||||
|
||||
+4
-4
@@ -29,13 +29,13 @@ This complete code example retrieves data from a database to populate a DataGrid
|
||||
|
||||
This example requires:
|
||||
|
||||
- Access to a Northwind SQL Server sample database. For more information about installing the Northwind sample database, see [Get the sample databases for ADO.NET code samples](https://docs.microsoft.com/dotnet/framework/data/adonet/sql/linq/downloading-sample-databases).
|
||||
- Access to a Northwind SQL Server sample database. For more information about installing the Northwind sample database, see [Get the sample databases for ADO.NET code samples](/dotnet/framework/data/adonet/sql/linq/downloading-sample-databases).
|
||||
|
||||
- References to the System, System.Windows.Forms, System.Data, and System.Xml assemblies.
|
||||
|
||||
To build and run this example, paste the code into the *Form1* code file in a new Windows Forms project. For information about building from the C# or Visual Basic command line, see [Command-line building with csc.exe](https://docs.microsoft.com/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe) or [Build from the command line](https://docs.microsoft.com/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line).
|
||||
To build and run this example, paste the code into the *Form1* code file in a new Windows Forms project. For information about building from the C# or Visual Basic command line, see [Command-line building with csc.exe](/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe) or [Build from the command line](/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line).
|
||||
|
||||
Populate the `connectionString` variable in the example with the values for your Northwind SQL Server sample database connection. Windows Authentication, also called integrated security, is a more secure way to connect to the database than storing a password in the connection string. For more information about connection security, see [Protect connection information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
Populate the `connectionString` variable in the example with the values for your Northwind SQL Server sample database connection. Windows Authentication, also called integrated security, is a more secure way to connect to the database than storing a password in the connection string. For more information about connection security, see [Protect connection information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridViewBoundEditable](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewBoundEditable/CS/datagridviewboundeditable.cs)]
|
||||
[!code-vb[System.Windows.Forms.DataGridViewBoundEditable](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewBoundEditable/VB/datagridviewboundeditable.vb)]
|
||||
@@ -46,4 +46,4 @@ Populate the `connectionString` variable in the example with the values for your
|
||||
- <xref:System.Windows.Forms.DataGridView.DataSource%2A?displayProperty=nameWithType>
|
||||
- <xref:System.Windows.Forms.BindingSource>
|
||||
- [Display data in the Windows Forms DataGridView control](displaying-data-in-the-windows-forms-datagridview-control.md)
|
||||
- [Protect connection information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protect connection information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ Often, within Windows applications you create, you will have to prompt users to
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> To use this class, your assembly requires a privilege level granted by the <xref:System.Security.Permissions.FileIOPermissionAttribute.PathDiscovery%2A> property, which is part of the <xref:System.Security.Permissions.FileIOPermissionAccess> enumeration. If you are running in a partial-trust context, the process might throw an exception because of insufficient privileges. For more information, see [Code Access Security Basics](https://docs.microsoft.com/dotnet/framework/misc/code-access-security-basics).
|
||||
> To use this class, your assembly requires a privilege level granted by the <xref:System.Security.Permissions.FileIOPermissionAttribute.PathDiscovery%2A> property, which is part of the <xref:System.Security.Permissions.FileIOPermissionAccess> enumeration. If you are running in a partial-trust context, the process might throw an exception because of insufficient privileges. For more information, see [Code Access Security Basics](/dotnet/framework/misc/code-access-security-basics).
|
||||
|
||||
For information on how to save files, see [How to: Save Files Using the SaveFileDialog Component](how-to-save-files-using-the-savefiledialog-component.md).
|
||||
|
||||
|
||||
+4
-1
@@ -13,9 +13,11 @@ helpviewer_keywords:
|
||||
ms.assetid: babdf198-404c-485d-a914-ed370c6ecd99
|
||||
---
|
||||
# How to: Create a Resizable Windows Form for Data Entry
|
||||
A good layout responds well to changes in the dimensions of its parent form. You can use the <xref:System.Windows.Forms.TableLayoutPanel> control to arrange the layout of your form to resize and position your controls in a consistent way as the form's dimensions change. The <xref:System.Windows.Forms.TableLayoutPanel> control is also useful when changes in the contents of your controls cause changes in the layout. The process covered in this procedure can be done within the Visual Studio environment. Also see [Walkthrough: Creating a Resizable Windows Form for Data Entry](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/991eahec(v=vs.100)).
|
||||
|
||||
A good layout responds well to changes in the dimensions of its parent form. You can use the <xref:System.Windows.Forms.TableLayoutPanel> control to arrange the layout of your form to resize and position your controls in a consistent way as the form's dimensions change. The <xref:System.Windows.Forms.TableLayoutPanel> control is also useful when changes in the contents of your controls cause changes in the layout. The process covered in this procedure can be done within the Visual Studio environment. Also see [Walkthrough: Creating a Resizable Windows Form for Data Entry](/previous-versions/visualstudio/visual-studio-2010/991eahec(v=vs.100)).
|
||||
|
||||
## Example
|
||||
|
||||
The following example demonstrates how to use a <xref:System.Windows.Forms.TableLayoutPanel> control to build a layout that responds well when the user resizes the form. It also demonstrates a layout that responds well to localization.
|
||||
|
||||
[!code-cpp[System.Windows.Forms.TableLayoutPanel.DataEntryForm#1](~/samples/snippets/cpp/VS_Snippets_Winforms/System.Windows.Forms.TableLayoutPanel.DataEntryForm/cpp/basicdataentryform.cpp#1)]
|
||||
@@ -23,6 +25,7 @@ A good layout responds well to changes in the dimensions of its parent form. You
|
||||
[!code-vb[System.Windows.Forms.TableLayoutPanel.DataEntryForm#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.TableLayoutPanel.DataEntryForm/VB/basicdataentryform.vb#1)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- References to the System, System.Data, System.Drawing and System.Windows.Forms assemblies.
|
||||
|
||||
+3
-1
@@ -12,6 +12,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 24c5a2e3-058c-4b8d-a217-c06e6a130c2f
|
||||
---
|
||||
# How to: Create a Windows Forms Control That Shows Progress
|
||||
|
||||
The following code example shows a custom control called `FlashTrackBar` that can be used to show the user the level or the progress of an application. It uses a gradient to visually represent progress.
|
||||
|
||||
The `FlashTrackBar` control illustrates the following concepts:
|
||||
@@ -72,6 +73,7 @@ The following code example shows a custom control called `FlashTrackBar` that ca
|
||||
- <xref:System.Windows.Forms.Control.OnTextChanged%2A>
|
||||
|
||||
## Example
|
||||
|
||||
The `FlashTrackBar` control defines two UI type editors, `FlashTrackBarValueEditor` and `FlashTrackBarDarkenByEditor`, which are shown in the following code listings. The `HostApp` class uses the `FlashTrackBar` control on a Windows Form.
|
||||
|
||||
[!code-csharp[System.Windows.Forms.FlashTrackBar#1](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.FlashTrackBar/CS/FlashTrackBar.cs#1)]
|
||||
@@ -88,5 +90,5 @@ The following code example shows a custom control called `FlashTrackBar` that ca
|
||||
|
||||
## See also
|
||||
|
||||
- [Extending Design-Time Support](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120))
|
||||
- [Extending Design-Time Support](/previous-versions/visualstudio/visual-studio-2013/37899azc(v=vs.120))
|
||||
- [Windows Forms Control Development Basics](windows-forms-control-development-basics.md)
|
||||
|
||||
+8
-5
@@ -12,12 +12,14 @@ helpviewer_keywords:
|
||||
ms.assetid: d13eff2d-701c-4b6e-8838-3885cbfb7223
|
||||
---
|
||||
# How to: Design a Windows Forms Layout that Responds Well to Localization
|
||||
|
||||
Creating forms that are ready to be localized greatly speeds development for international markets. You can use the <xref:System.Windows.Forms.TableLayoutPanel> control to implement layouts that respond gracefully as controls resize due to changes in their <xref:System.Windows.Forms.Control.Text%2A> property values.
|
||||
|
||||
## Example
|
||||
This form demonstrates how to create a layout that proportionally adjusts when you translate displayed string values into other languages. This process of translation is called *localization*. For more information, see [Localization](https://docs.microsoft.com/dotnet/standard/globalization-localization/localization).
|
||||
|
||||
There is extensive support for this task in Visual Studio. See also [Walkthrough: Creating a Layout That Adjusts Proportion for Localization](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/7k9fa71y(v=vs.100)).
|
||||
This form demonstrates how to create a layout that proportionally adjusts when you translate displayed string values into other languages. This process of translation is called *localization*. For more information, see [Localization](/dotnet/standard/globalization-localization/localization).
|
||||
|
||||
There is extensive support for this task in Visual Studio. See also [Walkthrough: Creating a Layout That Adjusts Proportion for Localization](/previous-versions/visualstudio/visual-studio-2010/7k9fa71y(v=vs.100)).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.TableLayoutPanel.LocalizableForm#1](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.TableLayoutPanel.LocalizableForm/CS/localizableform.cs#1)]
|
||||
[!code-vb[System.Windows.Forms.TableLayoutPanel.LocalizableForm#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.TableLayoutPanel.LocalizableForm/VB/localizableform.vb#1)]
|
||||
@@ -38,11 +40,12 @@ Creating forms that are ready to be localized greatly speeds development for int
|
||||
|
||||
7. [Walkthrough: Laying Out Windows Forms Controls with Padding, Margins, and the AutoSize Property](windows-forms-controls-padding-autosize.md)
|
||||
|
||||
8. [How to: Support Localization on Windows Forms Using AutoSize and the TableLayoutPanel Control](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/1zkt8b33(v=vs.100))
|
||||
8. [How to: Support Localization on Windows Forms Using AutoSize and the TableLayoutPanel Control](/previous-versions/visualstudio/visual-studio-2010/1zkt8b33(v=vs.100))
|
||||
|
||||
9. [Walkthrough: Creating a Resizable Windows Form for Data Entry](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/991eahec(v=vs.100))
|
||||
9. [Walkthrough: Creating a Resizable Windows Form for Data Entry](/previous-versions/visualstudio/visual-studio-2010/991eahec(v=vs.100))
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- References to the System, System.Data, System.Drawing and System.Windows.Forms assemblies.
|
||||
@@ -51,4 +54,4 @@ Creating forms that are ready to be localized greatly speeds development for int
|
||||
|
||||
- <xref:System.Windows.Forms.TableLayoutPanel>
|
||||
- <xref:System.Windows.Forms.FlowLayoutPanel>
|
||||
- [Localization](https://docs.microsoft.com/dotnet/standard/globalization-localization/localization)
|
||||
- [Localization](/dotnet/standard/globalization-localization/localization)
|
||||
|
||||
+4
-4
@@ -29,7 +29,7 @@ This section walks you through the key steps for authoring a custom Windows Form
|
||||
public class FirstControl:Control {}
|
||||
```
|
||||
|
||||
2. Define properties. (You are not required to define properties, because a control inherits many properties from the <xref:System.Windows.Forms.Control> class, but most custom controls generally do define additional properties.) The following code fragment defines a property named `TextAlignment` that `FirstControl` uses to format the display of the <xref:System.Windows.Forms.Control.Text%2A> property inherited from <xref:System.Windows.Forms.Control>. For more information about defining properties, see [Properties Overview](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/65zdfbdt(v%3dvs.120)).
|
||||
2. Define properties. (You are not required to define properties, because a control inherits many properties from the <xref:System.Windows.Forms.Control> class, but most custom controls generally do define additional properties.) The following code fragment defines a property named `TextAlignment` that `FirstControl` uses to format the display of the <xref:System.Windows.Forms.Control.Text%2A> property inherited from <xref:System.Windows.Forms.Control>. For more information about defining properties, see [Properties Overview](/previous-versions/visualstudio/visual-studio-2013/65zdfbdt(v%3dvs.120)).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.FirstControl#3](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.FirstControl/CS/FirstControl.cs#3)]
|
||||
[!code-vb[System.Windows.Forms.FirstControl#3](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.FirstControl/VB/FirstControl.vb#3)]
|
||||
@@ -41,12 +41,12 @@ This section walks you through the key steps for authoring a custom Windows Form
|
||||
[!code-csharp[System.Windows.Forms.FirstControl#4](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.FirstControl/CS/FirstControl.cs#4)]
|
||||
[!code-vb[System.Windows.Forms.FirstControl#4](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.FirstControl/VB/FirstControl.vb#4)]
|
||||
|
||||
4. Provide attributes for your control. Attributes enable a visual designer to display your control and its properties and events appropriately at design time. The following code fragment applies attributes to the `TextAlignment` property. In a designer such as Visual Studio, the <xref:System.ComponentModel.CategoryAttribute.Category%2A> attribute (shown in the code fragment) causes the property to be displayed under a logical category. The <xref:System.ComponentModel.DescriptionAttribute.Description%2A> attribute causes a descriptive string to be displayed at the bottom of the **Properties** window when the `TextAlignment` property is selected. For more information about attributes, see [Design-Time Attributes for Components](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2013/tk67c2t8(v=vs.120)).
|
||||
4. Provide attributes for your control. Attributes enable a visual designer to display your control and its properties and events appropriately at design time. The following code fragment applies attributes to the `TextAlignment` property. In a designer such as Visual Studio, the <xref:System.ComponentModel.CategoryAttribute.Category%2A> attribute (shown in the code fragment) causes the property to be displayed under a logical category. The <xref:System.ComponentModel.DescriptionAttribute.Description%2A> attribute causes a descriptive string to be displayed at the bottom of the **Properties** window when the `TextAlignment` property is selected. For more information about attributes, see [Design-Time Attributes for Components](/previous-versions/visualstudio/visual-studio-2013/tk67c2t8(v=vs.120)).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.FirstControl#5](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.FirstControl/CS/FirstControl.cs#5)]
|
||||
[!code-vb[System.Windows.Forms.FirstControl#5](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.FirstControl/VB/FirstControl.vb#5)]
|
||||
|
||||
5. (optional) Provide resources for your control. You can provide a resource, such as a bitmap, for your control by using a compiler option (`/res` for C#) to package resources with your control. At run time, the resource can be retrieved using the methods of the <xref:System.Resources.ResourceManager> class. For more information about creating and using resources, see the [Resources in Desktop Apps](https://docs.microsoft.com/dotnet/framework/resources/index).
|
||||
5. (optional) Provide resources for your control. You can provide a resource, such as a bitmap, for your control by using a compiler option (`/res` for C#) to package resources with your control. At run time, the resource can be retrieved using the methods of the <xref:System.Resources.ResourceManager> class. For more information about creating and using resources, see the [Resources in Desktop Apps](/dotnet/framework/resources/index).
|
||||
|
||||
6. Compile and deploy your control. To compile and deploy `FirstControl,` execute the following steps:
|
||||
|
||||
@@ -62,7 +62,7 @@ This section walks you through the key steps for authoring a custom Windows Form
|
||||
csc -t:library -out:[path to your application's directory]/CustomWinControls.dll -r:System.dll -r:System.Windows.Forms.dll -r:System.Drawing.dll FirstControl.cs
|
||||
```
|
||||
|
||||
The `/t:library` compiler option tells the compiler that the assembly you are creating is a library (and not an executable). The `/out` option specifies the path and name of the assembly. The`/r` option provides the name of the assemblies that are referenced by your code. In this example, you create a private assembly that only your applications can use. Hence, you have to save it in your application's directory. For more information about packaging and deploying a control for distribution, see [Deployment](https://docs.microsoft.com/dotnet/framework/deployment/index).
|
||||
The `/t:library` compiler option tells the compiler that the assembly you are creating is a library (and not an executable). The `/out` option specifies the path and name of the assembly. The`/r` option provides the name of the assemblies that are referenced by your code. In this example, you create a private assembly that only your applications can use. Hence, you have to save it in your application's directory. For more information about packaging and deploying a control for distribution, see [Deployment](/dotnet/framework/deployment/index).
|
||||
|
||||
The following sample shows the code for `FirstControl`. The control is enclosed in the namespace `CustomWinControls`. A namespace provides a logical grouping of related types. You can create your control in a new or existing namespace. In C#, the `using` declaration (in Visual Basic, `Imports`) allows types to be accessed from a namespace without using the fully qualified name of the type. In the following example, the `using` declaration allows code to access the class <xref:System.Windows.Forms.Control> from <xref:System.Windows.Forms?displayProperty=nameWithType> as simply <xref:System.Windows.Forms.Control> instead of having to use the fully qualified name <xref:System.Windows.Forms.Control?displayProperty=nameWithType>.
|
||||
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ As you develop and distribute controls, you may want those controls to appear in
|
||||
|
||||
To display your control in the Choose Toolbox Items dialog box:
|
||||
|
||||
- Install your control assembly to the global assembly cache. For more information, see [How to: Install an Assembly into the Global Assembly Cache](https://docs.microsoft.com/dotnet/framework/app-domains/install-assembly-into-gac).
|
||||
- Install your control assembly to the global assembly cache. For more information, see [How to: Install an Assembly into the Global Assembly Cache](/dotnet/framework/app-domains/install-assembly-into-gac).
|
||||
|
||||
-or-
|
||||
|
||||
@@ -27,5 +27,5 @@ To display your control in the Choose Toolbox Items dialog box:
|
||||
## See also
|
||||
|
||||
- [Developing Windows Forms Controls at Design Time](developing-windows-forms-controls-at-design-time.md)
|
||||
- [How to: Install an Assembly into the Global Assembly Cache](https://docs.microsoft.com/dotnet/framework/app-domains/install-assembly-into-gac)
|
||||
- [How to: Install an Assembly into the Global Assembly Cache](/dotnet/framework/app-domains/install-assembly-into-gac)
|
||||
- [Walkthrough: Automatically Populating the Toolbox with Custom Components](walkthrough-automatically-populating-the-toolbox-with-custom-components.md)
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ The Windows Forms <xref:System.Windows.Forms.RichTextBox> control can display We
|
||||
In the example below, the <xref:System.Windows.Forms.RichTextBox.LinkClicked> event opens an instance of Internet Explorer to the URL specified in the <xref:System.Windows.Forms.RichTextBox.Text%2A> property of the <xref:System.Windows.Forms.RichTextBox> control. This example assumes a form with a <xref:System.Windows.Forms.RichTextBox> control.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> In calling the <xref:System.Diagnostics.Process.Start%2A?displayProperty=nameWithType> method, you will encounter a <xref:System.Security.SecurityException> exception if you are running the code in a partial-trust context because of insufficient privileges. For more information, see [Code Access Security Basics](https://docs.microsoft.com/dotnet/framework/misc/code-access-security-basics).
|
||||
> In calling the <xref:System.Diagnostics.Process.Start%2A?displayProperty=nameWithType> method, you will encounter a <xref:System.Security.SecurityException> exception if you are running the code in a partial-trust context because of insufficient privileges. For more information, see [Code Access Security Basics](/dotnet/framework/misc/code-access-security-basics).
|
||||
|
||||
```vb
|
||||
Public p As New System.Diagnostics.Process
|
||||
|
||||
+6
-2
@@ -18,11 +18,12 @@ helpviewer_keywords:
|
||||
ms.assetid: 8c33543c-9c08-4636-a65a-fdf714a529b7
|
||||
---
|
||||
# How to: Format Data in the Windows Forms DataGridView Control
|
||||
|
||||
The following procedures demonstrate basic formatting of cell values using the <xref:System.Windows.Forms.DataGridView.DefaultCellStyle%2A> property of a <xref:System.Windows.Forms.DataGridView> control and of specific columns in a control. For information about advanced data formatting, see [How to: Customize Data Formatting in the Windows Forms DataGridView Control](how-to-customize-data-formatting-in-the-windows-forms-datagridview-control.md).
|
||||
|
||||
### To format currency and date values
|
||||
|
||||
- Set the <xref:System.Windows.Forms.DataGridViewCellStyle.Format%2A> property of a <xref:System.Windows.Forms.DataGridViewCellStyle>. The following code example sets the format for specific columns using the <xref:System.Windows.Forms.DataGridViewColumn.DefaultCellStyle%2A> property of the columns. Values in the `UnitPrice` column appear in the current culture-specific currency format, with negative values surrounded by parentheses. Values in the `ShipDate` column appear in the current culture-specific short date format. For more information about <xref:System.Windows.Forms.DataGridViewCellStyle.Format%2A> values, see [Formatting Types](https://docs.microsoft.com/dotnet/standard/base-types/formatting-types).
|
||||
- Set the <xref:System.Windows.Forms.DataGridViewCellStyle.Format%2A> property of a <xref:System.Windows.Forms.DataGridViewCellStyle>. The following code example sets the format for specific columns using the <xref:System.Windows.Forms.DataGridViewColumn.DefaultCellStyle%2A> property of the columns. Values in the `UnitPrice` column appear in the current culture-specific currency format, with negative values surrounded by parentheses. Values in the `ShipDate` column appear in the current culture-specific short date format. For more information about <xref:System.Windows.Forms.DataGridViewCellStyle.Format%2A> values, see [Formatting Types](/dotnet/standard/base-types/formatting-types).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridViewMisc#071](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/CS/datagridviewmisc.cs#071)]
|
||||
[!code-vb[System.Windows.Forms.DataGridViewMisc#071](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/VB/datagridviewmisc.vb#071)]
|
||||
@@ -49,10 +50,12 @@ The following procedures demonstrate basic formatting of cell values using the <
|
||||
[!code-vb[System.Windows.Forms.DataGridViewMisc#072](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/VB/datagridviewmisc.vb#072)]
|
||||
|
||||
## Example
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridViewMisc#070](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/CS/datagridviewmisc.cs#070)]
|
||||
[!code-vb[System.Windows.Forms.DataGridViewMisc#070](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewMisc/VB/datagridviewmisc.vb#070)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
These examples require:
|
||||
|
||||
- A <xref:System.Windows.Forms.DataGridView> control named `dataGridView1` that contains a column named `UnitPrice`, a column named `ShipDate`, and a column named `CustomerName`.
|
||||
@@ -60,6 +63,7 @@ The following procedures demonstrate basic formatting of cell values using the <
|
||||
- References to the <xref:System?displayProperty=nameWithType>, <xref:System.Drawing?displayProperty=nameWithType>, and <xref:System.Windows.Forms?displayProperty=nameWithType> assemblies.
|
||||
|
||||
## Robust Programming
|
||||
|
||||
For maximum scalability, you should share <xref:System.Windows.Forms.DataGridViewCellStyle> objects across multiple rows, columns, or cells that use the same styles rather than setting the style properties for each element separately. For more information, see [Best Practices for Scaling the Windows Forms DataGridView Control](best-practices-for-scaling-the-windows-forms-datagridview-control.md).
|
||||
|
||||
## See also
|
||||
@@ -71,4 +75,4 @@ The following procedures demonstrate basic formatting of cell values using the <
|
||||
- [Cell Styles in the Windows Forms DataGridView Control](cell-styles-in-the-windows-forms-datagridview-control.md)
|
||||
- [Data Formatting in the Windows Forms DataGridView Control](data-formatting-in-the-windows-forms-datagridview-control.md)
|
||||
- [How to: Customize Data Formatting in the Windows Forms DataGridView Control](how-to-customize-data-formatting-in-the-windows-forms-datagridview-control.md)
|
||||
- [Formatting Types](https://docs.microsoft.com/dotnet/standard/base-types/formatting-types)
|
||||
- [Formatting Types](/dotnet/standard/base-types/formatting-types)
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ There are three basic aspects of formatting the <xref:System.Windows.Forms.DataG
|
||||
|
||||
As an initial step in formatting a data grid, you can set the properties of the <xref:System.Windows.Forms.DataGrid> itself. These color and format choices form a base from which you can then make changes depending on the data tables and columns displayed.
|
||||
|
||||
The following procedure requires a **Windows Application** project with a form containing a <xref:System.Windows.Forms.DataGrid> control. For information about setting up such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). In Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox** by default. For more information, see [How to: Add Items to the Toolbox](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)).
|
||||
The following procedure requires a **Windows Application** project with a form containing a <xref:System.Windows.Forms.DataGrid> control. For information about setting up such a project, see [How to: Create a Windows Forms application project](/visualstudio/ide/step-1-create-a-windows-forms-application-project) and [How to: Add Controls to Windows Forms](how-to-add-controls-to-windows-forms.md). In Visual Studio 2005, the <xref:System.Windows.Forms.DataGrid> control is not in the **Toolbox** by default. For more information, see [How to: Add Items to the Toolbox](/previous-versions/visualstudio/visual-studio-2010/ms165355(v=vs.100)).
|
||||
|
||||
### To establish a default style for the DataGrid control
|
||||
|
||||
@@ -87,7 +87,7 @@ The following procedure requires a **Windows Application** project with a form c
|
||||
With the **DataGridColumnStyle Collection Editor**, you can add and remove column styles, set display and layout properties, and set the mapping name and formatting strings for the data columns.
|
||||
|
||||
> [!NOTE]
|
||||
> For more information about formatting strings, see [Formatting Types](https://docs.microsoft.com/dotnet/standard/base-types/formatting-types).
|
||||
> For more information about formatting strings, see [Formatting Types](/dotnet/standard/base-types/formatting-types).
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+6
-3
@@ -19,6 +19,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 9f483f93-1613-4be1-a021-b4934e9c78f3
|
||||
---
|
||||
# How to: Implement a Form That Uses a Background Operation
|
||||
|
||||
The following example program creates a form that calculates Fibonacci numbers. The calculation runs on a thread that is separate from the user interface thread, so the user interface continues to run without delays as the calculation proceeds.
|
||||
|
||||
There is extensive support for this task in Visual Studio.
|
||||
@@ -26,11 +27,13 @@ The following example program creates a form that calculates Fibonacci numbers.
|
||||
Also see [Walkthrough: Implementing a Form That Uses a Background Operation](walkthrough-implementing-a-form-that-uses-a-background-operation.md).
|
||||
|
||||
## Example
|
||||
|
||||
[!code-cpp[System.ComponentModel.BackgroundWorker#1](~/samples/snippets/cpp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CPP/fibonacciform.cpp#1)]
|
||||
[!code-csharp[System.ComponentModel.BackgroundWorker#1](~/samples/snippets/csharp/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/CS/fibonacciform.cs#1)]
|
||||
[!code-vb[System.ComponentModel.BackgroundWorker#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.ComponentModel.BackgroundWorker/VB/fibonacciform.vb#1)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- References to the System, System.Drawing, and System.Windows.Forms assemblies.
|
||||
@@ -38,11 +41,11 @@ The following example program creates a form that calculates Fibonacci numbers.
|
||||
## Robust Programming
|
||||
|
||||
> [!CAUTION]
|
||||
> When using multithreading of any sort, you potentially expose yourself to very serious and complex bugs. Consult the [Managed Threading Best Practices](https://docs.microsoft.com/dotnet/standard/threading/managed-threading-best-practices) before implementing any solution that uses multithreading.
|
||||
> When using multithreading of any sort, you potentially expose yourself to very serious and complex bugs. Consult the [Managed Threading Best Practices](/dotnet/standard/threading/managed-threading-best-practices) before implementing any solution that uses multithreading.
|
||||
|
||||
## See also
|
||||
|
||||
- <xref:System.ComponentModel.BackgroundWorker>
|
||||
- <xref:System.ComponentModel.DoWorkEventArgs>
|
||||
- [Event-based Asynchronous Pattern Overview](https://docs.microsoft.com/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
- [Managed Threading Best Practices](https://docs.microsoft.com/dotnet/standard/threading/managed-threading-best-practices)
|
||||
- [Event-based Asynchronous Pattern Overview](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
- [Managed Threading Best Practices](/dotnet/standard/threading/managed-threading-best-practices)
|
||||
|
||||
+1
-1
@@ -85,5 +85,5 @@ If you want to extend the functionality of an existing control, you can create a
|
||||
- [How to: Inherit from the Control Class](how-to-inherit-from-the-control-class.md)
|
||||
- [How to: Inherit from the UserControl Class](how-to-inherit-from-the-usercontrol-class.md)
|
||||
- [How to: Author Controls for Windows Forms](how-to-author-controls-for-windows-forms.md)
|
||||
- [Troubleshooting Inherited Event Handlers in Visual Basic](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
- [Troubleshooting Inherited Event Handlers in Visual Basic](/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
- [Walkthrough: Inheriting from a Windows Forms Control](walkthrough-inheriting-from-a-windows-forms-control-with-visual-csharp.md)
|
||||
|
||||
+1
-1
@@ -44,5 +44,5 @@ If you want to create a completely custom control to use on a Windows Form, you
|
||||
- [How to: Inherit from the UserControl Class](how-to-inherit-from-the-usercontrol-class.md)
|
||||
- [How to: Inherit from Existing Windows Forms Controls](how-to-inherit-from-existing-windows-forms-controls.md)
|
||||
- [How to: Author Controls for Windows Forms](how-to-author-controls-for-windows-forms.md)
|
||||
- [Troubleshooting Inherited Event Handlers in Visual Basic](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
- [Troubleshooting Inherited Event Handlers in Visual Basic](/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
- [Developing Windows Forms Controls at Design Time](developing-windows-forms-controls-at-design-time.md)
|
||||
|
||||
+1
-1
@@ -35,5 +35,5 @@ To combine the functionality of one or more Windows Forms controls with custom c
|
||||
- [How to: Inherit from the Control Class](how-to-inherit-from-the-control-class.md)
|
||||
- [How to: Inherit from Existing Windows Forms Controls](how-to-inherit-from-existing-windows-forms-controls.md)
|
||||
- [How to: Author Controls for Windows Forms](how-to-author-controls-for-windows-forms.md)
|
||||
- [Troubleshoot Inherited Event Handlers in Visual Basic](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
- [Troubleshoot Inherited Event Handlers in Visual Basic](/dotnet/visual-basic/programming-guide/language-features/events/troubleshooting-inherited-event-handlers)
|
||||
- [How to: Test the Run-Time Behavior of a UserControl](how-to-test-the-run-time-behavior-of-a-usercontrol.md)
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 427f8928-ebcf-4beb-887f-695b905d5134
|
||||
---
|
||||
# How to: Iterate Through All Nodes of a Windows Forms TreeView Control
|
||||
|
||||
It is sometimes useful to examine every node in a Windows Forms <xref:System.Windows.Forms.TreeView> control in order to perform some calculation on the node values. This operation can be done using a recursive procedure (recursive method in C# and C++) that iterates through each node in each collection of the tree.
|
||||
|
||||
Each <xref:System.Windows.Forms.TreeNode> object in a tree view has properties that you can use to navigate the tree view: <xref:System.Windows.Forms.TreeNode.FirstNode%2A>, <xref:System.Windows.Forms.TreeNode.LastNode%2A>, <xref:System.Windows.Forms.TreeNode.NextNode%2A>, <xref:System.Windows.Forms.TreeNode.PrevNode%2A>, and <xref:System.Windows.Forms.TreeNode.Parent%2A>. The value of the <xref:System.Windows.Forms.TreeNode.Parent%2A> property is the parent node of the current node. The child nodes of the current node, if there are any, are listed in its <xref:System.Windows.Forms.TreeNode.Nodes%2A> property. The <xref:System.Windows.Forms.TreeView> control itself has the <xref:System.Windows.Forms.TreeView.TopNode%2A> property, which is the root node of the entire tree view.
|
||||
@@ -120,4 +121,4 @@ It is sometimes useful to examine every node in a Windows Forms <xref:System.Win
|
||||
## See also
|
||||
|
||||
- [TreeView Control](treeview-control-windows-forms.md)
|
||||
- [Recursive Procedures](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/language-features/procedures/recursive-procedures)
|
||||
- [Recursive Procedures](/dotnet/visual-basic/programming-guide/language-features/procedures/recursive-procedures)
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ The Windows Forms <xref:System.Windows.Forms.RichTextBox> control can display a
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> To run this process, your assembly may require a privilege level granted by the <xref:System.Security.Permissions.FileIOPermission?displayProperty=nameWithType> class. If you are running in a partial-trust context, the process might throw an exception because of insufficient privileges. For more information, see [Code Access Security Basics](https://docs.microsoft.com/dotnet/framework/misc/code-access-security-basics).
|
||||
> To run this process, your assembly may require a privilege level granted by the <xref:System.Security.Permissions.FileIOPermission?displayProperty=nameWithType> class. If you are running in a partial-trust context, the process might throw an exception because of insufficient privileges. For more information, see [Code Access Security Basics](/dotnet/framework/misc/code-access-security-basics).
|
||||
|
||||
## See also
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ ms.assetid: 138f38b6-1099-4fd5-910c-390b41cbad35
|
||||
---
|
||||
# How to: Make thread-safe calls to Windows Forms controls
|
||||
|
||||
Multithreading can improve the performance of Windows Forms apps, but access to Windows Forms controls isn't inherently thread-safe. Multithreading can expose your code to very serious and complex bugs. Two or more threads manipulating a control can force the control into an inconsistent state and lead to race conditions, deadlocks, and freezes or hangs. If you implement multithreading in your app, be sure to call cross-thread controls in a thread-safe way. For more information, see [Managed threading best practices](https://docs.microsoft.com/dotnet/standard/threading/managed-threading-best-practices).
|
||||
Multithreading can improve the performance of Windows Forms apps, but access to Windows Forms controls isn't inherently thread-safe. Multithreading can expose your code to very serious and complex bugs. Two or more threads manipulating a control can force the control into an inconsistent state and lead to race conditions, deadlocks, and freezes or hangs. If you implement multithreading in your app, be sure to call cross-thread controls in a thread-safe way. For more information, see [Managed threading best practices](/dotnet/standard/threading/managed-threading-best-practices).
|
||||
|
||||
There are two ways to safely call a Windows Forms control from a thread that didn't create that control. You can use the <xref:System.Windows.Forms.Control.Invoke%2A?displayProperty=fullName> method to call a delegate created in the main thread, which in turn calls the control. Or, you can implement a <xref:System.ComponentModel.BackgroundWorker?displayProperty=nameWithType>, which uses an event-driven model to separate work done in the background thread from reporting on the results.
|
||||
|
||||
@@ -61,7 +61,7 @@ The following code examples demonstrate two ways to safely call a Windows Forms
|
||||
|
||||
In both examples, the background thread sleeps for one second to simulate work being done in that thread.
|
||||
|
||||
You can build and run these examples as .NET Framework apps from the C# or Visual Basic command line. For more information, see [Command-line building with csc.exe](https://docs.microsoft.com/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe) or [Build from the command line (Visual Basic)](https://docs.microsoft.com/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line).
|
||||
You can build and run these examples as .NET Framework apps from the C# or Visual Basic command line. For more information, see [Command-line building with csc.exe](/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe) or [Build from the command line (Visual Basic)](/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line).
|
||||
|
||||
Starting with .NET Core 3.0, you can also build and run the examples as Windows .NET Core apps from a folder that has a .NET Core Windows Forms *\<folder name>.csproj* project file.
|
||||
|
||||
|
||||
+2
-2
@@ -15,9 +15,9 @@ ms.assetid: 9d88367a-cc21-4ffd-be74-89fd63767d35
|
||||
|
||||
The <xref:System.Windows.Forms.OpenFileDialog?displayProperty=nameWithType> component opens the Windows dialog box for browsing and selecting files. To open and read the selected files, you can use the <xref:System.Windows.Forms.OpenFileDialog.OpenFile%2A?displayProperty=nameWithType> method, or create an instance of the <xref:System.IO.StreamReader?displayProperty=nameWithType> class. The following examples show both approaches.
|
||||
|
||||
In .NET Framework, to get or set the <xref:System.Windows.Forms.FileDialog.FileName%2A> property requires a privilege level granted by the <xref:System.Security.Permissions.FileIOPermission?displayProperty=nameWithType> class. The examples run a <xref:System.Security.Permissions.FileIOPermission> permission check, and can throw an exception due to insufficient privileges if run in a partial-trust context. For more information, see [Code access security basics](https://docs.microsoft.com/dotnet/framework/misc/code-access-security-basics).
|
||||
In .NET Framework, to get or set the <xref:System.Windows.Forms.FileDialog.FileName%2A> property requires a privilege level granted by the <xref:System.Security.Permissions.FileIOPermission?displayProperty=nameWithType> class. The examples run a <xref:System.Security.Permissions.FileIOPermission> permission check, and can throw an exception due to insufficient privileges if run in a partial-trust context. For more information, see [Code access security basics](/dotnet/framework/misc/code-access-security-basics).
|
||||
|
||||
You can build and run these examples as .NET Framework apps from the C# or Visual Basic command line. For more information, see [Command-line building with csc.exe](https://docs.microsoft.com/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe) or [Build from the command line](https://docs.microsoft.com/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line).
|
||||
You can build and run these examples as .NET Framework apps from the C# or Visual Basic command line. For more information, see [Command-line building with csc.exe](/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe) or [Build from the command line](/dotnet/visual-basic/reference/command-line-compiler/building-from-the-command-line).
|
||||
|
||||
Starting with .NET Core 3.0, you can also build and run the examples as Windows .NET Core apps from a folder that has a .NET Core Windows Forms *\<folder name>.csproj* project file.
|
||||
|
||||
|
||||
+1
-1
@@ -100,4 +100,4 @@ button1->Left += 200;
|
||||
- [Labeling Individual Windows Forms Controls and Providing Shortcuts to Them](labeling-individual-windows-forms-controls-and-providing-shortcuts-to-them.md)
|
||||
- [Controls to Use on Windows Forms](controls-to-use-on-windows-forms.md)
|
||||
- [Windows Forms Controls by Function](windows-forms-controls-by-function.md)
|
||||
- [How to: Set the Screen Location of Windows Forms](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/52aha046(v=vs.100))
|
||||
- [How to: Set the Screen Location of Windows Forms](/previous-versions/visualstudio/visual-studio-2010/52aha046(v=vs.100))
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ manager: jillfra
|
||||
---
|
||||
# How to: Provide a Toolbox Bitmap for a Control
|
||||
|
||||
If you want to have a special icon for your control appear in the **Toolbox** of Visual Studio, you can specify a particular image by using the <xref:System.Drawing.ToolboxBitmapAttribute>. This class is an *attribute*, a special kind of class you can attach to other classes. For more information about attributes, see [Attributes overview (Visual Basic)](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/concepts/attributes/index) for Visual Basic or [Attributes (C#)](https://docs.microsoft.com/dotnet/csharp/programming-guide/concepts/attributes/index) for C#.
|
||||
If you want to have a special icon for your control appear in the **Toolbox** of Visual Studio, you can specify a particular image by using the <xref:System.Drawing.ToolboxBitmapAttribute>. This class is an *attribute*, a special kind of class you can attach to other classes. For more information about attributes, see [Attributes overview (Visual Basic)](/dotnet/visual-basic/programming-guide/concepts/attributes/index) for Visual Basic or [Attributes (C#)](/dotnet/csharp/programming-guide/concepts/attributes/index) for C#.
|
||||
|
||||
Using the <xref:System.Drawing.ToolboxBitmapAttribute>, you can specify a string that indicates the path and file name for a 16 by 16 pixel bitmap. This bitmap then appears next to your control when added to the **Toolbox**. You can also specify a <xref:System.Type>, in which case the bitmap associated with that type is loaded. If you specify both a <xref:System.Type> and a string, the control searches for an image resource with the name specified by the string parameter in the assembly containing the type specified by the <xref:System.Type> parameter.
|
||||
|
||||
@@ -66,5 +66,5 @@ Using the <xref:System.Drawing.ToolboxBitmapAttribute>, you can specify a string
|
||||
- <xref:System.Drawing.ToolboxBitmapAttribute>
|
||||
- [Walkthrough: Automatically Populating the Toolbox with Custom Components](walkthrough-automatically-populating-the-toolbox-with-custom-components.md)
|
||||
- [Developing Windows Forms Controls at Design Time](developing-windows-forms-controls-at-design-time.md)
|
||||
- [Attributes overview (Visual Basic)](https://docs.microsoft.com/dotnet/visual-basic/programming-guide/concepts/attributes/index)
|
||||
- [Attributes (C#)](https://docs.microsoft.com/dotnet/csharp/programming-guide/concepts/attributes/index)
|
||||
- [Attributes overview (Visual Basic)](/dotnet/visual-basic/programming-guide/concepts/attributes/index)
|
||||
- [Attributes (C#)](/dotnet/csharp/programming-guide/concepts/attributes/index)
|
||||
|
||||
+1
-1
@@ -36,4 +36,4 @@ In Visual Studio, select the control to be resized and drag one of the eight siz
|
||||
- [Labeling Individual Windows Forms Controls and Providing Shortcuts to Them](labeling-individual-windows-forms-controls-and-providing-shortcuts-to-them.md)
|
||||
- [Controls to Use on Windows Forms](controls-to-use-on-windows-forms.md)
|
||||
- [Windows Forms Controls by Function](windows-forms-controls-by-function.md)
|
||||
- [How to: Resize Windows Forms Using the Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/37k2zkwx(v=vs.100))
|
||||
- [How to: Resize Windows Forms Using the Designer](/previous-versions/visualstudio/visual-studio-2010/37k2zkwx(v=vs.100))
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ The <xref:System.Windows.Forms.SaveFileDialog> component allows users to browse
|
||||
In the example below, there is a <xref:System.Windows.Forms.Button> control with an image assigned to it. When you click the button, a <xref:System.Windows.Forms.SaveFileDialog> component is instantiated with a filter that allows files of type .gif, .jpeg, and .bmp. If a file of this type is selected in the Save File dialog box, the button's image is saved.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> To get or set the <xref:System.Windows.Forms.FileDialog.FileName%2A> property, your assembly requires a privilege level granted by the <xref:System.Security.Permissions.FileIOPermission?displayProperty=nameWithType> class. If you are running in a partial-trust context, the process might throw an exception due to insufficient privileges. For more information, see [Code Access Security Basics](https://docs.microsoft.com/dotnet/framework/misc/code-access-security-basics).
|
||||
> To get or set the <xref:System.Windows.Forms.FileDialog.FileName%2A> property, your assembly requires a privilege level granted by the <xref:System.Security.Permissions.FileIOPermission?displayProperty=nameWithType> class. If you are running in a partial-trust context, the process might throw an exception due to insufficient privileges. For more information, see [Code Access Security Basics](/dotnet/framework/misc/code-access-security-basics).
|
||||
|
||||
The example assumes your form has a <xref:System.Windows.Forms.Button> control with its <xref:System.Windows.Forms.ButtonBase.Image%2A> property set to a file of type .gif, .jpeg, or .bmp.
|
||||
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 18ca41d0-68a5-4660-985e-a6c1fbc01d76
|
||||
---
|
||||
# How to: Set Pictures at Run Time (Windows Forms)
|
||||
|
||||
You can programmatically set the image displayed by a Windows Forms <xref:System.Windows.Forms.PictureBox> control.
|
||||
|
||||
### To set a picture programmatically
|
||||
@@ -87,7 +88,7 @@ You can programmatically set the image displayed by a Windows Forms <xref:System
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> For more information on why you should use the <xref:System.Drawing.Image.Dispose%2A> method in this way, see [Cleaning Up Unmanaged Resources](https://docs.microsoft.com/dotnet/standard/garbage-collection/unmanage).
|
||||
> For more information on why you should use the <xref:System.Drawing.Image.Dispose%2A> method in this way, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanage).
|
||||
|
||||
This code will clear the image even if a graphic was loaded into the control at design time.
|
||||
|
||||
|
||||
+1
-2
@@ -18,7 +18,6 @@ When you develop a <xref:System.Windows.Forms.UserControl>, you need to test its
|
||||
|
||||
> [!IMPORTANT]
|
||||
> For the test container to load your <xref:System.Windows.Forms.UserControl>, the control must have at least one public constructor.
|
||||
|
||||
> [!NOTE]
|
||||
> A Visual C++ control cannot be tested using the **UserControl Test Container**.
|
||||
|
||||
@@ -65,4 +64,4 @@ You can test user controls from other projects in your current project's test co
|
||||
- <xref:System.Windows.Forms.UserControl>
|
||||
- [How to: Author Composite Controls](how-to-author-composite-controls.md)
|
||||
- [Walkthrough: Authoring a Composite Control](walkthrough-authoring-a-composite-control-with-visual-csharp.md)
|
||||
- [User Control Designer](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/183c3hth(v=vs.100))
|
||||
- [User Control Designer](/previous-versions/visualstudio/visual-studio-2010/183c3hth(v=vs.100))
|
||||
|
||||
+4
-2
@@ -12,9 +12,10 @@ helpviewer_keywords:
|
||||
ms.assetid: 7fe3956f-5b8f-4f78-8aae-c9eb0b28f13a
|
||||
---
|
||||
# How to: Use a Background Thread to Search for Files
|
||||
|
||||
The <xref:System.ComponentModel.BackgroundWorker> component replaces and adds functionality to the <xref:System.Threading> namespace; however, the <xref:System.Threading> namespace is retained for both backward compatibility and future use, if you choose. For more information, see [BackgroundWorker Component Overview](backgroundworker-component-overview.md).
|
||||
|
||||
Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment-threaded. The STA model implies that a window can be created on any thread, but it cannot switch threads once created, and all function calls to it must occur on its creation thread. Outside Windows Forms, classes in the .NET Framework use the free threading model. For information about threading in the .NET Framework, see [Threading](https://docs.microsoft.com/dotnet/standard/threading/index).
|
||||
Windows Forms uses the single-threaded apartment (STA) model because Windows Forms is based on native Win32 windows that are inherently apartment-threaded. The STA model implies that a window can be created on any thread, but it cannot switch threads once created, and all function calls to it must occur on its creation thread. Outside Windows Forms, classes in the .NET Framework use the free threading model. For information about threading in the .NET Framework, see [Threading](/dotnet/standard/threading/index).
|
||||
|
||||
The STA model requires that any methods on a control that need to be called from outside the control's creation thread must be marshaled to (executed on) the control's creation thread. The base class <xref:System.Windows.Forms.Control> provides several methods (<xref:System.Windows.Forms.Control.Invoke%2A>, <xref:System.Windows.Forms.Control.BeginInvoke%2A>, and <xref:System.Windows.Forms.Control.EndInvoke%2A>) for this purpose. <xref:System.Windows.Forms.Control.Invoke%2A> makes synchronous method calls; <xref:System.Windows.Forms.Control.BeginInvoke%2A> makes asynchronous method calls.
|
||||
|
||||
@@ -563,6 +564,7 @@ namespace Microsoft.Samples.DirectorySearcher
|
||||
```
|
||||
|
||||
## Using the Multithreaded Control on a Form
|
||||
|
||||
The following example shows how the multithreaded `DirectorySearcher` control can be used on a form.
|
||||
|
||||
```vb
|
||||
@@ -758,4 +760,4 @@ namespace SampleUsage
|
||||
|
||||
- <xref:System.ComponentModel.BackgroundWorker>
|
||||
- [Developing Custom Windows Forms Controls with the .NET Framework](developing-custom-windows-forms-controls.md)
|
||||
- [Event-based Asynchronous Pattern Overview](https://docs.microsoft.com/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
- [Event-based Asynchronous Pattern Overview](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-overview)
|
||||
|
||||
+6
-2
@@ -12,21 +12,25 @@ helpviewer_keywords:
|
||||
ms.assetid: d10aef35-701e-4a3c-a684-2a2ed1aeaca6
|
||||
---
|
||||
# How to: Validate Data in the Windows Forms DataGridView Control
|
||||
|
||||
The following code example demonstrates how to validate data entered by a user into a <xref:System.Windows.Forms.DataGridView> control. In this example, the <xref:System.Windows.Forms.DataGridView> is populated with rows from the `Customers` table of the Northwind sample database. When the user edits a cell in the `CompanyName` column, its value is tested for validity by checking that it is not empty. If the event handler for the <xref:System.Windows.Forms.DataGridView.CellValidating> event finds that the value is an empty string, the <xref:System.Windows.Forms.DataGridView> prevents the user from exiting the cell until a non-empty string is entered.
|
||||
|
||||
For a complete explanation of this code example, see [Walkthrough: Validating Data in the Windows Forms DataGridView Control](walkthrough-validating-data-in-the-windows-forms-datagridview-control.md).
|
||||
|
||||
## Example
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridViewDataValidation#00](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewDataValidation/CS/datavalidation.cs#00)]
|
||||
[!code-vb[System.Windows.Forms.DataGridViewDataValidation#00](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridViewDataValidation/VB/datavalidation.vb#00)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- References to the System, System.Data, System.Windows.Forms and System.XML assemblies.
|
||||
|
||||
## .NET Framework Security
|
||||
Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
## See also
|
||||
|
||||
@@ -35,4 +39,4 @@ The following code example demonstrates how to validate data entered by a user i
|
||||
- [Walkthrough: Validating Data in the Windows Forms DataGridView Control](walkthrough-validating-data-in-the-windows-forms-datagridview-control.md)
|
||||
- [Data Entry in the Windows Forms DataGridView Control](data-entry-in-the-windows-forms-datagridview-control.md)
|
||||
- [Walkthrough: Handling Errors that Occur During Data Entry in the Windows Forms DataGridView Control](handling-errors-that-occur-during-data-entry-in-the-datagrid.md)
|
||||
- [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
- [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information)
|
||||
|
||||
+7
-1
@@ -14,6 +14,7 @@ helpviewer_keywords:
|
||||
ms.assetid: c2a052b9-423c-4ff7-91dc-d8c7c79345f6
|
||||
---
|
||||
# Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control
|
||||
|
||||
One reason to implement virtual mode in the <xref:System.Windows.Forms.DataGridView> control is to retrieve data only as it is needed. This is called *just-in-time data loading*.
|
||||
|
||||
If you are working with a very large table in a remote database, for example, you might want to avoid startup delays by retrieving only the data that is necessary for display and retrieving additional data only when the user scrolls new rows into view. If the client computers running your application have a limited amount of memory available for storing data, you might also want to discard unused data when retrieving new values from the database.
|
||||
@@ -23,17 +24,19 @@ One reason to implement virtual mode in the <xref:System.Windows.Forms.DataGridV
|
||||
To copy the code in this topic as a single listing, see [How to: Implement Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control](virtual-mode-with-just-in-time-data-loading-in-the-datagrid.md).
|
||||
|
||||
## The Form
|
||||
|
||||
The following code example defines a form containing a read-only <xref:System.Windows.Forms.DataGridView> control that interacts with a `Cache` object through a <xref:System.Windows.Forms.DataGridView.CellValueNeeded> event handler. The `Cache` object manages the locally stored values and uses a `DataRetriever` object to retrieve values from the Orders table of the sample Northwind database. The `DataRetriever` object, which implements the `IDataPageRetriever` interface required by the `Cache` class, is also used to initialize the <xref:System.Windows.Forms.DataGridView> control rows and columns.
|
||||
|
||||
The `IDataPageRetriever`, `DataRetriever`, and `Cache` types are described later in this topic.
|
||||
|
||||
> [!NOTE]
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridView.Virtual_lazyloading#100](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.Virtual_lazyloading/CS/lazyloading.cs#100)]
|
||||
[!code-vb[System.Windows.Forms.DataGridView.Virtual_lazyloading#100](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.Virtual_lazyloading/VB/lazyloading.vb#100)]
|
||||
|
||||
## The IDataPageRetriever Interface
|
||||
|
||||
The following code example defines the `IDataPageRetriever` interface, which is implemented by the `DataRetriever` class. The only method declared in this interface is the `SupplyPageOfData` method, which requires an initial row index and a count of the number of rows in a single page of data. These values are used by the implementer to retrieve a subset of data from a data source.
|
||||
|
||||
A `Cache` object uses an implementation of this interface during construction to load two initial pages of data. Whenever an uncached value is needed, the cache discards one of these pages and requests a new page containing the value from the `IDataPageRetriever`.
|
||||
@@ -42,12 +45,14 @@ One reason to implement virtual mode in the <xref:System.Windows.Forms.DataGridV
|
||||
[!code-vb[System.Windows.Forms.DataGridView.Virtual_lazyloading#201](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.Virtual_lazyloading/VB/lazyloading.vb#201)]
|
||||
|
||||
## The DataRetriever Class
|
||||
|
||||
The following code example defines the `DataRetriever` class, which implements the `IDataPageRetriever` interface to retrieve pages of data from a server. The `DataRetriever` class also provides `Columns` and `RowCount` properties, which the <xref:System.Windows.Forms.DataGridView> control uses to create the necessary columns and to add the appropriate number of empty rows to the <xref:System.Windows.Forms.DataGridView.Rows%2A> collection. Adding the empty rows is necessary so that the control will behave as though it contains all the data in the table. This means that the scroll box in the scroll bar will have the appropriate size, and the user will be able to access any row in the table. The rows are filled by the <xref:System.Windows.Forms.DataGridView.CellValueNeeded> event handler only when they are scrolled into view.
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataGridView.Virtual_lazyloading#200](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.Virtual_lazyloading/CS/lazyloading.cs#200)]
|
||||
[!code-vb[System.Windows.Forms.DataGridView.Virtual_lazyloading#200](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.Virtual_lazyloading/VB/lazyloading.vb#200)]
|
||||
|
||||
## The Cache Class
|
||||
|
||||
The following code example defines the `Cache` class, which manages two pages of data populated through an `IDataPageRetriever` implementation. The `Cache` class defines an inner `DataPage` structure, which contains a <xref:System.Data.DataTable> to store the values in a single cache page and which calculates the row indexes that represent the upper and lower boundaries of the page.
|
||||
|
||||
The `Cache` class loads two pages of data at construction time. Whenever the <xref:System.Windows.Forms.DataGridView.CellValueNeeded> event requests a value, the `Cache` object determines if the value is available in one of its two pages and, if so, returns it. If the value is not available locally, the `Cache` object determines which of its two pages is farthest from the currently displayed rows and replaces the page with a new one containing the requested value, which it then returns.
|
||||
@@ -58,6 +63,7 @@ One reason to implement virtual mode in the <xref:System.Windows.Forms.DataGridV
|
||||
[!code-vb[System.Windows.Forms.DataGridView.Virtual_lazyloading#300](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataGridView.Virtual_lazyloading/VB/lazyloading.vb#300)]
|
||||
|
||||
## Additional Considerations
|
||||
|
||||
The previous code examples are provided as a demonstration of just-in-time data loading. You will need to modify the code for your own needs to achieve maximum efficiency. At minimum, you will need to choose an appropriate value for the number of rows per page of data in the cache. This value is passed into the `Cache` constructor. The number of rows per page should be no less than the number of rows that can be displayed simultaneously in your <xref:System.Windows.Forms.DataGridView> control.
|
||||
|
||||
For best results, you will need to conduct performance testing and usability testing to determine the requirements of your system and your users. Several factors that you will need to take into consideration include the amount of memory in the client machines running your application, the available bandwidth of the network connection used, and the latency of the server used. The bandwidth and latency should be determined at times of peak usage.
|
||||
|
||||
@@ -34,5 +34,5 @@ Describes techniques for creating custom controls through design and inheritance
|
||||
|
||||
## Related sections
|
||||
|
||||
[Client Applications](https://docs.microsoft.com/dotnet/framework/develop-client-apps)\
|
||||
[Client Applications](/dotnet/framework/develop-client-apps)\
|
||||
Provides an overview of developing Windows-based applications.
|
||||
|
||||
+3
-1
@@ -9,11 +9,13 @@ helpviewer_keywords:
|
||||
ms.assetid: 7e5fb513-77e7-4046-a8e8-aab94e61ca0f
|
||||
---
|
||||
# Limitations of the Windows Forms Timer Component's Interval Property
|
||||
|
||||
The Windows Forms <xref:System.Windows.Forms.Timer> component has an <xref:System.Windows.Forms.Timer.Interval%2A> property that specifies the number of milliseconds that pass between one timer event and the next. Unless the component is disabled, a timer continues to receive the <xref:System.Windows.Forms.Timer.Tick> event at roughly equal intervals of time.
|
||||
|
||||
This component is designed for a Windows Forms environment. If you need a timer that is suitable for a server environment, see [Introduction to Server-Based Timers](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2008/tb9yt5e6(v=vs.90)).
|
||||
This component is designed for a Windows Forms environment. If you need a timer that is suitable for a server environment, see [Introduction to Server-Based Timers](/previous-versions/visualstudio/visual-studio-2008/tb9yt5e6(v=vs.90)).
|
||||
|
||||
## The Interval Property
|
||||
|
||||
The <xref:System.Windows.Forms.Timer.Interval%2A> property has a few limitations to consider when you are programming a <xref:System.Windows.Forms.Timer> component:
|
||||
|
||||
- If your application or another application is making heavy demands on the system — such as long loops, intensive calculations, or drive, network, or port access — your application may not get timer events as often as the <xref:System.Windows.Forms.Timer.Interval%2A> property specifies.
|
||||
|
||||
@@ -7,9 +7,11 @@ helpviewer_keywords:
|
||||
ms.assetid: e361bf98-eed8-4ed3-9dfb-5a2e865e3ce6
|
||||
---
|
||||
# MenuStrip Control (Windows Forms)
|
||||
|
||||
This control groups application commands and makes them easily accessible.
|
||||
|
||||
## In This Section
|
||||
|
||||
[MenuStrip Control Overview](menustrip-control-overview-windows-forms.md)
|
||||
Explains what the control is and its key features and properties.
|
||||
|
||||
@@ -49,7 +51,7 @@ This control groups application commands and makes them easily accessible.
|
||||
[How to: Set Up Automatic Menu Merging for MDI Applications](how-to-set-up-automatic-menu-merging-for-mdi-applications.md)
|
||||
Describes how to merge menu items automatically at run time.
|
||||
|
||||
- [MenuStrip Items Collection Editor](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms233625(v=vs.100))
|
||||
- [MenuStrip Items Collection Editor](/previous-versions/visualstudio/visual-studio-2010/ms233625(v=vs.100))
|
||||
|
||||
- [How to: Copy ToolStripMenuItems](how-to-copy-toolstripmenuitems.md)
|
||||
|
||||
@@ -61,9 +63,10 @@ This control groups application commands and makes them easily accessible.
|
||||
|
||||
- [Walkthrough: Providing Standard Menu Items to a Form](walkthrough-providing-standard-menu-items-to-a-form.md)
|
||||
|
||||
- [MenuStrip Tasks Dialog Box](https://docs.microsoft.com/previous-versions/visualstudio/visual-studio-2010/ms233645(v=vs.100))
|
||||
- [MenuStrip Tasks Dialog Box](/previous-versions/visualstudio/visual-studio-2010/ms233645(v=vs.100))
|
||||
|
||||
## Reference
|
||||
|
||||
<xref:System.Windows.Forms.MenuStrip>
|
||||
Describes the features of the <xref:System.Windows.Forms.MenuStrip> class, which provides a menu system for a form.
|
||||
|
||||
@@ -74,5 +77,6 @@ This control groups application commands and makes them easily accessible.
|
||||
Describes the features of the <xref:System.Windows.Forms.ToolStripMenuItem> class, which represents a selectable option displayed on a <xref:System.Windows.Forms.MenuStrip> or <xref:System.Windows.Forms.ContextMenuStrip>.
|
||||
|
||||
## Related Sections
|
||||
|
||||
[Controls to Use on Windows Forms](controls-to-use-on-windows-forms.md)
|
||||
Provides a complete list of Windows Forms controls, with links to information on their use.
|
||||
|
||||
+3
-1
@@ -13,6 +13,7 @@ helpviewer_keywords:
|
||||
ms.assetid: 35d14fca-4bb4-4a27-8211-1f7a98ea27de
|
||||
---
|
||||
# Method Implementation in Custom Controls
|
||||
|
||||
A method is implemented in a control in the same manner a method would be implemented in any other component.
|
||||
|
||||
In Visual Basic, if a method is required to return a value, it is implemented as a `Public Function`. If no value is returned, it is implemented as a `Public Sub`. Methods are declared using the following syntax:
|
||||
@@ -39,6 +40,7 @@ public int ConvertMatterToEnergy(int matter)
|
||||
Typed arguments allow many developer errors to be caught by the compiler, rather than at run time. The compiler always catches errors, whereas run-time testing is only as good as the test suite.
|
||||
|
||||
## Overloaded Methods
|
||||
|
||||
If you want to allow users of your control to supply different combinations of parameters to a method, provide multiple overloads of the method, using explicit data types. Avoid creating parameters declared `As Object` that can contain any data type, as this can lead to errors that might not be caught in testing.
|
||||
|
||||
> [!NOTE]
|
||||
@@ -71,5 +73,5 @@ public void Spin(Widget driver)
|
||||
|
||||
## See also
|
||||
|
||||
- [Events](https://docs.microsoft.com/dotnet/standard/events/index)
|
||||
- [Events](/dotnet/standard/events/index)
|
||||
- [Properties in Windows Forms Controls](properties-in-windows-forms-controls.md)
|
||||
|
||||
+4
-1
@@ -11,18 +11,21 @@ helpviewer_keywords:
|
||||
ms.assetid: 146d97be-3d97-400e-accb-860bbf47729d
|
||||
---
|
||||
# How to: Move Through a DataSet with the Windows Forms BindingNavigator Control
|
||||
|
||||
As you build data-driven applications, you will often need to display collections of data to users. The <xref:System.Windows.Forms.BindingNavigator> control, in conjunction with the <xref:System.Windows.Forms.BindingSource> component, provides a convenient and extensible solution for moving through a collection and displaying items sequentially.
|
||||
|
||||
## Example
|
||||
|
||||
The following code example demonstrates how to use a <xref:System.Windows.Forms.BindingNavigator> control to move through data. The set is contained in a <xref:System.Data.DataView>, which is bound to a <xref:System.Windows.Forms.TextBox> control with a <xref:System.Windows.Forms.BindingSource> component.
|
||||
|
||||
> [!NOTE]
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](https://docs.microsoft.com/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
> Storing sensitive information, such as a password, within the connection string can affect the security of your application. Using Windows Authentication (also known as integrated security) is a more secure way to control access to a database. For more information, see [Protecting Connection Information](/dotnet/framework/data/adonet/protecting-connection-information).
|
||||
|
||||
[!code-csharp[System.Windows.Forms.DataNavigator#1](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.DataNavigator/CS/form1.cs#1)]
|
||||
[!code-vb[System.Windows.Forms.DataNavigator#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.DataNavigator/VB/form1.vb#1)]
|
||||
|
||||
## Compiling the Code
|
||||
|
||||
This example requires:
|
||||
|
||||
- References to the System, System.Data, System.Drawing, System.Windows.Forms and System.Xml assemblies.
|
||||
|
||||
@@ -10,6 +10,7 @@ helpviewer_keywords:
|
||||
ms.assetid: e9ca2723-0107-4540-bb21-4f5ffb4a9906
|
||||
---
|
||||
# Overriding the OnPaint Method
|
||||
|
||||
The basic steps for overriding any event defined in the .NET Framework are identical and are summarized in the following list.
|
||||
|
||||
#### To override an inherited event
|
||||
@@ -82,6 +83,6 @@ public class PaintEventArgs : EventArgs {
|
||||
|
||||
## See also
|
||||
|
||||
- [Events](https://docs.microsoft.com/dotnet/standard/events/index)
|
||||
- [Events](/dotnet/standard/events/index)
|
||||
- [Rendering a Windows Forms Control](rendering-a-windows-forms-control.md)
|
||||
- [Defining an Event](defining-an-event-in-windows-forms-controls.md)
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ Two of the main scenarios that involve the <xref:System.Drawing.Printing.PrintDo
|
||||
|
||||
- Simple print jobs, such as printing an individual text file. In such a case you would add the <xref:System.Drawing.Printing.PrintDocument> component to a Windows Form, then add programming logic that prints a file in the <xref:System.Drawing.Printing.PrintDocument.PrintPage> event handler. The programming logic should culminate with the <xref:System.Drawing.Printing.PrintDocument.Print%2A> method to print the document. This method sends a <xref:System.Drawing.Graphics> object, contained in the <xref:System.Drawing.Printing.PrintPageEventArgs.Graphics%2A> property of the <xref:System.Drawing.Printing.PrintPageEventArgs> class, to the printer. For an example that shows how to print a text document using the <xref:System.Drawing.Printing.PrintDocument> component, see [How to: Print a Multi-Page Text File in Windows Forms](../advanced/how-to-print-a-multi-page-text-file-in-windows-forms.md).
|
||||
|
||||
- More complex print jobs, such as a situation where you will want to reuse printing logic you have written. In such a case you would derive a new component from the <xref:System.Drawing.Printing.PrintDocument> component and override (see [Overrides](https://docs.microsoft.com/dotnet/visual-basic/language-reference/modifiers/overrides) for Visual Basic or [override](https://docs.microsoft.com/dotnet/csharp/language-reference/keywords/override) for C#) the <xref:System.Drawing.Printing.PrintDocument.PrintPage> event.
|
||||
- More complex print jobs, such as a situation where you will want to reuse printing logic you have written. In such a case you would derive a new component from the <xref:System.Drawing.Printing.PrintDocument> component and override (see [Overrides](/dotnet/visual-basic/language-reference/modifiers/overrides) for Visual Basic or [override](/dotnet/csharp/language-reference/keywords/override) for C#) the <xref:System.Drawing.Printing.PrintDocument.PrintPage> event.
|
||||
|
||||
When it is added to a form, the <xref:System.Drawing.Printing.PrintDocument> component appears in the tray at the bottom of the Windows Forms Designer in Visual Studio.
|
||||
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ For apps running on the .NET Framework 4.5.2, you can add the following key to t
|
||||
|
||||
If the `EnablePrintPreviewOptimization` key is set to any other value, or if the key is not present, the optimization is not applied.
|
||||
|
||||
For apps running on the .NET Framework 4.6 or later versions, you can add the following switch to the [\<AppContextSwitchOverrides>](https://docs.microsoft.com/dotnet/framework/configure-apps/file-schema/runtime/appcontextswitchoverrides-element) element in the [\<runtime>](https://docs.microsoft.com/dotnet/framework/configure-apps/file-schema/runtime/index) section of your app config file:
|
||||
For apps running on the .NET Framework 4.6 or later versions, you can add the following switch to the [\<AppContextSwitchOverrides>](/dotnet/framework/configure-apps/file-schema/runtime/appcontextswitchoverrides-element) element in the [\<runtime>](/dotnet/framework/configure-apps/file-schema/runtime/index) section of your app config file:
|
||||
|
||||
```xml
|
||||
<runtime >
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user