適用于無(wú)邊框窗體,自定義標(biāo)題欄
普蘭店網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,普蘭店網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為普蘭店上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的普蘭店做網(wǎng)站的公司定做!
之前在網(wǎng)上找的,如http://www.cnblogs.com/yuxuan/archive/2010/09/25/1834346.html這篇博文,開始移動(dòng)時(shí)會(huì)瞬移幾個(gè)像素.....
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing;
- namespace EW.XIS.Common
- {
- /// <summary>
- /// <para>說(shuō)明:窗體拖動(dòng)類,通過(guò)這個(gè)類提供的方法實(shí)現(xiàn)窗體上任意控件可輔助拖動(dòng)窗體</para>
- /// </summary>
- public class DragFormClass
- {
- private static bool isMouseDown = false;
- private static Point mouseOffset;
- private static Form _form;
- /// <summary>
- /// 在窗體上增加拖拽事件
- /// </summary>
- /// <param name="control">控件對(duì)象</param>
- public static void bindControl(Control control)
- {
- //如果控件為空
- if (control == null)
- {
- return;
- }
- _form = control.FindForm();
- //增加鼠標(biāo)拖動(dòng)窗體移動(dòng)事件
- control.MouseMove += new MouseEventHandler(control_MouseMove);
- control.MouseDown += new MouseEventHandler(control_MouseDown);
- control.MouseUp += new MouseEventHandler(control_MouseUp);
- }
- /// <summary>
- /// 鼠標(biāo)按下之時(shí),保存鼠標(biāo)相對(duì)于窗體的位置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private static void control_MouseDown(object sender, MouseEventArgs e)
- {
- if (Control.MouseButtons == MouseButtons.Left)
- {
- Point p=_form.PointToClient(Control.MousePosition);
- mouseOffset = new Point(-p.X, -p.Y);
- isMouseDown = true;
- }
- }
- /// <summary>
- /// 移動(dòng)鼠標(biāo)的時(shí)候改變窗體位置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private static void control_MouseMove(object sender, MouseEventArgs e)
- {
- if (Control.MouseButtons == MouseButtons.Left)
- {
- if (isMouseDown)
- {
- Point mouse = Control.MousePosition;
- mouse.Offset(mouseOffset.X, mouseOffset.Y);
- _form.Location = new Point(mouse.X, mouse.Y);
- }
- }
- }
- /// <summary>
- /// 松開鼠標(biāo)的時(shí)候,重設(shè)事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private static void control_MouseUp(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- isMouseDown = false;
- }
- }
- }
- }
名稱欄目:通過(guò)控件拖動(dòng)窗體
地址分享:http://jinyejixie.com/article34/gpehpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、品牌網(wǎng)站制作、微信公眾號(hào)、軟件開發(fā)、域名注冊(cè)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)