Numeric Up Down

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

i am trying to determine which button was clicked (up or down) on a numeric up down control. dotting into the e or sender objects do not provide any usefill information

i need to execute different logic depending on what button was clicked

thanks in advance
Kunkel
 
Just compare the last value with the current value. If it was 5 and now
it's 6 then you know the user clicked the up button.
 
Hi Kunkel

NumericUpDown inherits from UpDownBase. You can override UpButton and
DownButton, thereby distinguishing between the two. Remember to call
MyBase.UpButton and MyBase.DownButton though.

HTH

Charles


Kunkel said:
Hi All,

i am trying to determine which button was clicked (up or down) on a
numeric up down control. dotting into the e or sender objects do not provide
any usefill information.
 
Try this:

Public Class NewNumeric
Inherits System.Windows.Forms.UpDownBase

Dim count As Integer = 0

Public Sub New()
Mybase.New()
End Sub

Public Overrides Sub DownButton()
Debug.WriteLine("Down Called")
count -= 1
Me.Text = count.ToString
End Sub

Public Overrides Sub UpButton()
Debug.WriteLine("Up Called")
count += 1
Me.Text = count.ToString
End Sub

Protected Overrides Sub UpdateEditText()

End Sub
End Class
 
Kunkel

First, create a user control inside your project. By default it will be
called UserControl1, and at the top it will have

Inherits System.Windows.Forms.UserControl

Change this to

Inherits System.Windows.Forms.NumericUpDown

Then add the following procedures

Public Overrides Sub UpButton()

MyBase.UpButton()

' Do your stuff here ...

End Sub

Public Overrides Sub DownButton()

MyBase.DownButton()

' Do your stuff here ...

End Sub

Build your project, and then go to the form where you want to use the
NumericUpDown control. In the toolbox you should see a tab 'My User
Controls', on which is the control you have just created. Drag one of these
onto your form and it will behave just like a NumericUpDown control. The
only difference is that when you click the buttons, the procedures you
copied above will be called, whereupon you can do your special processing.

HTH

Charles


Kunkel said:
Charles,

thanks for the reply. that makes sense, but i have had no experience in
overriding subs especially in non-user defined classes. could you please
elaborate a little bit more on the implementation of this?
 
No, you don't call MyBase.UpButton(). UpButton and DownDutton are
MustInherit so you don't and can't call MyBase.UpButton().
 
That would be true if inheriting from UpDownBase, but I am suggesting
inheriting from NumericUpDown.

The OP seemed prepared to use the NumericUpDown control, so they would lose
functionality if inheriting from UpDownBase.

Charles
 
Back
Top