 |
|
 |
Hi... Thanks for code.. But I have to convert it into VB.NET, I did it... But after converting it dont works... Public Const WM_NCLBUTTONDOWN As Integer = &HA1 Public Const HT_CAPTION As Integer = &H2 <DllImportAttribute("user32.dll")> _ Public Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As Integer) As Integer End Function <DllImportAttribute("user32.dll")> _ Public Shared Function ReleaseCapture() As Boolean End Function 'call functions to move the form in your form's MouseDown event Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) If e.Button = MouseButtons.Left Then ReleaseCapture() SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0) End If End Sub I have tried to debug it but cursor dont move into Form1_MouseDown method... What to do ?
|
|
|
|
 |
|
 |
Hi, i've tried it out and it works... here's the full Sourcecode for VB.NET
Imports System.Runtime.InteropServices
Public Class Form1
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Const HT_CAPTION As Integer = &H2
<DllImportAttribute("user32.dll")> _
Public Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As Integer) As Integer
End Function
<DllImportAttribute("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
End Function
Private Sub Form1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
ReleaseCapture()
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0)
End If
End Sub
End Class
If i press the left Button and drag the Form, it moves...
FreewareFire is in the House!
|
|
|
|
 |
|
 |
Nice guy!!! Thank's for that.
|
|
|
|
 |
|
 |
There is an easier way.
if (m.Msg == WM_NCHITTEST)
m.Result = (System.IntPtr)HT_CAPTION;
|
|
|
|
 |
|
|
 |
|
 |
5 thumbs up
|
|
|
|
 |
|
 |
In WPF you just make a MouseLeftButtonDown="Mouse" event in xaml,
and in the C# code:
private void Mouse(object sender, RoutedEventArgs e)
{
this.DragMove();
}
|
|
|
|
 |
|
 |
This code is very easy to convert in vb N IMP...Its really working
|
|
|
|
 |
|
|
 |
|
 |
WPF Windows / Forms do not inherit the Control object, thus are not privy to the Control.Handle property.
So add this using statement:
using System.Windows.Interop;
Then replace this line:
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
With this one:
SendMessage(new WindowInteropHelper(this).Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
Works perfectly! Enjoy and thanks to the original poster.
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I am curious have anyone experimented with this. DirectShow + WM_NCLBUTTONDOWN small explanation: DirectShow creates child window (seams like deatached from its parent) in content window in which he is playing. Which results in intercepting all window messages of it. (no mouse move, no mouse down up, ...). Now above hack works altrough with one small problem. looks like when movie plays in DirectShow last mouse position remmembered is one before movie started, and as a result it has form jumping to reposition it self on last known mouse position. does anyone knows how can I avoid this behaviour ?
|
|
|
|
 |
|
 |
How can I do this with the MouseButton.Right instead of .Left?
|
|
|
|
 |
|
 |
Try changing Left to Right, eh?
In Christ,
Aaron Laws
http://ProCure.com
|
|
|
|
 |
|
|
 |
|
 |
need more explanation..
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
 |
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
|
|
|
|
 |
|
|
 |
|
 |
Its a great piece of code, in two very simple steps i could my form.
thank you!
|
|
|
|
 |
|
 |
5 from me. Next app will be add your code.
Dream it, Do it.
|
|
|
|
 |
|
 |
This is awesome man!!! you did me a big favor with this! Thank you!!!
|
|
|
|
 |
|
|
 |
|
 |
Great article, small and straight to the point! thanks!
|
|
|
|
 |