diff --git a/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md b/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md index 6f2549d..c85725b 100644 --- a/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md +++ b/dotnet-desktop-guide/framework/winforms/controls/defining-default-values-with-the-shouldserialize-and-reset-methods.md @@ -1,5 +1,6 @@ --- title: "Defining Default Values with the ShouldSerialize and Reset Methods" +description: "Learn how to use the ShouldSerialize and Reset property methods to control the Windows Forms designer behavior." ms.date: "03/30/2017" dev_langs: - "csharp" @@ -10,7 +11,7 @@ helpviewer_keywords: ms.assetid: 7b6c5e00-3771-46b4-9142-5a80d5864a5e --- # Defining Default Values with the ShouldSerialize and Reset Methods -`ShouldSerialize` and `Reset` are optional methods that you can provide for a property, if the property does not a have simple default value. If the property has a simple default value, you should apply the and supply the default value to the attribute class constructor instead. Either of these mechanisms enables the following features in the designer: +`ShouldSerialize` and `Reset` are optional methods that you can provide for a property, if the property does not have a simple default value. If the property has a simple default value, you should apply the and supply the default value to the attribute class constructor instead. Either of these mechanisms enables the following features in the designer: - The property provides visual indication in the property browser if it has been modified from its default value. @@ -60,6 +61,9 @@ private bool ShouldSerializeMyFont() } ``` +> [!TIP] +> If you want to permanently prevent a property from being serialized by the designer, add the [DesignerSerializationVisibility](xref:System.ComponentModel.DesignerSerializationVisibilityAttribute) attribute with the value of `Hidden`. + A complete code example follows. ```vb @@ -147,3 +151,4 @@ public class MyControl : Control { - [Properties in Windows Forms Controls](properties-in-windows-forms-controls.md) - [Defining a Property](defining-a-property-in-windows-forms-controls.md) - [Property-Changed Events](property-changed-events.md) +- diff --git a/dotnet-desktop-guide/framework/winforms/how-to-create-event-handlers-at-run-time-for-windows-forms.md b/dotnet-desktop-guide/framework/winforms/how-to-create-event-handlers-at-run-time-for-windows-forms.md index c101101..47ccc73 100644 --- a/dotnet-desktop-guide/framework/winforms/how-to-create-event-handlers-at-run-time-for-windows-forms.md +++ b/dotnet-desktop-guide/framework/winforms/how-to-create-event-handlers-at-run-time-for-windows-forms.md @@ -66,8 +66,6 @@ In addition to creating events using the Windows Forms Designer in Visual Studio button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); ``` - The method demonstrated in the Visual Basic code above establishes a click event handler for the button. - ## See also - [Creating Event Handlers in Windows Forms](creating-event-handlers-in-windows-forms.md) diff --git a/dotnet-desktop-guide/framework/winforms/index.yml b/dotnet-desktop-guide/framework/winforms/index.yml index 06c1684..a22ee54 100644 --- a/dotnet-desktop-guide/framework/winforms/index.yml +++ b/dotnet-desktop-guide/framework/winforms/index.yml @@ -1,11 +1,11 @@ ### YamlMime:Landing title: .NET Desktop Guide for Windows Forms -summary: Learn about using Windows Forms on Windows with either .NET Framework, .NET 5 and above, or .NET Core 3.1. +summary: Learn about Windows Forms (WinForms), a graphical user interface for Windows and .NET Framework. metadata: title: Windows Forms for .NET documentation - description: Learn about using Windows Forms (WinForms), a graphical user interface for Windows and .NET. + description: Learn about Windows Forms (WinForms), a graphical user interface for Windows and .NET Framework. ms.topic: landing-page ms.date: 08/30/2020 @@ -27,7 +27,7 @@ landingContent: url: /visualstudio/designers/walkthrough-windows-forms-designer - text: Create a WinForms app from the command-line url: how-to-create-a-windows-forms-application-from-the-command-line.md - + - title: Controls linkLists: - linkListType: overview @@ -59,4 +59,28 @@ landingContent: links: - text: Order in which events are raised url: order-of-events-in-windows-forms.md - \ No newline at end of file + + - title: Input + linkLists: + - linkListType: overview + links: + - text: About keyboard input + url: how-keyboard-input-works.md + - text: About mouse input + url: how-mouse-input-works-in-windows-forms.md + - linkListType: concept + links: + - text: Keyboard events + url: using-keyboard-events.md + - text: Mouse events + url: mouse-events-in-windows-forms.md + - text: Mouse pointers + url: mouse-pointers-in-windows-forms.md + - linkListType: how-to-guide + links: + - text: Modify keyboard input + url: how-to-modify-keyboard-input-to-a-standard-control.md + - text: Detect modifier keyboard keys + url: how-to-determine-which-modifier-key-was-pressed.md + - text: Distinguish between single/double clicks + url: how-to-distinguish-between-clicks-and-double-clicks.md diff --git a/dotnet-desktop-guide/framework/wpf/advanced/how-to-use-special-characters-in-xaml.md b/dotnet-desktop-guide/framework/wpf/advanced/how-to-use-special-characters-in-xaml.md index 4d605f8..0b743a2 100644 --- a/dotnet-desktop-guide/framework/wpf/advanced/how-to-use-special-characters-in-xaml.md +++ b/dotnet-desktop-guide/framework/wpf/advanced/how-to-use-special-characters-in-xaml.md @@ -11,21 +11,23 @@ helpviewer_keywords: ms.assetid: a57776d1-f353-4794-afa0-bfa3c712ed1c --- # How to: Use Special Characters in XAML -Markup files that are created in Visual Studio are automatically saved in the Unicode UTF-8 file format, which means that most special characters, such as accent marks, are encoded correctly. However, there is a set of commonly-used special characters that are handled differently. These special characters follow the World Wide Web Consortium (W3C) XML standard for encoding. - - The following table shows the syntax for encoding this set of special characters: - -|Character|Syntax|Description| -|---------------|------------|-----------------| -|<|`<`|Less than symbol.| -|>|`>`|Greater than sign.| -|&|`&`|Ampersand symbol.| -|"|`"`|Double quote symbol.| - +Markup files that are created in Visual Studio are automatically saved in the Unicode UTF-8 file format, which means that most special characters, such as accent marks, are encoded correctly. However, there is a set of commonly-used special characters that are handled differently. These special characters follow the World [Wide Web Consortium (W3C) XML standard for encoding](https://www.w3resource.com/xml/reserved-markup-characters.php). + +The following table shows the syntax for encoding this set of special characters: + +| Character | Syntax | Description | +|-----------|----------|----------------------| +| `<` | `<` | Less than symbol. | +| `>` | `>` | Greater than sign. | +| `&` | `&` | Ampersand symbol. | +| `"` | `"` | Double quote symbol. | +| `'` | `'` | Single quote symbol. | + > [!NOTE] -> If you create a markup file using a text editor, such as Windows Notepad, you must save the file in the Unicode UTF-8 file format in order to preserve any encoded special characters. - - The following example shows how you can use special characters in text when creating markup. - -## Example - [!code-xaml[SpecialCharsSnippets#SpecialCharsSnippet1](~/samples/snippets/csharp/VS_Snippets_Wpf/SpecialCharsSnippets/CS/Window1.xaml#specialcharssnippet1)] +> If you create a markup file using a text editor, such as Windows Notepad, you must save the file in the Unicode UTF-8 file format in order to preserve any encoded special characters. + +The following example shows how you can use special characters in text when creating markup. + +## Example + +[!code-xaml[SpecialCharsSnippets#SpecialCharsSnippet1](~/samples/snippets/csharp/VS_Snippets_Wpf/SpecialCharsSnippets/CS/Window1.xaml#specialcharssnippet1)] diff --git a/dotnet-desktop-guide/framework/wpf/graphics-multimedia/storyboards-overview.md b/dotnet-desktop-guide/framework/wpf/graphics-multimedia/storyboards-overview.md index c92da92..3a98424 100644 --- a/dotnet-desktop-guide/framework/wpf/graphics-multimedia/storyboards-overview.md +++ b/dotnet-desktop-guide/framework/wpf/graphics-multimedia/storyboards-overview.md @@ -1,6 +1,6 @@ --- title: "Storyboards Overview" -desription: Organize and apply animations in storyboards. Use property-targeting syntax and combine timelines in Windows Presentation Foundation (WPF). +description: Organize and apply animations in storyboards. Use property-targeting syntax and combine timelines in Windows Presentation Foundation (WPF). ms.date: "03/30/2017" dev_langs: - "csharp" @@ -65,7 +65,9 @@ The following table shows the different places where each and an |Yes|Yes|Yes|Yes|[Animate a Property by Using a Storyboard](how-to-animate-a-property-by-using-a-storyboard.md)| | and a property |No|Yes|Yes|Yes|[Trigger an Animation When a Property Value Changes](how-to-trigger-an-animation-when-a-property-value-changes.md)| +| and a property |No|Yes|Yes|Yes|[MultiTrigger class example](/dotnet/api/system.windows.multitrigger#examples)| | and a |No|Yes|Yes|Yes|[How to: Trigger an Animation When Data Changes](/previous-versions/dotnet/netframework-3.5/aa970679(v=vs.90))| +| and a |No|Yes|Yes|Yes|[MultiDataTrigger class example](/dotnet/api/system.windows.multidatatrigger#examples)| | method|Yes|No|No|No|[Animate a Property by Using a Storyboard](how-to-animate-a-property-by-using-a-storyboard.md)| The following example uses a to animate the of a element and the of a used to paint that . @@ -80,7 +82,10 @@ The following sections describe the with the name of the property to animate. You specify the name of the object whose property you want to animate by setting the property on the animation. +The previous section mentioned that, for an animation to find its target, it must know the target's name and the property to animate. Specifying the property to animate is straight forward: simply set `TargetProperty` with the name of the property to animate. You specify the name of the object whose property you want to animate by setting the property on the animation. + +> [!CAUTION] +> While you can use the `Target` property to bind directly to an object as an alternative to `TargetName`, it isn't serializable. There is no guaranteed that the `Target` object can be correctly referenced in XAML. For the property to work, the targeted object must have a name. Assigning a name to a or a in [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] is different than assigning a name to a object. diff --git a/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md b/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md index 30ba752..8bad6bf 100644 --- a/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md +++ b/dotnet-desktop-guide/net/winforms/get-started/create-app-visual-studio.md @@ -88,22 +88,26 @@ With the _Form1_ form designer open, use the **Toolbox** pane to add the followi You can position and size the controls according to the following settings. Either visually move them to match the screenshot that follows, or click on each control and configure the settings in the **Properties** pane. You can also click on the form title area to select the form: -| Object | Setting | Value | -|---------|----------|------------| -| Form | Text | `Names` | -| | Size | `268, 180` | -| Label | Location | `12, 9` | -| | Text | `Names` | -| Listbox | Name | `lstNames` | -| | Location | `12, 27` | -| | Size | `120, 94` | -| Textbox | Name | `txtName` | -| | Location | `138, 26` | -| | Size | `100, 23` | -| Button | Name | `btnAdd` | -| | Location | `138, 55` | -| | Size | `100, 23` | -| | Text | `Add Name` | +| Object | Setting | Value | +|-------------|----------|------------| +| **Form** | Text | `Names` | +| | Size | `268, 180` | +| | | | +| **Label** | Location | `12, 9` | +| | Text | `Names` | +| | | | +| **Listbox** | Name | `lstNames` | +| | Location | `12, 27` | +| | Size | `120, 94` | +| | | | +| **Textbox** | Name | `txtName` | +| | Location | `138, 26` | +| | Size | `100, 23` | +| | | | +| **Button** | Name | `btnAdd` | +| | Location | `138, 55` | +| | Size | `100, 23` | +| | Text | `Add Name` | You should have a form in the designer that looks similar to the following: diff --git a/dotnet-desktop-guide/net/winforms/migration/index.md b/dotnet-desktop-guide/net/winforms/migration/index.md index 9028218..a6b5b71 100644 --- a/dotnet-desktop-guide/net/winforms/migration/index.md +++ b/dotnet-desktop-guide/net/winforms/migration/index.md @@ -49,16 +49,16 @@ When migrating a .NET Framework Windows Forms application, there are a few thing ## Back up your projects -The first step to migrating a project is to back up your project! If something goes wrong, you can restore your code to its original state by restoring your backup. Don't rely on tools such as the .NET Portability Analyzer to back up your project, even if they seem to. It's better to have a copy of the original project safely stored in the cloud or elsewhere on your computer. +The first step to migrating a project is to back up your project! If something goes wrong, you can restore your code to its original state by restoring your backup. Don't rely on tools such as the .NET Portability Analyzer to back up your project, even if they seem to. It's best to personally create a copy of the original project. ## NuGet packages If your project is referencing NuGet packages, you probably have a **packages.config** file in your project folder. With SDK-style projects, NuGet package references are configured in the project file. Visual Studio project files can optionally define NuGet packages in the project file too. .NET 5 doesn't use **packages.config** for NuGet packages. NuGet package references must be migrated into the project file before migration. -To migrate the **packages.config** file, do the following: +To migrate the **packages.config** file, do the following steps: 01. In **Solution explorer**, find the project you're migrating. -02. Right-click on **packages.config** > **Migrate packages.config to ProjectReference**. +02. Right-click on **packages.config** > **Migrate packages.config to PackageReference**. 03. Select all of the top-level packages. A build report is generated to let you know of any issues migrating the NuGet packages. @@ -67,13 +67,15 @@ A build report is generated to let you know of any issues migrating the NuGet pa The next step in migrating your app is converting the project file. As previously stated, .NET 5 uses SDK-style project files and won't load the Visual Studio project files that .NET Framework uses. However, there's the possibility that you're already using SDK-style projects. You can easily spot the difference in Visual Studio. Right-click on the project file in **Solution explorer** and look for the **Edit Project File** menu option. If this menu item is missing, you're using the old Visual Studio project format and need to upgrade. -To upgrade, do the following: +Convert each project in your solution. If you're using the sample app previously referenced, both the **MatchingGame** and **MatchingGame.Logic** projects would be converted. + +To convert a project, do the following steps: 01. In **Solution explorer**, find the project you're migrating. 01. Right-click on the project and select **Unload Project**. 01. Right-click on the project and select **Edit Project File**. 01. Copy-and-paste the project XML into a text editor. You'll want a copy so that it's easy to move content into the new project. -01. Erase the content of the file and paste in the following content: +01. Erase the content of the file and paste the following XML: ```xml @@ -91,14 +93,14 @@ To upgrade, do the following: > [!IMPORTANT] > Libraries don't need to define an `` setting. Remove that entry if you're upgrading a library project. -This XML gives you the basic structure of the project. However, it doesn't contain any of the settings from the old project file. Using the old project information you previously copied to a text editor, do the following: +This XML gives you the basic structure of the project. However, it doesn't contain any of the settings from the old project file. Using the old project information you previously copied to a text editor, do the following steps: 01. Copy the following elements from the old project file into the `` element in the new project file: - `` - `` - Your project file should look similar to the following: + Your project file should look similar to the following XML: ```xml @@ -118,7 +120,7 @@ This XML gives you the basic structure of the project. However, it doesn't conta 01. Copy the `` elements from the old project file that contain `` or `` into the new file after the `` closing tag. - Your project file should look similar to the following: + Your project file should look similar to the following XML: ```xml @@ -142,7 +144,7 @@ This XML gives you the basic structure of the project. However, it doesn't conta ``` - The `` elements don't need the `` and `` children, so you can remove those: + The `` elements don't need the `` and `` children, so you can remove those settings: ```xml @@ -156,7 +158,7 @@ Windows Forms projects for .NET Framework typically include other files such as Copy those entries from the old project file into an `` element in the new project. After you copy the entries, change any `` or `` elements to instead use `Update` instead of `Include`. -- Import the configuration for the *Settings.settings* file. Note that `Include` was changed to `Update` on the `` element: +- Import the configuration for the *Settings.settings* file. Notice that the `Include` was changed to `Update` on the `` element: ```xml @@ -172,7 +174,10 @@ Copy those entries from the old project file into an `` element in th ``` -- Import the configuration for any *resx* file, such as the *properties/Resources.resx* file. Note that `Include` was changed to `Update` on both the `` and `` elements, and `` was removed from ``: + > [!IMPORTANT] + > **Visual Basic** projects typically use the folder *My Project* while C# projects typically use the folder *Properties* for the default project settings file. + +- Import the configuration for any *resx* file, such as the *properties/Resources.resx* file. Notice that the `Include` was changed to `Update` on both the `` and `` elements, and `` was removed from ``: ```xml @@ -188,11 +193,97 @@ Copy those entries from the old project file into an `` element in th ``` -Convert each project in your solution. If you're using the sample app previously referenced, the **MatchingGame.Logic** project would be converted. + > [!IMPORTANT] + > **Visual Basic** projects typically use the folder *My Project* while C# projects typically use the folder *Properties* for the default project resource file. + +### Visual Basic + +Visual Basic language projects require extra configuration. + +01. Import the configuration file *My Project\Application.myapp* setting. Notice that the `` and `` elements use the `Update` attribute instead of the `Include` attribute. + + ```xml + + + MyApplicationCodeGenerator + Application.Designer.vb + + + True + Application.myapp + True + + + ``` + +01. Add the `WindowsForms` setting to the `` element: + + ```xml + + (contains settings previously described) + + WindowsForms + + ``` + + This setting imports the `My` namespace members Visual Basic programmers are familiar with. + +01. Import the namespaces defined by your project. + + Visual Basic projects can automatically import namespaces into every code file. Copy the `` elements from the old project file that contain `` into the new file after the `` closing tag. + + ```xml + + + + + + + + + + + + + + ``` + + If you can't find any `` statements, or your project fails to compile, make sure you at least have the following `` statements defined in your project: + + ```xml + + + + + + ``` + +01. From the original project, copy the `` and `` settings to the `` element: + + ```xml + + (contains settings previously described) + + On + Binary + Off + On + MatchingGame.My.MyApplication + + ``` + +### Reload the project + +After you convert a project to the new SDK-style format, reload the project in Visual Studio: + +01. In **Solution Explorer**, find the project you converted. +01. Right-click on the project and select **Reload Project**. + + If the project fails to load, you may have introduced a mistake in the XML of the project. Open the project file for editing and try to identify and fix the mistake. If you can't find a mistake, try starting over. ## Edit App.config -If your app has an *App.config* file, remove the `` element. +If your app has an *App.config* file, remove the `` element: ```xml @@ -202,16 +293,18 @@ There are some things you should consider with the *App.config* file. The *App.c ## Add the compatibility package -If compilation fails and you receive errors similar to the following: +If your project file is loading correctly, but compilation fails for your project and you receive errors similar to the following: - **The type or namespace \ could not be found** - **The name \ does not exist in the current context** -You may need to add the [**Microsoft.Windows.Compatibility**](https://www.nuget.org/packages/Microsoft.Windows.Compatibility/) package to your app. This package adds ~21,000 .NET APIs from .NET Framework, such as the `System.Configuration.ConfigurationManager` class and APIs for interacting with the Windows Registry. +You may need to add the [`Microsoft.Windows.Compatibility`](https://www.nuget.org/packages/Microsoft.Windows.Compatibility/) package to your app. This package adds ~21,000 .NET APIs from .NET Framework, such as the `System.Configuration.ConfigurationManager` class and APIs for interacting with the Windows Registry. Add the `Microsoft.Windows.Compatibility` package. + +Edit your project file and add the following `` element: ```xml - + ``` diff --git a/dotnet-desktop-guide/samples/snippets/cpp/VS_Snippets_Wpf/ScrollViewer/CPP/ScrollViewer_wcp.cpp b/dotnet-desktop-guide/samples/snippets/cpp/VS_Snippets_Wpf/ScrollViewer/CPP/ScrollViewer_wcp.cpp index 8739a01..bf507aa 100644 --- a/dotnet-desktop-guide/samples/snippets/cpp/VS_Snippets_Wpf/ScrollViewer/CPP/ScrollViewer_wcp.cpp +++ b/dotnet-desktop-guide/samples/snippets/cpp/VS_Snippets_Wpf/ScrollViewer/CPP/ScrollViewer_wcp.cpp @@ -55,10 +55,10 @@ namespace SDKSample { myStackPanel->Children->Add(myTextBlock); myStackPanel->Children->Add(myRectangle); - // Add the StackPanel as the lone Child of the Border + // Add the StackPanel as the lone child of the ScrollViewer myScrollViewer->Content = myStackPanel; - // Add the Border as the Content of the Parent Window Object + // Add the ScrollViewer as the Content of the parent Window object mainWindow->Content = myScrollViewer; mainWindow->Show(); diff --git a/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ControlTemplateExamples/CS/resources/expander.xaml b/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ControlTemplateExamples/CS/resources/expander.xaml index e540e9e..28b059e 100644 --- a/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ControlTemplateExamples/CS/resources/expander.xaml +++ b/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ControlTemplateExamples/CS/resources/expander.xaml @@ -220,7 +220,7 @@ Value="True"> + Value="{Binding Height, ElementName=Content}" /> diff --git a/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ScrollViewer/CSharp/ScrollViewer_wcp.cs b/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ScrollViewer/CSharp/ScrollViewer_wcp.cs index 37a224c..e070a26 100644 --- a/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ScrollViewer/CSharp/ScrollViewer_wcp.cs +++ b/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/ScrollViewer/CSharp/ScrollViewer_wcp.cs @@ -49,10 +49,10 @@ namespace SDKSample myStackPanel.Children.Add(myTextBlock); myStackPanel.Children.Add(myRectangle); - // Add the StackPanel as the lone Child of the Border + // Add the StackPanel as the lone child of the ScrollViewer myScrollViewer.Content = myStackPanel; - // Add the Border as the Content of the Parent Window Object + // Add the ScrollViewer as the Content of the parent Window object mainWindow.Content = myScrollViewer; mainWindow.Show (); diff --git a/dotnet-desktop-guide/samples/snippets/visualbasic/VS_Snippets_Wpf/ScrollViewer/VisualBasic/ScrollViewer.vb b/dotnet-desktop-guide/samples/snippets/visualbasic/VS_Snippets_Wpf/ScrollViewer/VisualBasic/ScrollViewer.vb index c68aa21..cba8b7e 100644 --- a/dotnet-desktop-guide/samples/snippets/visualbasic/VS_Snippets_Wpf/ScrollViewer/VisualBasic/ScrollViewer.vb +++ b/dotnet-desktop-guide/samples/snippets/visualbasic/VS_Snippets_Wpf/ScrollViewer/VisualBasic/ScrollViewer.vb @@ -38,8 +38,10 @@ Namespace SDKSample myStackPanel.Children.Add(myTextBlock) myStackPanel.Children.Add(myRectangle) - 'Add the StackPanel as the lone Child of the Border + 'Add the StackPanel as the lone child of the ScrollViewer myScrollViewer.Content = myStackPanel + + 'Add the ScrollViewer as the Content of the parent Window object Me.Content = myScrollViewer ' End Sub