 |
|
 |
Maybe somebody create winamp-like main window behavior (when I'm moving main window, other windows, that stick to main window, moves with it)?
|
|
|
|
 |
|
 |
Excellent article, extremely useful code, well done - you have my vote of '5'.
Also wanted to let you know (if you're not already aware) that there are some issues with forms that have their FormBorderStyle set to anything other than Sizable, at least on Win7 with Aero turned on.
Any 'Fixed' FormBorderStyle will cause the window borders to overlap slightly.
Additionally, borderless windows when using p/invoke SendMessage (as described here: Move window/form without Titlebar in C#[^]) to allow the user to drag the form causes the mouse to snap to the forms top left most position, rather than allow the user to drag the form from where they mouse downed. I believe the fix you posted on a previous commentors post partially addressed this (is was causing the form to relocate somewhere south and to the left prior to your suggestion).
|
|
|
|
 |
|
 |
Can any one help me to redo this work for VB dot net?
I have tried,I am in struggle to change the following code
DefaultMessageProcessor = new ProcessMessage ( DefaultMsgProcessor );
MoveMessageProcessor = new ProcessMessage ( MoveMsgProcessor );
ResizeMessageProcessor = new ProcessMessage ( ResizeMsgProcessor );
MessageProcessor = DefaultMessageProcessor;
Thanks,
Karthik.C
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I've been searching something like that long time, and now i've found your article.
Thanks a lot!
|
|
|
|
 |
|
 |
Hi,
Thanks. Is there’s a way to make MDI child forms sticky like that?
Thanks
gilvini
|
|
|
|
 |
|
|
 |
|
 |
Hi,
like the subject explains...
I have a two Forms, and they stick together as it should be.
As soon as I set the property "ShowInTaskbar" of one Form to false, the sticking doesn't work anymore.
What do I have to do to fix it?
|
|
|
|
 |
|
 |
Oh yeah, it's because the handle changes, when the window is banned from the taskbar.
So I used the HandleCreated-Event to create a new StickingWindow-Object with the current handle;)
|
|
|
|
 |
|
 |
Hello, your code works with a standard titlebar wonderful. But i would like to use my custom titlebar. After the click jumps the window to a another position. What am I doing wrong?
Codesniped:
private const int WM_NCLBUTTONDOWN = 0xA1;
private const int HTCAPTION = 0x2;
[ DllImport( "user32.dll" ) ]
public static extern bool ReleaseCapture();
[ DllImport( "user32.dll" ) ]
public static extern int SendMessage( IntPtr hWnd, int Msg, int wParam, int lParam );
private void panel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if ( e.Button == MouseButtons.Left )
{
ReleaseCapture();
SendMessage( Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0 );
}
}
Sorry for my English...
Mfg@Babybaer
|
|
|
|
 |
|
 |
OK i found the Problem.
SendMessage( Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0 );
In SendMessage is the LPARM = 0, but this will to calculate anew window position.
here the Solution:
Created the LPARM for the X and Y coordinates...
private int MakeLParam(int LoWord, int HiWord)
{
return (int) ((HiWord << 16) | (LoWord & 0xffff));
}
SendMessage with LPARM
private void MainForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, MakeLParam(((System.Windows.Forms.Form)(sender)).Location.X + e.Location.X, ((System.Windows.Forms.Form)(sender)).Location.Y + e.Location.Y));
}
}
Mfg@Babybaer
|
|
|
|
 |
|
 |
Do i need a child and parent window to use this..
How do i create a child and parent window.
I've been trying this for a few months but i do not have the funds to buy C# books to teach me.
Can you help me out with this?
|
|
|
|
 |
|
 |
Really great code workup,
I tried to implement it into my project. Bout an half an hour later, realized it wasn't working due to my mainForm being the parent to all the children.
Anyway of utilizing the stickiness to children that reference the mainform as their parent?
(ie: keep the children inside the clientrectangle of the parent)
|
|
|
|
 |
|
 |
I'm modifying this code to support move by parent -- its not quite as simple as some previous messages have suggested -- and am confused by:
protected override void OnHandleChange()
{
if ( (int)this.Handle != 0 )
{
GlobalStickyWindows.Add ( this.originalForm );
}
else
{
GlobalStickyWindows.Remove ( this.originalForm );
}
}
OnHandleChange() is pretty poorly documented. Can anyone explain to me what's going on here?
|
|
|
|
 |
|
 |
Hi,
I've created a borderless form and I'm using the following code to move it
private void mainForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
ReleaseCapture();
SendMessage(this.Handle, WM_NCLBUTTONDOWN, HTCAPTION, IntPtr.Zero);
}
}
When I clic on the form the form is moved and correctly attached to the borders of the screen but it's translated. I mean that when I start to move the mouse the form is no longer under the mousepointer. Any idea on how to fix this (removing the StickyWindow link everything works as expected).
Thanks.
|
|
|
|
 |
|
 |
Comment-out this line :
offsetPoint.Offset ( -rParent.Left, -rParent.Top );
in the OnNCLButtonDown method, eg:
private bool OnNCLButtonDown ( int iHitTest, Point point )
{
Rectangle rParent = originalForm.Bounds;
offsetPoint = point;
switch ( iHitTest )
{
case Win32.HT.HTCAPTION:
{ if ( stickOnMove )
{
StartMove();
return true;
...
|
|
|
|
 |
|
 |
I was wondering if its possible to have an StickyWindow implementation without listening for Windows Messages in the WndProc versus native control events such as mousemove etc? Just wanted to know why you chose to go with the windows message route?
thanks.
|
|
|
|
 |
|
 |
Good question.
I've implemented this code for the first time 2 years ago in C++.
And I know I had a good reason why I had to relay on window messages, but I can't remember exactly.
I think it was because using mousemove events you could sometime get in some strange behaviour when used in WinXP.
And btw, "native control events such as mousemove" are generated from WM_MOUSEMOVE events from inside the WndProc of the Control.
|
|
|
|
 |
|
 |
Hi. This will be very useful if I can get it to work.
The 02/09/2004 demo version was loaded into the latest .NET Vidual Studio framework and does not work. The project compiles and the main form is generated. The checkbox forms appear when you click the only button on the main from. But from that point forward, nothing happens. What am I doing incorrectly in the demo? What does one have to do to make the form windows stick to each other? Also, were some bugs reported since 02/09/2004 and is there a version with the fixes?
Thanks,
Harry
|
|
|
|
 |
|
 |
I'm trying your class and it is very good. I had one problem though. I notices that during the resizing and movement of the the form the client area is repainted very slowly and there's a lot of flickering. How can I avoid that? Thanks a lot and keep up with the good work.
Andrea
|
|
|
|
 |
|
 |
An easy way to avoid the flickering is to use the forms Opacity property. When creating a new form that uses the StickyWindow class, just set this new forms opacity to e.g. 0.99...
Example (from a version converted to VB.NET):
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
magneticWindow = New MagneticWindow(Me)
chkStickOnMove.Checked = magneticWindow.StickOnMove
chkStickOnResize.Checked = magneticWindow.StickOnResize
chkStickToOthers.Checked = magneticWindow.StickToOther
chkStickToScreen.Checked = magneticWindow.StickToScreen
Me.Opacity = 0.99
End Sub
|
|
|
|
 |
|
 |
Any hints on how to get Sticky Windows to work with MDI?
|
|
|
|
 |
|
 |
Have you tried them as they are? I think you should only set StickToScreen to false and it should work. I'll have a look and try to update the article asap.
Tutu.
|
|
|
|
 |
|
 |
Yes, I tried it as is with MDI windows but no luck.
|
|
|
|
 |