摘要
简单实现了一个这样的功能,程序启动时,窗口悬固定在右下角,并可以通过鼠标拖拽移动。
核心代码块
无边框窗口并不出现在任务栏
//无边框 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //不出现在任务栏 this.ShowInTaskbar = false;
置顶
this.TopMost = true;
拖拽移动无边框窗口
//全局窗口坐标 private Point _frmPoint; public MainFrm() { InitializeComponent(); this.TopMost = true; _frmPoint = new Point(); } private void MainFrm_Load(object sender, EventArgs e) { this.MouseDown += MainFrm_MouseDown; this.MouseMove += MainFrm_MouseMove; } void MainFrm_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point myPosittion = MousePosition; myPosittion.Offset(-_frmPoint.X, -_frmPoint.Y); Location = myPosittion; } } void MainFrm_MouseDown(object sender, MouseEventArgs e) { _frmPoint.X = e.X; _frmPoint.Y = e.Y; }
可实现类似杀毒软件悬浮的窗口。