8 Replies - 9297 Views - Last Post: 11 September 2007 - 06:55 PM Rate Topic: -----

#1 quick_nick  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 11-September 07

onmouseover on a button

Post icon  Posted 11 September 2007 - 04:05 PM

I am trying to create a small joke program while learning vb. What i would like to do is make one button control disappear when the mouse rolls over it. Problem i am running into is i don't see a how to handle this. Is this even possible? :blink:

For instance user moves mouse over button that says something like exit and it set the cmdButton.Visible = false property.


here is what i have so far. but it doesnt work so i must have something wrong.

Private Sub CmdNo1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
with cmdNo1
.Visible = False
End With
with cmdNo2
.Visible = True
End With
End Sub

Private Sub CmdNo2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
with cmdNo2
.Visible = False
End With
with cmdNo1
.Visible = True
End With
End Sub

This post has been edited by quick_nick: 11 September 2007 - 04:51 PM


Is This A Good Question/Topic? 1

Replies To: onmouseover on a button

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onmouseover on a button

Posted 11 September 2007 - 05:13 PM

This took a little trial & error. To do this:
  • Add a command button to your form (I used the default name Command1)
  • Add a label under the button, make it wider than the button yet short
  • In the buttons MouseMove Event add this code:
    Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.Visible = False
    End Sub
    
    

  • In the labels MouseMove Event add this code:
    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.Visible = True
    End Sub
    
    

Now when you mouse over the button the button will disappear, and when you mouse of the label (with the Caption set to an empty string) the button becomes visible again
Was This Post Helpful? 0
  • +
  • -

#3 quick_nick  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 11-September 07

Re: onmouseover on a button

Posted 11 September 2007 - 05:34 PM

Thanks for your help Psyco

unfortuantly i was trying to do this with #develop and it doesnt work unless i use vb6. I dont own a copy of vb6 just the demo that comes with the teachyourself book by sams.

:D :D

This post has been edited by quick_nick: 11 September 2007 - 05:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onmouseover on a button

Posted 11 September 2007 - 05:49 PM

What exactly is #develop?
Was This Post Helpful? 0
  • +
  • -

#5 quick_nick  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 11-September 07

Re: onmouseover on a button

Posted 11 September 2007 - 06:03 PM

View PostPsychoCoder, on 11 Sep, 2007 - 05:49 PM, said:

What exactly is #develop?


its an open source object oriented compiler for windows. Used for C#, VB.net and boo mostly but i am just getting into it.
Here is the wikipedia info on it.

I like #develop better because its smaller and has a lot more options for usage but then again it doesnt work for this simple project so maybe its not so great.

This post has been edited by quick_nick: 11 September 2007 - 06:05 PM

Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onmouseover on a button

Posted 11 September 2007 - 06:41 PM

Ohhh Sharp Develop, I have that also. So you're trying to do this in VB.Net?
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onmouseover on a button

Posted 11 September 2007 - 06:52 PM

If you're doing this in VB.Net then do this

Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Button1.MouseMove
		If Button1.Visible = False Then
			Button1.Visible = True
		Else
			Button1.Visible = False
		End If
End Sub

	Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
		If Button1.Visible = False Then
			Button1.Visible = True
		Else
			Button1.Visible = False
		End If
End Sub



I tested it and it does exactly what you're looking for.

Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#8 quick_nick  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 11-September 07

Re: onmouseover on a button

Posted 11 September 2007 - 06:53 PM

Thanks psyco your a great help

This post has been edited by quick_nick: 11 September 2007 - 06:53 PM

Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onmouseover on a button

Posted 11 September 2007 - 06:55 PM

No problem Nick, thats what we're here for :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1