10 Replies - 759 Views - Last Post: 06 September 2012 - 09:58 PM Rate Topic: -----

#1 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Tool Tips in VB

Posted 03 September 2012 - 07:46 PM

I just wanted to know how i can add a ToolTip so that i can force the user NOT to enter numbers less and 0?

I've tried tutorials everywhere but they dont do what i need.

Basically i need the textbox (ALCTextBox) to make sure that ONLY positive numbers are entered. And if they user TRIES to type a '-' it doesn't get added to the tetbox. instead a tooltip error pops up saying that they must input a positive integer.

Thank you very much for helping <3

Is This A Good Question/Topic? 0
  • +

Replies To: Tool Tips in VB

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 230
  • View blog
  • Posts: 753
  • Joined: 19-October 11

Re: Tool Tips in VB

Posted 03 September 2012 - 10:44 PM

Did you try adding new ToolTip to TextChanged event handling subroutine for that textbox?

Spoiler

Was This Post Helpful? 1
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 832
  • Joined: 21-December 11

Re: Tool Tips in VB

Posted 04 September 2012 - 05:57 AM

There is control called tooltip, you can use this control and show tooltip anywhere and anytime on the form. You can use IsNumeric function to check whether the pressed key is number or not, if not then call
e.SuppressKeyPress = True
in the "keydown" event.
Was This Post Helpful? 0
  • +
  • -

#4 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: Tool Tips in VB

Posted 04 September 2012 - 04:22 PM

View Postlucky3, on 03 September 2012 - 10:44 PM, said:

Did you try adding new ToolTip to TextChanged event handling subroutine for that textbox?

Spoiler


THAT WORKS!
However, is there an option that STOPS the user from entering a '-' or a letter of the alphabet? As in if they try and press 'w', the 'w' wont appear only the error?
Was This Post Helpful? 0
  • +
  • -

#5 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 966
  • View blog
  • Posts: 3,721
  • Joined: 02-July 08

Re: Tool Tips in VB

Posted 04 September 2012 - 08:25 PM

You need to use the keyDown or keyPress events to check the key that is being pressed and suppress the ones you don't want. Snippet found right on this web page. I use a slightly diff approach, but it will help you understand.
Was This Post Helpful? 0
  • +
  • -

#6 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: Tool Tips in VB

Posted 05 September 2012 - 01:00 AM

View Post_HAWK_, on 04 September 2012 - 08:25 PM, said:

You need to use the keyDown or keyPress events to check the key that is being pressed and suppress the ones you don't want. Snippet found right on this web page. I use a slightly diff approach, but it will help you understand.


Okay, i now have the opposite XD
It restricts all non-numeric inputs but has no display?! :|
Is there anyway that i can notify the user to enter positive numbers?
Was This Post Helpful? 0
  • +
  • -

#7 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 230
  • View blog
  • Posts: 753
  • Joined: 19-October 11

Re: Tool Tips in VB

Posted 05 September 2012 - 01:51 AM

Just add Dim myToolTip... and myToolTip.Show... lines from my previous post, after e.Handled = True line, if you're using that snippet.

This post has been edited by lucky3: 05 September 2012 - 01:52 AM

Was This Post Helpful? 0
  • +
  • -

#8 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: Tool Tips in VB

Posted 05 September 2012 - 02:47 AM

Alrighty. That all works fine.

However. If i enter a letter it accepts it :(

Heres my code:
Private Sub ALCTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ALCTextBox.KeyPress
        If (e.KeyChar < "0") _
    AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then
            e.Handled = True
            Dim myToolTip As New ToolTip With {.IsBalloon = True, .ToolTipTitle = "Error..."}
            myToolTip.Show("You must enter a positive Integer", ALCTextBox, 3000)
        ElseIf IsNumeric(ALCTextBox) Then
            e.Handled = True
            Dim myToolTip As New ToolTip With {.IsBalloon = True, .ToolTipTitle = "Error..."}
            myToolTip.Show("You must enter an Integer", ALCTextBox, 3000)
        End If
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#9 ebolisa  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 22-September 09

Re: Tool Tips in VB

Posted 05 September 2012 - 03:45 AM

It appears you left out the following code on line 2 to check for alpha chars.

OrElse e.KeyChar > "9"



EDIT:

These few lines worked for me...

    If (e.KeyChar < "0") OrElse e.KeyChar > "9" _
            AndAlso e.KeyChar <> ControlChars.Back _ 
            AndAlso e.KeyChar <> "." Then

            e.Handled = True

            Dim myToolTip As New ToolTip With {.IsBalloon = True, .ToolTipTitle = "Error..."}
            myToolTip.Show("You must enter a positive Integer", Me.txbUsrName, 3000)

        End If


This post has been edited by ebolisa: 05 September 2012 - 03:55 AM

Was This Post Helpful? 0
  • +
  • -

#10 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: Tool Tips in VB

Posted 06 September 2012 - 09:38 PM

Its all good!

Is there anyway that i can change the LOCATION of the pop-up bubble?

Its showing underneath the textbox and its distracting :(

This post has been edited by Rmclayton: 06 September 2012 - 09:44 PM

Was This Post Helpful? 0
  • +
  • -

#11 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 966
  • View blog
  • Posts: 3,721
  • Joined: 02-July 08

Re: Tool Tips in VB

Posted 06 September 2012 - 09:58 PM

MSDN can be useful when researching how to make the controls work.

ToolTip.Show()
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1