Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a Form's clicks "fall through" to the application below

Tags:

c#

.net

winforms

I've made a form with an opacity of 30%, and I want this to overlay on my screen so I can draw a grid on it whilst still being able to control any programs underneath. So I want the form I created with the grid to ignore my mouse events, so I can click through to the program underneath but still have it displaying on top.

Any ideas on this one?

like image 990
Mike Avatar asked Jun 21 '11 09:06

Mike


1 Answers

You can specify Transparent Key Color to some color value of forms backcolor for clickthru area this color should be different from Grid Color you choose

This is VB.Net Code I tried should not be difficult to convert to C#

Private Sub frmTest_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    Dim rc As Rectangle = New Rectangle(0, 0, Me.Width - 1, Me.Height - 1)
    Using br As New Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Color.Silver, Color.Transparent)
        e.Graphics.FillRectangle(br, rc)
    End Using
End Sub

Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.TopMost = True : Me.Opacity = 10% : Me.WindowState = FormWindowState.Maximized
    Me.BackColor = Color.White
    Me.TransparencyKey = Color.White
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End Sub
like image 161
Rajeev Avatar answered Sep 26 '22 22:09

Rajeev