From b8531632cc304856c63f05d8fbf0b16c89744d5e Mon Sep 17 00:00:00 2001 From: "Andy De George (adegeo)" Date: Tue, 30 Apr 2024 12:32:22 -0700 Subject: [PATCH] Add step --- .../net/winforms/controls-design/extend-existing.md | 9 +++++++-- .../extend-existing/csharp/CustomControlProject.csproj | 2 +- .../extend-existing/vb/CustomControlProjectVB.vbproj | 6 +----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dotnet-desktop-guide/net/winforms/controls-design/extend-existing.md b/dotnet-desktop-guide/net/winforms/controls-design/extend-existing.md index 1b72e019b9..cb5813511a 100644 --- a/dotnet-desktop-guide/net/winforms/controls-design/extend-existing.md +++ b/dotnet-desktop-guide/net/winforms/controls-design/extend-existing.md @@ -1,7 +1,7 @@ --- title: Customize an existing control description: Learn how to inherit from existing controls so that another control has all of its functionality and visual properties. -ms.date: 06/01/2023 +ms.date: 04/30/2024 dev_langs: - "csharp" - "vb" @@ -9,6 +9,7 @@ helpviewer_keywords: - "inheritance [Windows Forms], Windows Forms custom controls" - "custom controls [Windows Forms], inheritance" --- + # Extend an existing control If you want to add more features to an existing control, you can create a control that inherits from an existing control. The new control contains all of the capabilities and visual aspect of the base control, but gives you opportunity to extend it. For example, if you created a control that inherits , your new control would look and act exactly like a button. You could create new methods and properties to customize the behavior of the control. Some controls allow you to override the method to change the way the control looks. @@ -41,7 +42,11 @@ After [you add a custom control to your project](#add-a-custom-control-to-a-proj :::code language="csharp" source="./snippets/extend-existing/csharp/CustomControl2.cs" id="control"::: :::code language="vb" source="./snippets/extend-existing/vb/CustomControl2.vb" id="control"::: -01. First, add a class-scoped variable named `_counter`. +01. Change the base class from `Control` to `Button`. + + If you're using Visual Basic, you need to open the _\*.designer.vb_ file of your control and set the base class to `System.Windows.Forms.Button`. + +01. Add a class-scoped variable named `_counter`. :::code language="csharp" source="./snippets/extend-existing/csharp/CustomControl1.cs" id="counter"::: :::code language="vb" source="./snippets/extend-existing/vb/CustomControl1.vb" id="counter"::: diff --git a/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/csharp/CustomControlProject.csproj b/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/csharp/CustomControlProject.csproj index e1a0735019..663fdb88b6 100644 --- a/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/csharp/CustomControlProject.csproj +++ b/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/csharp/CustomControlProject.csproj @@ -2,7 +2,7 @@ WinExe - net7.0-windows + net8.0-windows enable true enable diff --git a/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/vb/CustomControlProjectVB.vbproj b/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/vb/CustomControlProjectVB.vbproj index 26b38e2551..a3579038b2 100644 --- a/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/vb/CustomControlProjectVB.vbproj +++ b/dotnet-desktop-guide/net/winforms/controls-design/snippets/extend-existing/vb/CustomControlProjectVB.vbproj @@ -2,7 +2,7 @@ WinExe - net7.0-windows + net8.0-windows Sub Main true WindowsForms @@ -15,10 +15,6 @@ - - - - True