-1

I wanna make simple form application with FormBorderStyle set to None, but the problem is I cant move this form, its just.. static? I wanna make something like this: http://i.imgur.com/TlQCWJx.png

Any ideas how to fix it?

fur
  • 1
  • 1
  • 3

3 Answers3

1

You can use code like this to make the form draggable:

Public Class Form1

    Private Const HTCLIENT As Integer = &H1
    Private Const HTCAPTION As Integer = &H2
    Private Const WM_NCHITTEST As Integer = &H84

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        MyBase.WndProc(m)

        If m.Msg = WM_NCHITTEST AndAlso m.Result = HTCLIENT Then
            m.Result = HTCAPTION
        End If
    End Sub

End Class
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
0

You could take a look at WPF. It's a newer version of WinForms and you have much more possibilities to design your dialogs.

But it's also very different to WinForms. You will need time to find into WPF.

Microsoft Docs about WPF

Nik Bo
  • 1,410
  • 2
  • 17
  • 29
0

Here's a very simple example of moving a borderless form to get you started:

Add a panel to your form, name it pnlTopBorder and dock it to the top. When you mousedown on the panel, capture the mouse position. When you mousemove on the panel, if the left button is pressed, then you calculate and set the new form position.

Public Class Form1

    Private newpoint As System.Drawing.Point
    Private xpos1 As Integer
    Private ypos1 As Integer

    Private Sub pnlTopBorder_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles pnlTopBorder.MouseDown
        xpos1 = Control.MousePosition.X - Me.Location.X
        ypos1 = Control.MousePosition.Y - Me.Location.Y
    End Sub

    Private Sub pnlTopBorder_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles pnlTopBorder.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            newpoint = Control.MousePosition
            newpoint.X -= (xpos1)
            newpoint.Y -= (ypos1)
            Me.Location = newpoint
        End If
    End Sub

End Class

If you want the window title and form controls, you'll have to draw them in the Paint event and handle all the events to get them to work. It's all doable, but it's just more complex.

Chase Rocker
  • 1,908
  • 2
  • 13
  • 14