Hack Forums
[.NET] Question about moving a themed borderless form - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Question about moving a themed borderless form (/showthread.php?tid=4634715)



Question about moving a themed borderless form - DigiDeveloper - Jan 13, 2015

Hello, Thanks for checking out the thread , and hopefully someone can point me in the right direction....

Ok I have a form that I need to drag and the form im using i have themed.... so i try using the following code with no success.....

Code
Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer

    Private Sub PositronTheme2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End Sub
    Private Sub PositronTheme2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If drag Then
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
        End If
    End Sub



* - Odus - Jan 13, 2015

I've just tested it on Positron theme, it moves fine. But to answer your question:

Declare the following:
Code
Private cX, cY As Integer
Private Dragging As Boolean = False

MouseDown event:
Code
Dragging = True
cX = e.X
cY = e.Y

MouseMove event:
Code
If Dragging Then
      Me.Top = Me.Top + (e.Y - cY)
      Me.Left = Me.Left + (e.X - cX)
End If

MouseUp event:
Code
Dragging = False



* - Hawk HF - Jan 13, 2015

You'll want to make changes directly to the PositronTheme class. Otherwise you'll be using repetitive code over all of your themed forms.

I've coded up a simple form skin for you. Take these concepts and apply them to Pat Positron's theme.

http://pastebin.com/BYbeSvQ3

Enjoy. 🤝


* - Only3 - Jan 13, 2015

https://hackforums.net/showthread.php?tid=4558018


* - DigiDeveloper - Jan 13, 2015

Thanks Guys .... appreciate the quick replies! :D