|
-
Aug 25th, 2010, 04:38 PM
#1
Thread Starter
Banned
[RESOLVED] How to set panel visible as true
Hi guys,
I need a little help. I have set the panel on visible as false, so it would not show up when I run the form. I am trying to set the visible as true when I enter my mouse on panel location, but it doesn't show anything....
Code:
Private Sub Panel1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Enter
Panel1.Visible = True
End Sub
How to set the panel visible as true when I enter my mouse on panel location while the visible are false?
Thanks,
Mark
-
Aug 25th, 2010, 04:41 PM
#2
Re: How to set panel visible as true
The panel is invisible, none of its events will run. You could use the panels parent as the event starter, or hide all the controls on the panel and show them in a loop on your panel enter event.
-
Aug 25th, 2010, 04:43 PM
#3
Re: How to set panel visible as true
Well, if the Panel isn't visible, the user obviously can't put their mouse over it, so you have a bit of a problem there... 
To make it invisible, instead do this:
Code:
For Each c As Control In Me.Panel1.Controls : c.Hide() : Next
To make it visible:
Code:
For Each c As Control In Me.Panel1.Controls : c.Show() : Next
Of course, you might have to make a few special exceptions.
The alternative is to create a Rectangle and check the mouse's position:
Code:
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If Me.Panel1.Bounds.Contains(e.Location) Then Me.Panel1.Show()
End Sub
Last edited by minitech; Aug 25th, 2010 at 05:28 PM.
-
Aug 25th, 2010, 04:47 PM
#4
Re: How to set panel visible as true
The Panel's Enter (and MouseEnter) events won't fire if it's not visible. So instead handle the Form's MouseMove event like this:
vb.net Code:
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove If Panel1.Visible = False AndAlso Panel1.Bounds.Contains(e.Location) Then Panel1.Visible = True End Sub
BB
Edit: too slow again! The above sub is identical in effect to Minitech's OnMouseDown.
-
Aug 25th, 2010, 05:17 PM
#5
Thread Starter
Banned
Re: How to set panel visible as true
 Originally Posted by boops boops
The Panel's Enter (and MouseEnter) events won't fire if it's not visible. So instead handle the Form's MouseMove event like this:
vb.net Code:
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If Panel1.Visible = False AndAlso Panel1.Bounds.Contains(e.Location) Then Panel1.Visible = True
End Sub
BB
Edit: too slow again! The above sub is identical in effect to Minitech's OnMouseDown.
Thanks for your quick response, this is what I wanted. I wish to use that code on a different control such as shockwave, so in what event that I could use for mouse move on shockwave?
Using form mouse move event is a good things to use, but it doesn't help me out for shockwave. It only works for the form without using any of the controls.
Thanks,
Mark
-
Aug 25th, 2010, 05:27 PM
#6
Re: How to set panel visible as true
Oh, darn! I wrote OnMouseDown! 
@mark108: It should work pretty much the same, just replace Panel1 with ShockWaveFlash1 or whatever the name of your flash player is.
-
Aug 25th, 2010, 05:30 PM
#7
Re: How to set panel visible as true
Is shockwave a control or you mean an external app?
-
Aug 25th, 2010, 05:34 PM
#8
Thread Starter
Banned
Re: How to set panel visible as true
 Originally Posted by Grimfort
Is shockwave a control or you mean an external app?
Yep, shockwave is a flash control that I am using. In what event that I should use for mouse move on shockwave?
-
Aug 25th, 2010, 05:43 PM
#9
Re: How to set panel visible as true
If the control is on the form and you want the same thing, to make it visible, then the code above should work as well just replacing the panel name for the shockwave control.
-
Aug 25th, 2010, 05:58 PM
#10
Thread Starter
Banned
Re: How to set panel visible as true
I have tried it, but unfortunately it doesn't work. Any idea?
-
Aug 25th, 2010, 07:09 PM
#11
Re: How to set panel visible as true
 Originally Posted by mark108
