VirtualButton 2.0.0
Versions 2.0.0 & 2.1.0 are broken due to https://github.com/dotnet/winforms/issues/6663 -- 2.1.1 fixes these bugs.
See the version list below for details.
dotnet add package VirtualButton --version 2.0.0
NuGet\Install-Package VirtualButton -Version 2.0.0
<PackageReference Include="VirtualButton" Version="2.0.0" />
<PackageVersion Include="VirtualButton" Version="2.0.0" />
<PackageReference Include="VirtualButton" />
paket add VirtualButton --version 2.0.0
#r "nuget: VirtualButton, 2.0.0"
#:package VirtualButton@2.0.0
#addin nuget:?package=VirtualButton&version=2.0.0
#tool nuget:?package=VirtualButton&version=2.0.0
VirtualButton
This was made for .NET Core 6, but doesn't rely on anything specific to it - feel free to build it for .NET Framework or other .NET Core versions as needed.
Getting Started
Installation
A) Nuget
- If you're using Visual Studio, right-click on your project or solution & select Manage Nuget Packages.

- Switch to the Browse tab & search for
VirtualButton, then click the install icon.
B) From Source
- Clone the repository to a location of your choice (for best results, use a git submodule), and add it to your solution.
- Add a project reference in the project you want to use the virtual button in:

Usage
This assumes you already have a form or control, and know how to create them.
In order for the virtual button's Click events to fire correctly, you must assign (or reassign) Form.(...)Button programmatically outside of the designer at least once.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CancelButton = virtualButton1; //< this has to happen before Click events can fire. (thank microsoft)
}
}
For more detail on implementations, see below.
Designer Usage
- If the installation was successful, you will have a
VirtualButtonitem in the designer toolbox:

- Select the
VirtualButtonitem, then click somewhere on your form/control. You will now have a new component:

Handling Virtual Click Events
- Define a handler for the click event by double-clicking in the
Clickdropdown, or by selecting an already-existing function.

Setting Built-In Form Buttons
- Now that you have a
VirtualButtonadded to the form/control, you can select it from theFormCancelButton/AcceptButton/HelpButtondropdown boxes:

Programmatic Usage
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Initialize the virtual button:
vbCancelButton = new(delegate{ this.Close() });
// Assign the virtual button as the form button handler:
this.CancelButton = vbCancelButton;
}
private readonly VirtualButton vbCancelButton;
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. net9.0-windows was computed. net10.0-windows was computed. |
-
net6.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.