VirtualButton 2.1.1

dotnet add package VirtualButton --version 2.1.1                
NuGet\Install-Package VirtualButton -Version 2.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VirtualButton" Version="2.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VirtualButton --version 2.1.1                
#r "nuget: VirtualButton, 2.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install VirtualButton as a Cake Addin
#addin nuget:?package=VirtualButton&version=2.1.1

// Install VirtualButton as a Cake Tool
#tool nuget:?package=VirtualButton&version=2.1.1                

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
  1. If you're using Visual Studio, right-click on your project or solution & select Manage Nuget Packages. image
  2. Switch to the Browse tab & search for VirtualButton, then click the install icon. image
B) From Source
  1. Clone the repository to a location of your choice (for best results, use a git submodule), and add it to your solution.
  2. Add a project reference in the project you want to use the virtual button in:
    Adding a Project Reference

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
  1. If the installation was successful, you will have a VirtualButton item in the designer toolbox:
    (as of v2.0.0+ this is now VirtualButton.VButton, which appears as VButton)
    image
  2. Select the VirtualButton item, then click somewhere on your form/control. You will now have a new component:
    image
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.
    image
Setting Built-In Form Buttons
  • Now that you have a VirtualButton added to the form/control, you can select it from the Form CancelButton/AcceptButton/HelpButton dropdown boxes:
    image
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 Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.