0

I have created a winform app in c# and made it transparent but I need to allow client click behind the winform area (right click or run if there is a file behind) is it possible?

        InitializeComponent();

        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.BackColor = Color.Transparent;
        this.TransparencyKey = Color.Blue;
        this.FormBorderStyle = FormBorderStyle.None;

        Rectangle workingArea = Screen.GetWorkingArea(this);
        this.Location = new Point(workingArea.Right - Size.Width,
                                  workingArea.Bottom - Size.Height);

    private void FormNotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }
    private void NotifyMenuMin_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }
    private void NotifyMenuMax_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }
VillageTech
  • 1,968
  • 8
  • 18
Brusky
  • 43
  • 9
  • What do you mean ***file behind***? – Chibueze Opata Dec 11 '19 at 07:21
  • When I run my winform app in bottom right of desktop only icon appear and form area is transparency but if I have any file behind the form is not clickable/run! – Brusky Dec 11 '19 at 07:33
  • 1
    The specific choice of TransparencyKey matters on recent versions of Windows. Related to a bug in DWM (aka Aero), it is sensitive to the color you choose. The side-effect of the bug is that the UI is transparent to the eye but not the mouse. Color.Blue happens to be a bad choice, Color.Red is another one that doesn't work correctly. They are in general bad choices anyway since it is somewhat likely that other parts of the UI use that color and get transparent unintentionally. Good choices are Color.Fuchsia and Color.Lime. – Hans Passant Dec 11 '19 at 08:53

2 Answers2

1

Try to use the same color for TransparencyKey and BackColor as follow.

    public TestForm()
    {
        InitializeComponent();

        this.BackColor = Color.Lime; 
        this.TransparencyKey = Color.Lime;
        this.FormBorderStyle = FormBorderStyle.None;
    }
  • and follow these links as well in order to get an idea https://stackoverflow.com/a/2798294/2801351 https://stackoverflow.com/a/7290369/2801351 – Dilan Wickramarathna Dec 11 '19 at 08:04
  • transparency is ok if client have a file behind cant click! (green area) https://imgbbb.com/images/2019/12/11/2019-12-11_11-19-07.jpg – Brusky Dec 11 '19 at 08:24
  • yes, I can understand, can you try to use this.BackColor = Color.Blue; instead of this.BackColor = Color.Transparent; by using the same colors as background and TransparencyKey will allow you to click through the transparent area – Dilan Wickramarathna Dec 11 '19 at 08:32
  • InitializeComponent(); SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Blue; this.TransparencyKey = Color.Blue; this.TopMost = true; this.FormBorderStyle = FormBorderStyle.None; result is same:( – Brusky Dec 11 '19 at 08:37
0

I found this code and working but makes all content of form transparent and also clickable button is not working :( I changed the key color to blue soo lime color has been used in myform!

        InitializeComponent();
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.BackColor = Color.Blue;
        this.TransparencyKey = Color.Blue;
        this.TopMost = true;
        this.FormBorderStyle = FormBorderStyle.None;

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            // Set the form click-through
            cp.ExStyle |= 0x80000 /* WS_EX_LAYERED */ | 0x20 /* WS_EX_TRANSPARENT */;
            return cp;
        }
    }
Brusky
  • 43
  • 9
  • https://imgbbb.com/images/2019/12/11/2019-12-11_11-41-13.jpg – Brusky Dec 11 '19 at 08:43
  • 1
    If it's not working, don't post it as an answer. There are a *lot* of duplicate questions about transparent forms or irregular form shapes already – Panagiotis Kanavos Dec 11 '19 at 08:52
  • Besides, Hans Passant explained in a question comment that using Blue and Red don't work well as a TransparencyKey color and are likely to be used in other parts of the form anyway – Panagiotis Kanavos Dec 11 '19 at 08:57