https://github.com/radj307/virtualbutton
(.NET Core 6) A Windows Forms Component that implements the IButtonControl interface to emulate a Button Control.
https://github.com/radj307/virtualbutton
csharp dotnet dotnet-core-6 net netcore netcore6 winforms winforms-components winforms-controls
Last synced: 3 months ago
JSON representation
(.NET Core 6) A Windows Forms Component that implements the IButtonControl interface to emulate a Button Control.
- Host: GitHub
- URL: https://github.com/radj307/virtualbutton
- Owner: radj307
- License: mit
- Created: 2022-04-24T14:00:36.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-23T23:10:04.000Z (about 3 years ago)
- Last Synced: 2025-02-28T19:03:59.163Z (4 months ago)
- Topics: csharp, dotnet, dotnet-core-6, net, netcore, netcore6, winforms, winforms-components, winforms-controls
- Language: C#
- Homepage:
- Size: 83 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
***
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 acceptsIButtonControl
interfaces.# Installation
*Visual Studio*
1. Right-Click on a `.csproj` or `.sln` file in the solution explorer, then click the  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](https://github.com/radj307/VirtualButton/blob/main/LICENSE) 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:
```cs
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:
```cs
this.CancelButton = new VButton(delegate{
// Do something
});
```Or with any event handler compatible with `HandledEventHandler`:
```cs
private void HandlerOfHandledEvents(object sender, HandledEventArgs e)
{
// ...
}private void Form1_Load(object sender, EventArgs e)
{
vButton1.Click += HandlerOfHandledEvents!;
}
```