Class:
Spoiler:
- Code: Select all
using System;
using System.Windows.Forms;
// \\
// Classes by: joppiesaus \\
// \\
// This was made for easier plugin coding in MCDzienny. All classes are V 1.0;
namespace EventHandlerExtension
{
public class ClickEvent
{
/// <summary>
/// This will return true when the control is clicked. Check this, and if true ALWAYS set it back to false.
/// </summary>
public bool buttonClicked { get; set; }
Button button;
event EventHandler clickedHandler;
/// <summary>
/// New event for clicked button.
/// </summary>
/// <param name="Button">Button</param>
public ClickEvent(Button Button)
{
Button = button;
initialize();
}
private void initialize()
{
button.Click += this.handleClick;
}
private void handleClick(object sender, EventArgs e)
{
this.clicked(EventArgs.Empty);
}
protected virtual void clicked(EventArgs e)
{
EventHandler hand = this.clickedHandler;
if (hand != null)
{
hand(this, e);
}
buttonClicked = true;
}
}
public class TextChangedEvent
{
/// <summary>
/// This will return true when the control text is changed. Check this, and if true ALWAYS set it back to false.
/// </summary>
public bool textChanged { get; set; }
TextBox textbox;
event EventHandler textChangedHandler;
/// <summary>
/// New event for textchanged textbox.
/// </summary>
/// <param name="TextBox">TextBox</param>
public TextChangedEvent(TextBox TextBox)
{
textbox = TextBox;
initialize();
}
private void initialize()
{
textbox.TextChanged += this.handleTextChanged;
}
private void handleTextChanged(object sender, EventArgs e)
{
this.Changed(EventArgs.Empty);
}
protected virtual void Changed(EventArgs e)
{
EventHandler hand = this.textChangedHandler;
if (hand != null)
{
hand(this, e);
}
textChanged = true;
}
}
public class CheckedChangedEvent
{
/// <summary>
/// This will return true when the control checked is changed. Check this, and if true ALWAYS set it back to false.
/// </summary>
public bool checkedChanged { get; set; }
CheckBox checkbox;
event EventHandler checkedChangedHandler;
/// <summary>
/// New event for Checkbox CheckedChanged
/// </summary>
/// <param name="CheckBox">CheckBox</param>
public CheckedChangedEvent(CheckBox CheckBox)
{
checkbox = CheckBox;
initialize();
}
private void initialize()
{
checkbox.CheckedChanged += this.handleCheckedChanged;
}
private void handleCheckedChanged(object sender, EventArgs e)
{
this.Changed(EventArgs.Empty);
}
protected virtual void Changed(EventArgs e)
{
EventHandler hand = this.checkedChangedHandler;
if (hand != null)
{
hand(this, e);
}
checkedChanged = true;
}
}
}
Example:
Spoiler:
- Code: Select all
using System;
using System.Windows.Forms;
namespace example
{
class exampleClass
{
static Button button = new Button();
EventHandlerExtension.ClickEvent click;
//dummy bool
bool clicked = false;
public exampleClass()
{
//define a new ClickEvent for the button
click = new EventHandlerExtension.ClickEvent(button);
//infinite loop
while (1 == 1)
{
//is the button clickced?
if (click.buttonClicked)
{
clicked = true;
click.buttonClicked = false;
}
}
}
}
}
I hope this will help people . This will cover the most basic things, the rest you have to code yourself.
Let me know if you have comments on this.