在C# WinForm中,边框不显示就会造成窗体无法拖动的情况,把下边的代码添加上去就可以解决。
1.导入命名空间
using System.Runtime.InteropServices;
2.输入如下代码
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private void pictureBox2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void pictureBox4_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
在窗体的MouseDown事件中编写如下代码
private void zcmmForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture(); SendMessage(Handle, 0xA1, 0x02, 0);
}
}
时间: 2024-12-20 14:48:11