Skip to content

(.NET Core 6) A Windows Forms Component that implements the IButtonControl interface to emulate a Button Control.

License

Notifications You must be signed in to change notification settings

radj307/VirtualButton

Repository files navigation


Virtual Button
▼ NuGet ▼                      ▼ Github ▼
Nuget     GitHub tag (latest by date)


Lightweight WinForms component that makes implementing handlers for the built-in form buttons a breeze!
Of course, you can use it for whatever you want to - it is compatible with anything that accepts IButtonControl interfaces.

Installation

Visual Studio

  1. Right-Click on a .csproj or .sln file in the solution explorer, then click the Manage NuGet Packages... button.

  2. Switch to the Browse tab and search for 'Virtual Button'

  3. Click on the Install button next to the package description:

    The code is open-sourced under the GPLv3 license.

Usage

You can add virtual buttons using the designer, or entirely programmatically.
VButton appears at the bottom alongside other components, such as NotifyIcon, Timer, BindingSource, etc.

Designer

  1. Once you have the NuGet package installed, open the designer toolbox (You may have to recompile the project for it to appear.) and add the VButton component somewhere.
  2. In the properties window, create a handler for the Click event, and put whatever code you want to execute when the associated key is pressed in the handler.
  3. Re-assign the button property at least once before attempting to use it.
    Common places to do this are the form's constructor or Form.Load event, for example:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
		
        // Even though we set this in the designer, we have
        //  to set it again manually for it to work correctly:
        this.CancelButton = vButton1;
    }
}

Programmatic

You can create VButtons with ad-hoc delegates:

this.CancelButton = new VButton(delegate{
    // Do something
});

Or with any event handler compatible with HandledEventHandler:

private void HandlerOfHandledEvents(object sender, HandledEventArgs e)
{
    // ...
}

private void Form1_Load(object sender, EventArgs e)
{
    vButton1.Click += HandlerOfHandledEvents!;
}

About

(.NET Core 6) A Windows Forms Component that implements the IButtonControl interface to emulate a Button Control.

Topics

Resources

License

Stars

Watchers

Forks