如何创建拖动控件

如何创建拖动控件

本文介绍了如何创建拖动控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在使用Windows窗体,我想创建一个自定义控件,它有助于拖动border_less窗体和所有窗体放在Windows窗体上的控件。

i'm working on windows form, i want to create a custom control that helps to drag border_less windows form and all the control that is placed on windows Form.

就像windows窗体一样,有助于将窗体从一个位置拖动到其他位置。

just like windows form Border that helps to drag form from a position to Other.

推荐答案

感谢您在此发帖。

对于您的问题,我不确定是什么您想要的自定义控件。但是如果你想用gif做事,你可以试试下面的代码。

For your question, I am not sure what custom control you want. But if you want to do thing in gif you could try the code below.

这是代码。

//const and dll functions for moving form
		public const int WM_NCLBUTTONDOWN = 0xA1;
		public const int HT_CAPTION = 0x2;

		[DllImportAttribute ("user32.dll")]
		public static extern int SendMessage(IntPtr hWnd,
			int Msg, int wParam, int lParam);

		[DllImportAttribute ("user32.dll")]
		public static extern bool ReleaseCapture();

		//call functions to move the form in your form's MouseDown event
		private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left)
			{
				ReleaseCapture();
				SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
			}
		}

您可以从代码项目下载源代码。

You could download the source code from the code project.

https://www.codeproject.com/Articles/11114/Move-window-form-没有-Titlebar-in-C

最好的问候,

Wendy


这篇关于如何创建拖动控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:06