我试图在winForm中用C#创建一个程序,其中一个图像将跟随应用程序外部的鼠标。
我不知道如何在表单之外画一幅图像,更不用说让它跟随鼠标。我的解决方案是-创建一个无边界的表单,并让它跟随鼠标-但这个解决方案将无法工作,因为我不能通过代码移动一个表单。
鼠标需要能够独立于此图像单击和工作。
我该怎么做呢?
发布于 2014-11-27 06:53:48
它必须在不改变鼠标使用方式的情况下这样做。
为扩展样式设置WS_EX_TRANSPARENT,使窗体忽略鼠标单击。将TopMost设置为真,将不透明度设置为小于100%,以使其半透明.用计时器移动表单。类似于:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Opacity = .5;
this.TopMost = true;
this.BackColor = Color.Yellow;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
// Makes the form circular:
System.Drawing.Drawing2D.GraphicsPath GP = new System.Drawing.Drawing2D.GraphicsPath();
GP.AddEllipse(this.ClientRectangle);
this.Region = new Region(GP);
}
const int WS_EX_TRANSPARENT = 0x20;
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = cp.ExStyle | WS_EX_TRANSPARENT;
return cp;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
Point pt = Cursor.Position;
pt.Offset(-1 * this.Width / 2, -1 * this.Height / 2);
this.Location = pt;
}
}发布于 2014-11-27 05:17:15
https://stackoverflow.com/questions/27163478
复制相似问题