Results 1 to 3 of 3

Thread: transparent panel to catch mouse events

  1. #1

    Thread Starter
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    transparent panel to catch mouse events

    i have a panel on a form that allows me to view any window under the form.




    The problem i cannot sort out is at the moment i am able to select items under the transparent panel, how can i change this so i can only view items under the form and not actually select them?

    I am also wanting to capture the mosue events in the panel.

    Forms property:
    ForeColor = ButtonFace
    TransparentKey = ButtonFace
    TopMost = true
    Rest are default

    Panels properties:
    BackColor = Transparent
    Rest are default

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: transparent panel to catch mouse events

    If the form/Panel is 100% transparent then you can't click it. It's needs to be at least 1% opaque.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: transparent panel to catch mouse events

    You can deal with it by placing an Owned Form with 1% opacity in front of your main form, to capture the mouse events. An Owned Form stays linked with its owner in the Z order. You need to code the X and Y bounds in the main form's Move event etc. Here's example:
    Code:
    Public Class Form1
    
    	Private WithEvents Form2 As New Form
    
    	Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    		With Form2
    			.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    			.ShowInTaskbar = False			
    			.Opacity = 0.01
    			.Show(Me) 'show Form2 with Owner (Me)
    		End With
    	End Sub
    
    	Private Sub Form1_MoveEtc(sender As Object, e As System.EventArgs) Handles Me.Move, Me.SizeChanged, Me.Shown
    		Form2.Bounds = Me.RectangleToScreen(Me.ClientRectangle)
    	End Sub
    
            Private Sub Form2_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Form2.MouseClick
    		If Me.Panel1.Bounds.Contains(e.Location) Then
    			'your panel click action here
    		End If
    	End Sub
    
    End Class
    For debugging purposes, set Form2's opacity to e.g. 0.1 instead of 0.01. As an alternative to coding Form2's mouse events, you can make the area of Form2 corresponding to the Panel on Form1 transparent by using Form2's TransparencyKey. Then you can handle all the Panel's mouse events directly.

    BB

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