[VB.NET] Form bewegen

09/10/2011 02:55 P00w#1
Hey Leute,
Ihr kennt ja wenn man FormBoderStyle auf "None" setzt
Das man die Form1 wenn sie gestartet ist nicht mehr hin und her schieben kann
Weil ja der Rahmen weg ist

Aber ich habe ein Code für euch damit ihr die Form dann noch immer "hin und her" schieben könnt.
(Jeder der sich gut mit VB auskennt kann das ja eh aber das ist jetzt für die Leute die es noch nicht so gut können)

Code:
    Private Sub Sticky_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Capture = False
            Const WM_NCLBUTTONDOWN As Integer = &HA1S
            Const HTCAPTION As Integer = 2
            Dim msg As Message = Message.Create(Me.Handle, WM_NCLBUTTONDOWN, New IntPtr(HTCAPTION), IntPtr.Zero)
            Me.WndProc(msg)
        End If
    End Sub
09/10/2011 18:10 .KeRo#2
Ty klappt ganz gut ;)
09/10/2011 21:10 .SkyneT.#3
Bekommst ein Thx, hab früher mal ne Zeit lang nach sowas gesucht, dann
hab ichs aber doch noch selber hinbekommen...

(Nur war mein Code viel länger und die einzigen Sachen die gleich sind wie hier
sind :
Code:
    Private Sub Sticky_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
09/10/2011 21:52 P00w#4
Es gibt einige möglichkeiten es zu machen
09/18/2011 17:48 Kraizy​#5
Quote:
Originally Posted by -_HackGamer View Post
Nice das hat keiner gefunden kriegst ein thanks
gefunden?^^
09/19/2011 07:22 P00w#6
er hats schon editiert^^

Er meinte wohl was anderes
10/17/2011 16:54 Benhero#7
Gibt es auch eine Möglichkeit die Form über ein Element. In meinem Fall ein Bild zu bewegen? Also ich klicke bild an und bewege die maus und form bewegt sich mit?

Wäre nett wenn jemand ne idee hat wies geht :D

Mfg. Benhero
10/17/2011 17:47 Demon-777#8
@Benhero: Let just say you want to use it with a picturebox. So declare an MouseDown event for you picturebox and write following code in there:

Code:
private void samplePicBox_MouseDown(object sender, MouseEventArgs e)
{
    const int WmNclButtonDown = 0xA1;
    const int HtCaption = 0x2;

    if (e.Button == MouseButtons.Left)
    {
        ReleaseCapture();
        SendMessage(this.Handle, WmNclButtonDown, HtCaption, 0);
    }
}
but you should also add System.Runtime.InteropServices class to your imports and declare 2 winapi functions.

Code:
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr handle, int message, int wParam, int lParam);

[DllImportAttribute("user32.dll")] 
public static extern bool ReleaseCapture();
well it's in C# but I hope you are smart enough to rewrite it with VB.NET or at least use code translator (look at google).
10/17/2011 18:27 Benhero#9
i´ve just startet with Vb.NET... so i can´t translate it.. and the most Online Translater i hate :D....
But thank you very mutch..

Code:
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr handle, int message, int wParam, int lParam);

[DllImportAttribute("user32.dll")] 
public static extern bool ReleaseCapture();
Must be
Code:
Import System
Or?

Mfg.
10/17/2011 18:30 Kraizy​#10
Aus dem Kopf, muss nicht richtig übersetzt sein:
PHP Code:
Private Sub samplePicBox_MouseDown(sender As ObjectAs MouseEventArgsHandles samplePicBox.MouseDown
     
Const WmNclButtonDown As Integer = &HA1
     
Const HtCaption As Integer = &H2

     
If e.Button MouseButtons.Left Then
          ReleaseCapture
()
          
SendMessage(samplePicBox.HandleWmNclButtonDownHtCaption0)
     
End If
End Sub 
Ansonsten: [Only registered and activated users can see links. Click Here To Register...]
10/17/2011 19:11 Benhero#11
geht leider nicht.
Code:
ReleaseCapture
SendMessage
Nicht Deklariert..

Mfg.
10/17/2011 19:15 Kraizy​#12
Quote:
Originally Posted by Benhero View Post
geht leider nicht.
Code:
ReleaseCapture
SendMessage
Nicht Deklariert..

Mfg.
Bitte Grundlagen lernen..
Diese musste ja auch erstmal deklarieren.
Post von Demon-777:
Quote:
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr handle, int message, int wParam, int lParam);

[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
Benutz die Seite, die ich dir gegeben habe und lass es nach VB.NET übersetzen.
10/17/2011 19:23 Benhero#13
Problem soweit gelöst...

Weiteres Problem.. Er verschiebt zwar das Bild. Aber die Form nicht mit :/
Ist dies irgendwie möglich?

Mfg.

##### EDIT
Code:
Imports System.Runtime.InteropServices
war erforderlich &
Code:
SendMessage(PictureBox1.Handle, WmNclButtonDown, HtCaption, 0)
Durch:
Code:
 SendMessage(Me.Handle, WmNclButtonDown, HtCaption, 0)
ersetzen :D Danke für eure Hilfe!!!
10/17/2011 19:53 Kraizy​#14
Achso, dachte du willst die PicBox bewegen, und nicht über diese die komplette Form. Naja dann ist ja logisch, dass du das Handle der Form selbst nehmen musst.^^
07/26/2012 03:37 Sedrika#15
Ist zwar etwas her aber das hier ist die beste Methode find ich:
PHP Code:
    Private ptMouseDownLocation As Point
    
Private Sub f_MouseDown(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgsHandles Me.MouseDown
        
If e.Button Windows.Forms.MouseButtons.Left Then
            ptMouseDownLocation 
e.Location
        End 
If
    
End Sub
    
Private Sub f_MouseMove(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgsHandles Me.MouseMove
        
If e.Button Windows.Forms.MouseButtons.Left Then
            Me
.Location e.Location ptMouseDownLocation Me.Location
        End 
If
    
End Sub