VirtualButton 2.1.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.1.0
NuGet\Install-Package VirtualButton -Version 2.1.0
<PackageReference Include="VirtualButton" Version="2.1.0" />
paket add VirtualButton --version 2.1.0
#r "nuget: VirtualButton, 2.1.0"
// Install VirtualButton as a Cake Addin #addin nuget:?package=VirtualButton&version=2.1.0 // Install VirtualButton as a Cake Tool #tool nuget:?package=VirtualButton&version=2.1.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
VirtualButton
item in the designer toolbox:
- Select the
VirtualButton
item, 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
Click
dropdown, or by selecting an already-existing function.
Setting Built-In Form Buttons
- Now that you have a
VirtualButton
added to the form/control, you can select it from theForm
CancelButton
/AcceptButton
/HelpButton
dropdown 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. |
-
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.