c#可移动不规则窗体
关键代码:
设置窗体的FormBorderStyle为None,和TransparencyKey为Fuchsia(为图片背景色)必须和图片背景色一样。 是代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Point mouse_offset; private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { Point mousepos = Control.MousePosition; mousepos.Offset(mouse_offset.X,mouse_offset.Y); Location = mousepos; } } private void Form1_MouseDown(object sender, MouseEventArgs e) { mouse_offset = new Point(-e.X,-e.Y); } } }