NumericUpDown

  • Thread starter Thread starter Guest
  • Start date Start date
Hi Dave,

I don't think there is an event that tells you when a button is pressed, but you can easily add events if you want. I wrote this
code using the 2.0 framework and it seems to work just fine:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

public class NumericUpDownEx : NumericUpDown
{
public override void UpButton()
{
base.UpButton();

OnUpButtonClick(EventArgs.Empty);
}

public override void DownButton()
{
base.DownButton();

OnDownButtonClick(EventArgs.Empty);
}

private static readonly object DownButtonClickEvent = new object(), UpButtonClickEvent = new object();

[Category("Action")]
public event EventHandler DownButtonClick
{
add
{
Events.AddHandler(DownButtonClickEvent, value);
}
remove
{
Events.RemoveHandler(DownButtonClickEvent, value);
}
}

[Category("Action")]
public event EventHandler UpButtonClick
{
add
{
Events.AddHandler(UpButtonClickEvent, value);
}
remove
{
Events.RemoveHandler(UpButtonClickEvent, value);
}
}

protected virtual void OnUpButtonClick(EventArgs e)
{
if (Events[UpButtonClickEvent] != null)
(Events[UpButtonClickEvent] as EventHandler)(this, e);
}

protected virtual void OnDownButtonClick(EventArgs e)
{
if (Events[DownButtonClickEvent] != null)
(Events[DownButtonClickEvent] as EventHandler)(this, e);
}
}
 
Thank you,

dave

Dave Sexton said:
Hi Dave,

I don't think there is an event that tells you when a button is pressed, but you can easily add events if you want. I wrote this
code using the 2.0 framework and it seems to work just fine:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

public class NumericUpDownEx : NumericUpDown
{
public override void UpButton()
{
base.UpButton();

OnUpButtonClick(EventArgs.Empty);
}

public override void DownButton()
{
base.DownButton();

OnDownButtonClick(EventArgs.Empty);
}

private static readonly object DownButtonClickEvent = new object(), UpButtonClickEvent = new object();

[Category("Action")]
public event EventHandler DownButtonClick
{
add
{
Events.AddHandler(DownButtonClickEvent, value);
}
remove
{
Events.RemoveHandler(DownButtonClickEvent, value);
}
}

[Category("Action")]
public event EventHandler UpButtonClick
{
add
{
Events.AddHandler(UpButtonClickEvent, value);
}
remove
{
Events.RemoveHandler(UpButtonClickEvent, value);
}
}

protected virtual void OnUpButtonClick(EventArgs e)
{
if (Events[UpButtonClickEvent] != null)
(Events[UpButtonClickEvent] as EventHandler)(this, e);
}

protected virtual void OnDownButtonClick(EventArgs e)
{
if (Events[DownButtonClickEvent] != null)
(Events[DownButtonClickEvent] as EventHandler)(this, e);
}
}

--
Dave Sexton

dave said:
Hello:


Is there way to find out whether
Up or Down button on NumericUpDown was clicked ?
 
Back
Top