Tags: button, clicked, net, numericupdown, sharp

NumericUpDown

On .Net » .Net C# (C sharp)

4,124 words with 2 Comments; publish: Mon, 02 Jun 2008 16:56:00 GMT; (10093.75, « »)

Hello:

Is there way to find out whether

Up or Down button on NumericUpDown was clicked ?

All Comments

Leave a comment...

  • 2 Comments
    • 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" <dave.net-csharp.questionfor.info.discussions.microsoft.com> wrote in message news:AC30ADC6-F56A-4715-82E7-D9741CD0B68F.net-csharp.questionfor.info.microsoft.com...

      > Hello:

      >

      > Is there way to find out whether

      > Up or Down button on NumericUpDown was clicked ?

      #1; Mon, 02 Jun 2008 16:57:00 GMT
    • Thank you,

      dave

      "Dave Sexton" wrote:

      > 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" <dave.net-csharp.questionfor.info.discussions.microsoft.com> wrote in message news:AC30ADC6-F56A-4715-82E7-D9741CD0B68F.net-csharp.questionfor.info.microsoft.com...

      > > Hello:

      > >

      > >

      > > Is there way to find out whether

      > > Up or Down button on NumericUpDown was clicked ?

      >

      >

      #2; Mon, 02 Jun 2008 16:58:00 GMT