Results 1 to 34 of 34

Thread: [RESOLVED] How to set panel visible as true

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  3. #3
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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:
    1. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    2.         If Panel1.Visible = False AndAlso Panel1.Bounds.Contains(e.Location) Then Panel1.Visible = True
    3.     End Sub

    BB

    Edit: too slow again! The above sub is identical in effect to Minitech's OnMouseDown.

  5. #5

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: How to set panel visible as true

    Quote Originally Posted by boops boops View Post
    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:
    1. Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    2.         If Panel1.Visible = False AndAlso Panel1.Bounds.Contains(e.Location) Then Panel1.Visible = True
    3.     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

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: How to set panel visible as true

    Is shockwave a control or you mean an external app?

  8. #8

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: How to set panel visible as true

    Quote Originally Posted by Grimfort View Post
    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?

  9. #9
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  10. #10

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: How to set panel visible as true

    I have tried it, but unfortunately it doesn't work. Any idea?

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to set panel visible as true

    Quote Originally Posted by mark108 View Post
    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

  12. #12

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    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

  13. #13
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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?

  14. #14

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    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?

  15. #15
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  16. #16
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to set panel visible as true

    Quote Originally Posted by mark108 View Post
    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.

  17. #17

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    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

  18. #18
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  19. #19

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    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

  20. #20

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: How to set panel visible as true

    Quote Originally Posted by minitech View Post
    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?

  21. #21
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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?

  22. #22
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  23. #23
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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?

  24. #24
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: How to set panel visible as true

    Quote 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.

  25. #25
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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.

  26. #26

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: How to set panel visible as true

    Quote Originally Posted by minitech View Post
    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

  27. #27
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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"?

  28. #28
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    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.

  29. #29

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    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?

  30. #30
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: How to set panel visible as true

    You only need the second sample, not both and it should be in your timer event.

  31. #31

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: How to set panel visible as true

    I got it now, thanks for the help guys. You all have been amazing!

    Problem solved!

  32. #32
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: [RESOLVED] How to set panel visible as true

    I'm sorry, it should be .Position, not .Location. I've edited my post.

  33. #33
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: [RESOLVED] How to set panel visible as true

    Rate minitech, I think he understood you better then anyone else .

  34. #34

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: [RESOLVED] How to set panel visible as true

    Quote Originally Posted by minitech View Post
    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!


    Quote Originally Posted by Grimfort View Post
    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
  •  



Click Here to Expand Forum to Full Width