I have tried it, but unfortunately it doesn't work. Any idea?
The SW control doesn't seem to have a mouse_move event, so I guess you'd have to come up with a workaround? Never used the control myself, did something like this in VB6 for someone once...
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")> _
Private Shared Function WindowFromPoint(ByVal Point As Point) As IntPtr
End Function
Dim SW_hWnd As Long
Dim WithEvents SW_tmr As New Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'SW control must be visible to get handle ?
AxShockwaveFlash1.Visible = True
SW_hWnd = AxShockwaveFlash1.Handle
' setup timer
SW_tmr.Interval = 60 ' set mouse move detect speed
SW_tmr.Start()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SW_tmr.Stop() ' stop timer
End Sub
Private Sub SW_tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles SW_tmr.Tick
Dim tPA As Point
Dim lhWnd As Long
Static SW_Last_Point As Point
' get cursor pos.
tPA = Cursor.Position
' get window handle from point
lhWnd = WindowFromPoint(tPA)
' is cursor over SW control?
If lhWnd = SW_hWnd Then
' did cursor position change since last checked?
If SW_Last_Point.X <> tPA.X Or SW_Last_Point.Y <> tPA.Y Then
SW_Last_Point.X = tPA.X
SW_Last_Point.Y = tPA.Y
' do something here...
Debug.Print("mouse move - SW control (x,y) = " & tPA.X & "," & tPA.Y) ' clintto
End If
End If
End Sub
End Class
-
Aug 25th, 2010, 08:38 PM
#12
Thread Starter
Banned
Re: How to set panel visible as true
Thanks for this, so how can I make a mouse point of the panel location on the shockwave mousemove event using on above?
Thanks,
Mark
-
Aug 25th, 2010, 09:25 PM
#13
Re: How to set panel visible as true
The SW control doesn't have a MouseMove event, yes, but in this case we're handling the form's MouseMove event... can you post the code you tried, please?
-
Aug 26th, 2010, 12:16 PM
#14
Thread Starter
Banned
Re: How to set panel visible as true
Here it is:
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function WindowFromPoint(ByVal Point As Point) As IntPtr
End Function
Dim SW_hWnd As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'SW control must be visible to get handle ?
SW_hWnd = AxShockwaveFlash1.Handle
' setup timer
SWtmr.Interval = 60 ' set mouse move detect speed
SWtmr.Start()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
SWtmr.Stop() ' stop timer
End Sub
Private Sub SWtmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles SWtmr.Tick
Dim tPA As Point
Dim lhWnd As Long
Static SW_Last_Point As Point
' get cursor pos.
tPA = Windows.Forms.Cursor.Position
' get window handle from point
lhWnd = WindowFromPoint(tPA)
' is cursor over SW control?
Dim e1 As System.Windows.Forms.MouseEventArgs
If lhWnd = SW_hWnd Then
' did cursor position change since last checked?
If SW_Last_Point.X <> tPA.X Or SW_Last_Point.Y <> tPA.Y Then
If Panel1.Visible = False AndAlso Panel1.Bounds.Contains(e1.Location) Then
Panel1.Visible = True
SW_Last_Point.X = tPA.X
SW_Last_Point.Y = tPA.Y
' do something here...
MessageBox.Show("mouse move - SW control (x,y) = " & tPA.X & "," & tPA.Y) ' clintto
End If
End If
End If
End Sub
End Class
When I mouseover on the shockwave control, the project start to crash everytime when I mouseover on the shockwave.
Any idea?
-
Aug 26th, 2010, 12:19 PM
#15
Re: How to set panel visible as true
Wha??? Use this instead, and remove the timer and timer code entirely...
Code:
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If Me.AxShockwaveFlash1.Bounds.Contains(e.Location) Then Me.AxShockwaveFlash1.Show()
End Sub
If it doesn't have a Bounds property (I don't know about this control) you need to make your own rectangle.
-
Aug 26th, 2010, 12:35 PM
#16
Re: How to set panel visible as true
 Originally Posted by mark108
