问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;usingRightMenuItem;namespaceClientFrom{publicpartialclassForm12:Form{privateconstintWM_SYSCOMMAND=0x0112;//点击窗口左上角那个图标时的系统信息privateconstintWM_NCHITTEST=0x0084;privateconstintWM_NCMBUTTONDOWN=0x00A7;privateconstintWS_SYSMENU=0x00080000;//系统菜单privateconstintWS_MINIMIZEBOX=0x20000;//最大最小化按钮privateconstintSC_MAXIMIZE=0xF030;//最大化信息privateconstintSC_MINIMIZE=0xF020;//最小化信息privateconstintGWL_WNDPROC=-4;privatestaticintLEFT=2,RIGHT=2,BOTTOM=2,TOP=2,TITLE_WIDTH=16;//边框和标题栏的大小privateintm_BorderWidth=4;privateintm_CaptionHeight=22;[DllImport("user32.dll",EntryPoint="GetWindowLong",CharSet=CharSet.Auto)]publicstaticexternintGetWindowLong(HandleRefhWnd,intnIndex);[DllImport("user32.dll",EntryPoint="SetWindowLong",CharSet=CharSet.Auto)]publicstaticexternIntPtrSetWindowLong(HandleRefhWnd,intnIndex,intdwNewLong);[DllImport("user32.dll")]privatestaticexternintGetSystemMenu(inthwnd,intbRevert);[DllImport("user32.dll")]privatestaticexternintAppendMenu(inthMenu,intFlagsw,intIDNewItem,stringlpNewItem);publicForm12(){InitializeComponent();//SetWindowLong(newHandleRef(this,this.Handle),-16,GetWindowLong(newHandleRef(this,this.Handle),-16)|WS_SYSMENU);//这里加上这段后下面的caseWM_NCHITTEST:就没反应了请问这儿怎么写}#regionWndProcprotectedoverridevoidWndProc(refMessagem){base.WndProc(refm);HandleRefhr=newHandleRef(this,m.HWnd);switch(m.Msg){caseWM_SYSCOMMAND:if(m.WParam==(IntPtr)SC_MAXIMIZE){m.WParam=(IntPtr)SC_MINIMIZE;}break;caseWM_NCHITTEST:if(m.Result==(IntPtr)HitTest.HTCLIENT){m.HWnd=this.Handle;Rectanglerect=this.Bounds;PointvPoint=newPoint((int)m.LParam&0xFFFF,(int)m.LParam>>16&0xFFFF);vPoint=PointToClient(vPoint);if(vPoint.X<=LEFT){if(vPoint.Y<=TOP){m.Result=(IntPtr)HitTest.HTTOPLEFT;}elseif(vPoint.Y>=ClientSize.Height-BOTTOM){m.Result=(IntPtr)HitTest.HTBOTTOMLEFT;}else{m.Result=(IntPtr)HitTest.HTLEFT;}}elseif(vPoint.X>=ClientSize.Width-RIGHT){if(vPoint.Y<=TOP){m.Result=(IntPtr)HitTest.HTTOPRIGHT;}elseif(vPoint.Y>=ClientSize.Height-BOTTOM){m.Result=(IntPtr)HitTest.HTBOTTOMRIGHT;}else{m.Result=(IntPtr)HitTest.HTRIGHT;}}elseif(vPoint.Y<=TOP){m.Result=(IntPtr)HitTest.HTTOP;}elseif(vPoint.Y>=ClientSize.Height-BOTTOM){m.Result=(IntPtr)HitTest.HTBOTTOM;}elseif(vPoint.Y>TITLE_WIDTH){m.Result=(IntPtr)HitTest.HTCAPTION;}}break;}}#endregion///<summary>///枚举鼠标拖动///</summary>publicenumHitTest:int{HTERROR=-2,HTTRANSPARENT=-1,HTNOWHERE=0,HTCLIENT=1,HTCAPTION=2,HTSYSMENU=3,HTGROWBOX=4,HTSIZE=HTGROWBOX,HTMENU=5,HTHSCROLL=6,HTVSCROLL=7,HTMINBUTTON=8,HTMAXBUTTON=9,HTLEFT=10,HTRIGHT=11,HTTOP=12,HTTOPLEFT=13,HTTOPRIGHT=14,HTBOTTOM=15,HTBOTTOMLEFT=16,HTBOTTOMRIGHT=17,HTBORDER=18,HTREDUCE=HTMINBUTTON,HTZOOM=HTMAXBUTTON,HTSIZEFIRST=HTLEFT,HTSIZELAST=HTBOTTOMRIGHT,HTOBJECT=19,HTCLOSE=20,HTHELP=21}}}
解决方案
解决方案二:
哎,粘了这么长的代码,不知道什么意思~!接分
解决方案三:
代码有点长了!你加点描述就好了!
解决方案四:
//SetWindowLong(newHandleRef(this,this.Handle),-16,GetWindowLong(newHandleRef(this,this.Handle),-16)|WS_SYSMENU);//这里加上这段后下面的caseWM_NCHITTEST:就没反应了请问这儿怎么写这段有问题
解决方案五:
[DllImport("user32.dll")]publicstaticexternboolReleaseCapture();[DllImport("user32.dll")]publicstaticexternboolSendMessage(IntPtrhwnd,intwMsg,intwParam,intlParam);publicconstintWM_SYSCOMMAND=0x0112;publicconstintSC_MOVE=0xF010;publicconstintHTCAPTION=0x0002;privatevoidbutton1_MouseDown(objectsender,MouseEventArgse){ReleaseCapture();SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0);}
这是无边框拖动
解决方案六:
发的东西很好很完整放到VS2008里新建一个窗体就行了就能看到是什么意思就是//SetWindowLong(newHandleRef(this,this.Handle),-16,GetWindowLong(newHandleRef(this,this.Handle),-16)|WS_SYSMENU);//这里加上这段后下面的caseWM_NCHITTEST:就没反应了请问这儿怎么写这段有问题把注释去掉就不能响应caseWM_NCHITTEST:的功能了
解决方案七:
hhc123你的我试过了不好用privatevoidForm12_MouseDown(objectsender,MouseEventArgse){ReleaseCapture();SendMessage(this.Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0);}
解决方案八:
接分,接分,接分,接分,
解决方案九:
解决方案十:
学习。。。
解决方案十一:
有没有牛人可以解决这个问题啊?急!!!呵呵~
解决方案十二:
同求答案。。加上任务栏左右键功能后不能改变大小,可以改变大小的时候却不能使用任务栏左右键功能。。