怎样设置窗口全透明,而鼠标不穿透
1个回答
展开全部
环境:VS2008 .net2.0 C# winform
问题:程序需要实现在主窗口上显示子窗口,子窗口上显示电压值,要求背景完全透明但文字不透明,可以拖动改变位置和大小;现在已经基本实现了该功能,就是透明的部分会有鼠标穿透效果,导致点击到透明部分时无法拖动子窗口。请问这个效果该如何修改?
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//实现透明
label_U.BackColor = Color.White;
this.TransparencyKey = Color.White;
//移动窗口
private static void labelU_MouseDown(object sender, MouseEventArgs e)
{
FxWinApis.ReleaseCapture();
Control g = sender as Control;
if (g != null)
{
FxWinApis.SendMessage(this.Handle, FxWinApis.WM_SYSCOMMAND, FxWinApis.SC_MOVE + FxWinApis.HTCAPTION, 0);
}
}
//缩放窗口
private void FormShowVoltage_MouseDown(object sender, MouseEventArgs e)
{
this.Capture = false;
Form ff = new Form();
ff.StartPosition = FormStartPosition.Manual;
ff.Size = this.Size;
ff.Location = this.Location;
ff.SizeChanged += new EventHandler(ff_SizeChanged);
ff.LocationChanged += new EventHandler(ff_LocationChanged);
int pos = GetPostionAt(e.Location);
if (pos > 0)
{
SendMessage(ff.Handle, WM_SYSCOMMAND, SC_Size + pos, 0);//发送缩放消息
}
ff.Dispose();
}
问题:程序需要实现在主窗口上显示子窗口,子窗口上显示电压值,要求背景完全透明但文字不透明,可以拖动改变位置和大小;现在已经基本实现了该功能,就是透明的部分会有鼠标穿透效果,导致点击到透明部分时无法拖动子窗口。请问这个效果该如何修改?
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//实现透明
label_U.BackColor = Color.White;
this.TransparencyKey = Color.White;
//移动窗口
private static void labelU_MouseDown(object sender, MouseEventArgs e)
{
FxWinApis.ReleaseCapture();
Control g = sender as Control;
if (g != null)
{
FxWinApis.SendMessage(this.Handle, FxWinApis.WM_SYSCOMMAND, FxWinApis.SC_MOVE + FxWinApis.HTCAPTION, 0);
}
}
//缩放窗口
private void FormShowVoltage_MouseDown(object sender, MouseEventArgs e)
{
this.Capture = false;
Form ff = new Form();
ff.StartPosition = FormStartPosition.Manual;
ff.Size = this.Size;
ff.Location = this.Location;
ff.SizeChanged += new EventHandler(ff_SizeChanged);
ff.LocationChanged += new EventHandler(ff_LocationChanged);
int pos = GetPostionAt(e.Location);
if (pos > 0)
{
SendMessage(ff.Handle, WM_SYSCOMMAND, SC_Size + pos, 0);//发送缩放消息
}
ff.Dispose();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询