Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 透明,点击表单,但可以按标题栏移动_C#_Winforms - Fatal编程技术网

C# 透明,点击表单,但可以按标题栏移动

C# 透明,点击表单,但可以按标题栏移动,c#,winforms,C#,Winforms,我选择了一些代码,通过代码实现了一个最顶层、透明和点击式表单: public enum GWL { ExStyle = -20 } public enum WS_EX { Transparent = 0x20, Layered = 0x80000 } public enum LWA { ColorKey = 0x1, Alpha = 0x2 } [DllImport("user32.dll", EntryPoint = "GetWindowLong"

我选择了一些代码,通过代码实现了一个最顶层、透明和点击式表单:

public enum GWL
{
    ExStyle = -20
}

public enum WS_EX
{
    Transparent = 0x20,
    Layered = 0x80000
}

public enum LWA
{
    ColorKey = 0x1,
    Alpha = 0x2
}

[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr hWnd, GWL nIndex);

[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, int dwNewLong);

[DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, LWA dwFlags);

protected override void OnShown(EventArgs e)
{
    base.OnShown(e);
    int wl = GetWindowLong(this.Handle, GWL.ExStyle);
    wl = wl | 0x80000 | 0x20;
    SetWindowLong(this.Handle, GWL.ExStyle, wl);
    SetLayeredWindowAttributes(this.Handle, 0, 128, LWA.Alpha);
}
这里的问题,所有的表单都是不能点击它(原因是点击代码),如何做点击表单,但除了标题栏(用户可以点击标题栏将表单移动到其他位置)

我有一个方法,这段代码可以解决我的问题(尽管点击),但表单中的文本并没有不透明性,标题栏也并没有不透明性

this.BackColor = Color.Magenta;
  this.TransparencyKey = Color.Magenta;

图像例如表单在这里是什么意思…但表单中的文本并没有它的不透明度,标题栏也并没有不透明度?您不能单击不可见的内容!对不起,我的英语不好,我的意思是文本和标题栏的不透明度为1,我希望文本和标题栏的不透明度为0.5,第二个代码集
opacity
(在属性中)为您的表单
50%
谢谢,但是表单中的文本不能点击