C#TransparencyKey does not work on the back when the transparent panel is overlapped on the backgroundless form.

Asked 1 years ago, Updated 1 years ago, 58 views

Set the red background image to the WindowsForm background and set the TransparencyKey to Red. This will create a form in the form of the image without the background (whether or not the edges are removed in FormBorderStyle).
Normally, in this state, the empty space between stars as shown in the figure can be accessed by the desktop on the back.

However, the panel is attached to it with Dock.Fill, etc., and the BackColor of the panel is Transparent, which looks like the same form, but it seems that the panel is interfering with the desktop side.

Naturally, controls such as panels do not have TransparencyKey, and even if the background is transparent and missing, you cannot operate on the back side.

Is there a way to allow the transparent part to operate on the back even if the control is extended to the full form in Dock.Fill?

Thank you for your cooperation.

Enter a description of the image here

add

Today (November 15) I tried to recreate it from scratch again, but when I tried to run both BackColor and TransparencyKey in the same color, the background will continue, but I can't operate on the back side.

Until now, I felt that I could operate the back of the transparent part without any problems, but has the specification changed since it became the latest .Net?

Just in case, I will post the design code.

namespace WindowsFormsApp1
{
    partial class Form 1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components=null;

        /// <summary>
        /// Clean up all resources in use.
        /// </summary>
        /// <param name="disposing"> Specify true to discard managed resources, otherwise false.</param>
        protected override void disposition (bool disposition)
        {
            if(disposing&&(components!=null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for designer support.The content of this method is:
        /// Do not change in the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            This.SuspendLayout();
            // 
            // Form 1
            // 
            this.AutoScaleDimensions=new System.Drawing.SizeF (8F, 15F);
            this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
            This.BackColor=System.Drawing.Color.Red;
            this.BackgroundImage=global::WindowsFormsApp1.Properties.Resources.star;
            This.ClientSize=new System.Drawing.Size(800,450);
            This.Name="Form1";
            This.Text="Form1";
            This.TransparencyKey=System.Drawing.Color.Red;
            This.ResumeLayout(false);

        }

        #endregion
    }
}

c# form

2022-09-30 16:24

2 Answers

If you set the Region of the Form, the form will appear to have been truncated.

private void Form2_Shown (object sender, EventArgse)
        {
            GraphicsPath GraphicsPath=new GraphicsPath();
            graphicsPath.AddElipse(0,0,100,100);
            Region = new Region (graphicsPath);
        }

Generating a Region from Bitmap is
https://smdn.jp/programming/tips/create_region_from_bitmap/
You can refer to the .

Also, generating Region from a string is
https://qiita.com/Zuishin/items/0de2c21fbac5d0190c8b

by reference to
var graphicsPath=new GraphicsPath();
graphicsPath.AddString("★", new FontFamily("Mario"), 0, 50, new Point(0, 0), StringFormat.GeneralDefault);
Region = new Region (graphicsPath);

You can write .
If you don't change the shape of the form, you won't be able to operate it behind you even if you make it transparent.


2022-09-30 16:24

I will answer your most recent question by connecting your comments.
According to the English version of StackOverflow article below, there is a bug that has been around for quite a long time, and it seems that the R:red and B:blue values in the color information set to BackColor and TransparencyKey must be the same.
C#Form.TransparencyKey working different for different colors, why?

While I don't know what causes it, I can tell you that you can reach click through for 100% of colors where the red and blue channels are equal.For instance, Color.FromArgb (255, 61, 139, 61) will allow click through, but Color.FromArgb (255, 30, not)

I don't know what caused it, but I can tell you that the red and blue channels can achieve click-through with 100% of the same color.For example, Color.FromArgb (255, 61, 139, 61) allows click-through, but not Color.FromArgb (255, 10, 20, 30).

Thanks for your reply. I tested it and you're right. I can click through without Aero enabled. Now the funny thing is that I actually made use of this bug. I have one transparent window that I can't click through (so I can use OnMouseMove event with it) and second with other transparency key that I can click through (what is what I want). Now I know that without Aero or on XP it won't work... Fortunately it's for my personause only;).

Thank you for your reply.I tested that, you are right.You can click through without enabling Aero.What's interesting is that I actually used this bug.There are non-clickable transparent windows (you can use OnMouseMove events) and other clickable transparent keys (what you want).Now I know that Aero or XP won't work...fortunately it's for my personal use only ;)

Hehe, yeah, this bug has been around for a while. When they don't fix it, it becomes a feature making our lives pretty through.

Hehe, yes, this bug has been around for a while.When they don't fix it, it becomes a characteristic that makes our lives quite rough.

For example, the default SystemColors.Control in the form's BackColor can be mouse-transparent, but you may want to use that color in the display, so you can choose a color that you don't want to use or specify a number to customize.
SystemColors class
Color structure


2022-09-30 16:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.