 |
|
 |
Note: Those handling the WM_NCHITTEST message with the WndProc method will have their form 'Context Menu' capability removed.
The method proposed in this article seems to be a better way even if the 'if condition' could be omitted. The Context Menu will still appear since the form cannot be dragged with the right click anyway.
if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); }
For those who prefer not to use Interop, here's another way to send that same message:
void Form_MouseDown(object sender, MouseEventArgs e) { Capture = false; Message msg = Message.Create(Handle, WM_NCLBUTTONDOWN, (IntPtr)HT_CAPTION, IntPtr.Zero); base.WndProc(ref msg); }
-> JockerSoft approach is also another solution even if I did not test it yet.
modified on Wednesday, August 5, 2009 10:34 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
can you help me about resizing form ?
i use this code :
this.Text = ""; this.ControlBox = false; this.FormBorderStyle = FormBorderStyle.Sizable;
But , there some problems !You app looks very profesionally. I need code similar you code . thanks , with best regards , Nematjon Rakhmanov
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
Both WPARAM and LPARAM are 8B on Windows x64 - therefore int is small and your program fail on such a system when using 64bit .NET framework. You should use IntPtr for wParam and lPARAM too.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
oppps actually i want to load my Next FORM in a diffierent way simply how could i send a variable value in current form to my next form in my desktop application
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
 |
You r owesome.. U had saved my life.
It is perfectly working.
Thanking you again
i want to add combobox and dtpicker into datagrid
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Insert your code in the mouse move event function and it will probably work fine with an additional double click event function 
See Microsoft MSDN.
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
how can i handle move compleated... MouseUp event did not fired after move compleated. Move & LocationCnanged events raises on every small location changes. i need to know when user release mouse button.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Did you find a solution to the problem of the MouseUp event not being triggered?
I capture the mouse, from my WPF ListView, but my MouseUp event is not called if I release the mouse button outside the listview. So I do not get the opportunity to call ReleaseMouseCapture.
I have tried using the AddHandler() with the last param set to TRUE for both MouseUp and PreviewMouseUp.
I have tried both MouseUp and PreviewMouseUp.
craigk
craigk
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, your article wasn't meant to solve this, but you might know the aneswer. I have to apps, one that is running, and my own. I'd like to move the window of the other app.
How to do it? I am sure that interop can help here.
CUIN Kaczy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Well, hi!
Sorry, was on Holiday - you might try to play with some Api Code. Try SetWindow... Or try SendMessage - so you may be will be able to set new window position...
Greets! FreewareFire
FreewareFire
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Nice article. I currently use yet another method to move a window without the titlebar and it doesn't use interop:
private Point distanceFormMouse; private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { switch (e.Button) { case MouseButtons.Left: distanceFormMouse = new Point(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y) ; mouseDown = true; break; } }
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Left) { this.Location = new Point(MousePosition.X - distanceFormMouse.X, MousePosition.Y - distanceFormMouse.Y); } } and it works well, but I have a problem: I have a form with this.FormBorderStyle = FormBorderStyle.None; and I would like to display the standard shortcut menu that usually pops up when the user right clicks on a application button in the taskbar (the one with Restore, Move, Size, Minimize, Maximize & Close buttons) How can I do this? Any suggestion is highly appreciated
It would be great to add some custom entries to the menu (as winamp does, see sceenshot) but maybe I'm asking too much.
It would be cool if you could update your article to include everything a dev must know when working with forms without the titlebar (move/resize/menu in taskbar/anything else)
Jocker
_______ JeniuS - the file Organizer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Well, of course i could, but i don't update due the simple reason: It would pass the Topic! Topic is "Move window/form without Titlebar in C#" - and that's it. All other would not fit to topic. There a other Topics explaining your problems - try searching or look at the Forums.
Greets
FreewareFire
FreewareFire
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
 |
It would pass the Topic! Topic is "Move window/form without Titlebar in C#" I wonder why you wrote this article since this problem is easy to solve and several solutions exist ranging from managed code to api calls. I think that an article that aim to be useful, should include something that solve non-trivial problems or problems that require a bit of research.
There a other Topics explaining your problem If you say so, I guess you have found one: can you give me a link? I've searched a lot on Usenet and on the Internet and found no solutions. I asked on a couple of forums but no luck. Thank you
_______ JeniuS - the file Organizer
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
 |
Here's a nother technique that gives you much more control. Trapping the WM_NCHITTEST windows message is the key solution here.
class PeriodPanel: Panel { private const int WM_NCHITTEST = 0x0084; private const int HTTOP = 0x000C; private const int HTBOTTOM = 0x000F; private const int HTCAPTION = 0x0002; private const int MOUSEAWARE_BORDERWIDTH = 4; // we can play with this
protected override void WndProc(ref Message m) { // Default behaviour base.WndProc(ref m); // Trap the message sent when the mouse is over the borders if(m.Msg == WM_NCHITTEST) { int pos = m.LParam.ToInt32(); short yPos = (short)(pos >> 16); short xPos = (short) pos; Point pt = this.PointToClient(new Point(xPos, yPos));
// over the bottom border? if(pt.Y > Height - MOUSEAWARE_BORDERWIDTH) { // HTBOTTOM to resize the panel using the bottom border m.Result = new IntPtr(HTBOTTOM); } else if(pt.Y < MOUSEAWARE_BORDERWIDTH) // over top border? { // HTTOP to resize the panel using the top border m.Result = new IntPtr(HTTOP); } ... and you can return HT_CAPTION to be able to drag the form no matter where the mouse is, over the form. You would have m.Result = new IntPtr(HTTOP) ... instead... } }
Hope this helps. Sorry for the format. A quick and dirty paste ! This is typical old windows programming by the way.
Richard B.
Richard
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
 |
Opps! last line of code should show... ... and you can return HTCAPTION to be able to drag the form no matter where the mouse is, over the form. You would have m.Result = new IntPtr(HTCAPTION ) ... instead... Ciau!
Richard
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |