如何在C#中使桌面上的移动成为无边界形式? [英] How to make moveable on the desktop a borderless form in c#?

查看:56
本文介绍了如何在C#中使桌面上的移动成为无边界形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够用鼠标在c#中移动没有边框和标题栏的表单.

I want to be able to move with the mouse a form without border and title bar in c#.

我查看了youtube,但找不到任何有效的方法.

I looked over youtube but i can't find anything that is working.

有人可以帮助我吗?

推荐答案

您可以将窗体的MouseDown,Up和Move事件与条件变量一起使用,例如:

You can use the form's MouseDown, Up and Move events with a conditional variable like that:

private bool IsMoving;
private Point LastCursorPosition;

private void FormTest_MouseDown(object sender, MouseEventArgs e)
{
  IsMoving = true;
  LastCursorPosition = Cursor.Position;
}

private void FormTest_MouseUp(object sender, MouseEventArgs e)
{
  IsMoving = false;
}

private void FormTest_MouseMove(object sender, MouseEventArgs e)
{
  if ( IsMoving )
  {
    int x = Left - ( LastCursorPosition.X - Cursor.Position.X );
    int y = Top - ( LastCursorPosition.Y - Cursor.Position.Y );
    Location = new Point(x, y);
    LastCursorPosition = Cursor.Position;
  }
}

它与表单的背景一起使用,但是您也可以将其添加到任何其他控件中.

It works with the background of the form but you can add this to any other control too.

这篇关于如何在C#中使桌面上的移动成为无边界形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