When I mouseover on the shockwave control, the project start to crash everytime when I mouseover on the shockwave.
Any idea?
I'd follow minitech's advise , but if you use a timer you should stop the timer before you take any action (so it doesn't repeat), then restart the timer when mouse is over the form or whatever.
-
Aug 26th, 2010, 12:48 PM
#17
Thread Starter
Banned
Re: How to set panel visible as true
Well that is what I tried to use. The panel is on the shockwave control, so I tried to mouseover on the shockwave and then mouseover on the panel to set the visible as true. That's how the program start to crash.
As you override code you post, it only mouseover on the shockwave control. I want to mouseover the shockwave control and then mouseover the panel to set the visible as true.
Thanks,
Mark
-
Aug 26th, 2010, 12:48 PM
#18
Re: How to set panel visible as true
Sorry, I missed your post there. I thought he sort of pulled the timer out of thin air.
@mark108: Is the Shockwave control on the Panel? If not, you just add another line:
Code:
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If Me.AxShockwaveFlash1.Bounds.Contains(e.Location) Then Me.AxShockwaveFlash1.Show()
If Me.Panel1.Bounds.Contains(e.Location) Then Me.Panel1.Show()
End Sub
Last edited by minitech; Aug 26th, 2010 at 12:51 PM.
-
Aug 26th, 2010, 12:51 PM
#19
Thread Starter
Banned
Re: How to set panel visible as true
That's okay, so now you know what I am trying to do: Mouseover the panel location on the shockwave control to set the panel visible as true.
Thanks,
Mark
-
Aug 26th, 2010, 12:56 PM
#20
Thread Starter
Banned
Re: How to set panel visible as true
 Originally Posted by minitech
Sorry, I missed your post there. I thought he sort of pulled the timer out of thin air.
@mark108: Is the Shockwave control on the Panel? If not, you just add another line:
Code:
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If Me.AxShockwaveFlash1.Bounds.Contains(e.Location) Then Me.AxShockwaveFlash1.Show()
If Me.Panel1.Bounds.Contains(e.Location) Then Me.Panel1.Show()
End Sub
Thanks, but nothing have happens when I mouseover on the shockwave control and then the panel. Any idea?
-
Aug 26th, 2010, 12:59 PM
#21
Re: How to set panel visible as true
No.
So, again: is the Shockwave Flash control in the Panel? Are both of their Visible properties set to False? Does the order matter? Can you post your full code, please?
-
Aug 26th, 2010, 12:59 PM
#22
Re: How to set panel visible as true
You have a form, on that form you have a panel, in that panel you have the flash control?
You say the flash control "then" the panel but nothing happens, if both are invisible then does one become visible? If one does become visible, then the mouse events of the form will stop because the control that became visible is now raising the events instead.
Last edited by Grimfort; Aug 26th, 2010 at 01:04 PM.
-
Aug 26th, 2010, 01:04 PM
#23
Re: How to set panel visible as true
Actually, I bet both the panel and the flash control are on the form itself. Why is there even a panel involved in this?
-
Aug 26th, 2010, 01:04 PM
#24
Re: How to set panel visible as true
 Originally Posted by Grimfort
You have a form, on that form you have a panel, in that form you have the flash control?
You say the flash control "then" the panel but nothing happens, if both are invisible then does one become visible? If one does become visible, then the mouse events of the form will stop because the control that became visible is now raising the events instead.
That's not true - if the mouse is not within the bounds of any visible control, the OnMouseDown method will be called.
-
Aug 26th, 2010, 01:07 PM
#25
Re: How to set panel visible as true
Thats what I said (and its move thats being talked about ), the forms events will fire until either panel/flash control is visible, then it will stop firing as the control will be handling the events.
-
Aug 26th, 2010, 01:09 PM
#26
Thread Starter
Banned
Re: How to set panel visible as true
 Originally Posted by minitech
No.
So, again: is the Shockwave Flash control in the Panel? Are both of their Visible properties set to False? Does the order matter? Can you post your full code, please?
I am sorry if I have made you confused, so please forgive me. No, the shockwave flash control isn't in the panel. The panel is in the shockwave control, so the shockwave are visible as true but the panel visible are false.
Code:
Public Class Form1
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
MyBase.OnMouseMove(e)
If Me.AxShockwaveFlash1.Bounds.Contains(e.Location) Then
If Me.Panel1.Bounds.Contains(e.Location) Then Me.Panel1.Visible = True
End Sub
End Class
On the code on above, I have tried to mouseover on the shockwave control and then the panel, so nothing have happens. What I am trying to do: I want to mouseover on the shockwave control while the panel visible are false and then mouseover on the panel location in the shockwave flash control to set the panel visible as true. I tried to use it on the form mousemove event, it doesn't do anything. 
Hope you will understand this now.
Thanks,
Mark
-
Aug 26th, 2010, 01:12 PM
#27
Re: How to set panel visible as true
Okay... that makes things a little bit harder. You're going to have to go with the timer, I think...
By the way, does this have any relation to your thread "Flash overlay"?
-
Aug 26th, 2010, 01:14 PM
#28
Re: How to set panel visible as true
But! You don't need any APIs. Here's some code, put this inside the timer's Tick event:
Code:
Dim r As New Rectangle(Me.AxShockwaveFlash1.Location, Me.Panel1.Size)
r.Location += New Size(Me.Panel1.Location)
If r.Contains(Me.PointToClient(Windows.Forms.Cursor.Position)) Then
Me.Panel1.Show()
Me.Timer1.Stop()
End If
Come to think of it, you might even be able to do this:
Code:
If Me.Panel1.ClientRectangle.Contains(Me.Panel1.PointToClient(Windows.Forms.Cursor.Position)) Then
Me.Panel1.Show()
Me.Timer1.Stop()
End If
Last edited by minitech; Aug 26th, 2010 at 01:27 PM.
-
Aug 26th, 2010, 01:23 PM
#29
Thread Starter
Banned
Re: How to set panel visible as true
Thanks for this, where shall I input the both code in which event shall I input each of them?
And I am received the same error which they are jumping on both if statement. The error are goes on Windows.Forms.Cursor.Location.
Error I am getting:'Location' is not a member of 'System.Windows.Forms.Cursor'.
What can I do to change to a different method in the properties?
-
Aug 26th, 2010, 01:24 PM
#30
Re: How to set panel visible as true
You only need the second sample, not both and it should be in your timer event.
-
Aug 26th, 2010, 01:26 PM
#31
Thread Starter
Banned
Re: How to set panel visible as true
I got it now, thanks for the help guys. You all have been amazing!
Problem solved!
-
Aug 26th, 2010, 01:27 PM
#32
Re: [RESOLVED] How to set panel visible as true
I'm sorry, it should be .Position, not .Location. I've edited my post.
-
Aug 26th, 2010, 01:27 PM
#33
Re: [RESOLVED] How to set panel visible as true
Rate minitech, I think he understood you better then anyone else .
-
Aug 26th, 2010, 01:39 PM
#34
Thread Starter
Banned
Re: [RESOLVED] How to set panel visible as true
 Originally Posted by minitech
I'm sorry, it should be .Position, not .Location. I've edited my post.
Don't worry about it, as mistake can happens. I have found solution anyway I don't need to blame you for it. Thanks for your help anyway, you have been brilliant but a very clever and smart guy!
 Originally Posted by Grimfort
Rate minitech, I think he understood you better then anyone else  .
Yes he did, he's very good on things and always understood with something what we are trying to do. He has got good intelligent and he brought with his good brains today. I am going to rate him anyway....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|