Just a little comment. The WM_NCHITTEST solution is ok, but I don't think it prevents the user from using other means of moving the window, i.e. by cascading or tiling windows.
Regards Henrik > -----Original Message----- > From: Ian Griffiths [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, May 07, 2002 3:49 PM > To: [EMAIL PROTECTED] > Subject: Re: prohibit window from moving by mouse > > > Is removing the title bar an option? You could set the > FormBorderStyle to none. Users will then have difficulty > moving your window. The problem then of course is that your > window will not have a normal title bar... > > Unfortunately, if you leave the title bar present, it looks > like Windows Forms provides no hooks to intercept the > resizing or moving behaviour. There is a pretty barf-worthy > solution which involves hooking the WndProc. Rama Krishna > beat me to it with an WM_NCHITTEST solution. My solution was > less nice, since it involved some unsafe code. In case > you're interested, here it is: > > > [StructLayout(LayoutKind.Sequential)] > struct WINDOWPOS { > public IntPtr hwnd; > public IntPtr hwndInsertAfter; > public int x; > public int y; > public int cx; > public int cy; > public uint flags; > } > protected override void WndProc(ref > System.Windows.Forms.Message m) { > // WM_WINDOWPOSMOVING > if (m.Msg == 0x46) { > unsafe { > // Force window position and size to > // remain the same > WINDOWPOS* wp = > (WINDOWPOS*) m.LParam.ToPointer(); > wp->x = Location.X; > wp->y = Location.Y; > wp->cx = Size.Width; > wp->cy = Size.Height; > } > return; > } > base.WndProc(ref m); > } > > As you can see, this requies unsafe code. I usually avoid > doing anything with the WndProc, so there may be a way of > doing this that I'm unaware of. > > But Rama Krishna's solution doesn't require any unsafe code - > he processes a message that doesn't need pointers to > structures to be retrieved. So I would go with his code. > (Ideally there would be a native .NET way of doing this, but > I don't think there is.) > > > Someone else suggested double buffering, which I don't think > will help here. Whilst this is a good solution for avoiding > flicker within your own window, I don't think it will help in > avoiding flicker caused by the motion of your window. (Your > window never actually gets redrawn when it is dragged, its > contents are merely moved.) > > > -- > Ian Griffiths > DevelopMentor > > ----- Original Message ----- > From: "Alois Reisinger" <[EMAIL PROTECTED]> > > > Hi everyone, > > I have a form that is programmatically attached to my glue i > a way like you can see below. This works fine. The glued > window moves along with the "parent" one. But what i try to > move the glued window itself with the mouse, it produces some > awful flicker, although it stayes at its place. > > So how can i prevent this? > > Best regards > alois > > --snip > // Don�t worry about initialization of some variables.... > // it�s just a snippet > > public Constructor() > { > LocationChanged += new System.EventHandler(this.LocChange); > Resize += new System.EventHandler(this.LocChange); > gluedwindow.Resize += new System.EventHandler(this.LocChange); > gluedwindow.LocationChanged += new > System.EventHandler(this.LocChange); > } > > [...] > > private void LocChange(object sender,System.EventArgs e) > { > if (gluedwindow!=null) > { > gluedwindow.Left = this.Right + 1; > gluedwindow.Top = this.Top; > System.Drawing.Size gs = gluedwindow.Size; > gs.Height = this.Size.Height; > gluedwindow.Size = gs; > } > } > ---snap > > You can read messages from the DOTNET archive, unsubscribe > from DOTNET, or subscribe to other DevelopMentor lists at > http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.
