Possibility to drag a form with the mouse when its title bar has been hidden

Asked

Viewed 254 times

-1

inserir a descrição da imagem aqui

I have a problem! When I try to move my program to some other place on the screen, I can’t, it seems to be fixed. Does anyone know how to solve?

@PS: I tried this code provided by Roberto and it didn’t work.

Public Class Form1
Private WM_NCHITTEST As Integer = &H84
Private HTCLIENT As Integer = &H1
Private HTCAPTION As Integer = &H2

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

    Select Case m.Msg
        Case WM_NCHITTEST
            If m.Result = New IntPtr(HTCLIENT) Then
                m.Result = New IntPtr(HTCAPTION)
            End If
    End Select

The title bar of the form has been removed so that a custom design is used in its place so that the drag form feature by clicking on its title bar has been lost.

Code Form1.Designer.Vb :

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.header = New System.Windows.Forms.Panel
        Me.PictureBox10 = New System.Windows.Forms.PictureBox
        Me.PictureBox8 = New System.Windows.Forms.PictureBox
        Me.PictureBox3 = New System.Windows.Forms.PictureBox
        Me.body = New System.Windows.Forms.Panel
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.PictureBox9 = New System.Windows.Forms.PictureBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.PictureBox7 = New System.Windows.Forms.PictureBox
        Me.PictureBox6 = New System.Windows.Forms.PictureBox
        Me.PictureBox5 = New System.Windows.Forms.PictureBox
        Me.PictureBox4 = New System.Windows.Forms.PictureBox
        Me.PictureBox2 = New System.Windows.Forms.PictureBox
        Me.bemvindo = New System.Windows.Forms.Label
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider(Me.components)
        Me.Label8 = New System.Windows.Forms.Label
        Me.header.SuspendLayout()
        CType(Me.PictureBox10, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox8, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox3, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.body.SuspendLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox9, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox7, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox6, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox5, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox4, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'header
        '
        Me.header.BackColor = System.Drawing.Color.FromArgb(CType(CType(51, Byte), Integer), CType(CType(153, Byte), Integer), CType(CType(204, Byte), Integer))
        Me.header.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.header.Controls.Add(Me.PictureBox10)
        Me.header.Controls.Add(Me.PictureBox8)
        Me.header.Controls.Add(Me.PictureBox3)
        Me.header.Dock = System.Windows.Forms.DockStyle.Top
        Me.header.Location = New System.Drawing.Point(0, 0)
        Me.header.Name = "header"
        Me.header.Size = New System.Drawing.Size(575, 46)
        Me.header.TabIndex = 0
        '
        'PictureBox10
        '
        Me.PictureBox10.Image = Global.AssistenteFdF.My.Resources.Resources.hruonXC
        Me.PictureBox10.Location = New System.Drawing.Point(506, 3)
        Me.PictureBox10.Name = "PictureBox10"
        Me.PictureBox10.Size = New System.Drawing.Size(34, 35)
        Me.PictureBox10.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox10.TabIndex = 2
        Me.PictureBox10.TabStop = False
        '
        'PictureBox8
        '
        Me.PictureBox8.Image = Global.AssistenteFdF.My.Resources.Resources.vdc7y0T
        Me.PictureBox8.Location = New System.Drawing.Point(532, 4)
        Me.PictureBox8.Name = "PictureBox8"
        Me.PictureBox8.Size = New System.Drawing.Size(34, 35)
        Me.PictureBox8.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox8.TabIndex = 1
        Me.PictureBox8.TabStop = False
        '
        'PictureBox3
        '
        Me.PictureBox3.Image = Global.AssistenteFdF.My.Resources.Resources.INS1aq9
        Me.PictureBox3.Location = New System.Drawing.Point(11, 8)
        Me.PictureBox3.Name = "PictureBox3"
        Me.PictureBox3.Size = New System.Drawing.Size(316, 34)
        Me.PictureBox3.TabIndex = 0
        Me.PictureBox3.TabStop = False
        '
        'body
        '
        Me.body.BackColor = System.Drawing.Color.White
        Me.body.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.body.Controls.Add(Me.Label8)
        Me.body.Controls.Add(Me.PictureBox1)
        Me.body.Controls.Add(Me.Label7)
        Me.body.Controls.Add(Me.Label6)
        Me.body.Controls.Add(Me.PictureBox9)
        Me.body.Controls.Add(Me.Label5)
        Me.body.Controls.Add(Me.Label4)
        Me.body.Controls.Add(Me.Label3)
        Me.body.Controls.Add(Me.Label2)
        Me.body.Controls.Add(Me.Label1)
        Me.body.Controls.Add(Me.PictureBox7)
        Me.body.Controls.Add(Me.PictureBox6)
        Me.body.Controls.Add(Me.PictureBox5)
        Me.body.Controls.Add(Me.PictureBox4)
        Me.body.Controls.Add(Me.PictureBox2)
        Me.body.Controls.Add(Me.bemvindo)
        Me.body.Dock = System.Windows.Forms.DockStyle.Fill
        Me.body.Location = New System.Drawing.Point(0, 46)
        Me.body.Name = "body"
        Me.body.Size = New System.Drawing.Size(575, 311)
        Me.body.TabIndex = 1
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = Global.AssistenteFdF.My.Resources.Resources.sl6Iv9x
        Me.PictureBox1.Location = New System.Drawing.Point(408, 207)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(158, 100)
        Me.PictureBox1.TabIndex = 15
        Me.PictureBox1.TabStop = False
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.Font = New System.Drawing.Font("Arial Narrow", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.Location = New System.Drawing.Point(2, 274)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(355, 20)
        Me.Label7.TabIndex = 14
        Me.Label7.Text = "Desenvolvido pela equipe de suporte Forumeiros © 2015" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10)
        '
        'Label6
        '
        Me.Label6.AutoSize = True
        Me.Label6.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.Location = New System.Drawing.Point(437, 145)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(71, 28)
        Me.Label6.TabIndex = 13
        Me.Label6.Text = "Mensagens" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "pré-definidas"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'PictureBox9
        '
        Me.PictureBox9.Image = Global.AssistenteFdF.My.Resources.Resources.Done2
        Me.PictureBox9.Location = New System.Drawing.Point(447, 81)
        Me.PictureBox9.Name = "PictureBox9"
        Me.PictureBox9.Size = New System.Drawing.Size(57, 61)
        Me.PictureBox9.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox9.TabIndex = 12
        Me.PictureBox9.TabStop = False
        Me.ToolTip1.SetToolTip(Me.PictureBox9, "Mensagens pré-definidas")
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(377, 145)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(42, 28)
        Me.Label5.TabIndex = 11
        Me.Label5.Text = "Mover" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "tópicos"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(289, 145)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(67, 28)
        Me.Label4.TabIndex = 10
        Me.Label4.Text = "Visualizador" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "HTML"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(213, 145)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(65, 42)
        Me.Label3.TabIndex = 9
        Me.Label3.Text = "Perguntas e" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "respostas" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "frequentes"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(139, 145)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 28)
        Me.Label2.TabIndex = 8
        Me.Label2.Text = "MP de" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "advertência"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(59, 145)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(66, 28)
        Me.Label1.TabIndex = 7
        Me.Label1.Text = "Mensagens " & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "moderativas"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'PictureBox7
        '
        Me.ErrorProvider1.SetError(Me.PictureBox7, "[ERRO] Função indisponivel")
        Me.ErrorProvider1.SetIconAlignment(Me.PictureBox7, System.Windows.Forms.ErrorIconAlignment.BottomRight)
        Me.ErrorProvider1.SetIconPadding(Me.PictureBox7, -15)
        Me.PictureBox7.Image = Global.AssistenteFdF.My.Resources.Resources.folder_move_icon
        Me.PictureBox7.Location = New System.Drawing.Point(371, 81)
        Me.PictureBox7.Name = "PictureBox7"
        Me.PictureBox7.Size = New System.Drawing.Size(57, 61)
        Me.PictureBox7.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox7.TabIndex = 5
        Me.PictureBox7.TabStop = False
        Me.ToolTip1.SetToolTip(Me.PictureBox7, "Mover tópicos (função indisponível)")
        '
        'PictureBox6
        '
        Me.PictureBox6.Image = Global.AssistenteFdF.My.Resources.Resources.HTML_File_Extension
        Me.PictureBox6.Location = New System.Drawing.Point(294, 81)
        Me.PictureBox6.Name = "PictureBox6"
        Me.PictureBox6.Size = New System.Drawing.Size(57, 61)
        Me.PictureBox6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox6.TabIndex = 4
        Me.PictureBox6.TabStop = False
        Me.ToolTip1.SetToolTip(Me.PictureBox6, "Visualizador HTML")
        '
        'PictureBox5
        '
        Me.PictureBox5.Image = Global.AssistenteFdF.My.Resources.Resources.tez
        Me.PictureBox5.Location = New System.Drawing.Point(216, 81)
        Me.PictureBox5.Name = "PictureBox5"
        Me.PictureBox5.Size = New System.Drawing.Size(57, 61)
        Me.PictureBox5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox5.TabIndex = 3
        Me.PictureBox5.TabStop = False
        Me.ToolTip1.SetToolTip(Me.PictureBox5, "Perguntas e respostas frequentes")
        '
        'PictureBox4
        '
        Me.PictureBox4.Image = Global.AssistenteFdF.My.Resources.Resources.metroui_other_mail_icon
        Me.PictureBox4.Location = New System.Drawing.Point(142, 81)
        Me.PictureBox4.Name = "PictureBox4"
        Me.PictureBox4.Size = New System.Drawing.Size(57, 61)
        Me.PictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox4.TabIndex = 2
        Me.PictureBox4.TabStop = False
        Me.ToolTip1.SetToolTip(Me.PictureBox4, "Enviar MP de advertência")
        '
        'PictureBox2
        '
        Me.PictureBox2.BackColor = System.Drawing.Color.White
        Me.PictureBox2.Image = Global.AssistenteFdF.My.Resources.Resources.icon_help
        Me.PictureBox2.Location = New System.Drawing.Point(62, 81)
        Me.PictureBox2.Name = "PictureBox2"
        Me.PictureBox2.Size = New System.Drawing.Size(57, 61)
        Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox2.TabIndex = 1
        Me.PictureBox2.TabStop = False
        Me.ToolTip1.SetToolTip(Me.PictureBox2, "Mensagens moderativas")
        '
        'bemvindo
        '
        Me.bemvindo.AutoSize = True
        Me.bemvindo.Font = New System.Drawing.Font("Arial Narrow", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.bemvindo.Location = New System.Drawing.Point(32, 10)
        Me.bemvindo.Name = "bemvindo"
        Me.bemvindo.Size = New System.Drawing.Size(516, 23)
        Me.bemvindo.TabIndex = 0
        Me.bemvindo.Text = "Bem-vindo ao assistente de moderação do fórum de suporte Forumeiros!" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10)
        '
        'ToolTip1
        '
        Me.ToolTip1.AutomaticDelay = 0
        Me.ToolTip1.AutoPopDelay = 5000
        Me.ToolTip1.BackColor = System.Drawing.SystemColors.ControlText
        Me.ToolTip1.ForeColor = System.Drawing.SystemColors.Control
        Me.ToolTip1.InitialDelay = 0
        Me.ToolTip1.IsBalloon = True
        Me.ToolTip1.ReshowDelay = 100
        Me.ToolTip1.UseAnimation = False
        Me.ToolTip1.UseFading = False
        '
        'ErrorProvider1
        '
        Me.ErrorProvider1.ContainerControl = Me
        '
        'Label8
        '
        Me.Label8.AutoSize = True
        Me.Label8.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label8.Location = New System.Drawing.Point(3, 294)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(131, 14)
        Me.Label8.TabIndex = 16
        Me.Label8.Text = "Verificar por atualizações" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10)
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(575, 357)
        Me.Controls.Add(Me.body)
        Me.Controls.Add(Me.header)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.header.ResumeLayout(False)
        CType(Me.PictureBox10, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox8, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox3, System.ComponentModel.ISupportInitialize).EndInit()
        Me.body.ResumeLayout(False)
        Me.body.PerformLayout()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox9, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox7, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox6, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox5, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox4, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.PictureBox2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.ErrorProvider1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents header As System.Windows.Forms.Panel
    Friend WithEvents body As System.Windows.Forms.Panel
    Friend WithEvents bemvindo As System.Windows.Forms.Label
    Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    Friend WithEvents PictureBox4 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox5 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox6 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox7 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents PictureBox9 As System.Windows.Forms.PictureBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents ErrorProvider1 As System.Windows.Forms.ErrorProvider
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox3 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox8 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox10 As System.Windows.Forms.PictureBox
    Friend WithEvents Label8 As System.Windows.Forms.Label

End Class
  • 1

    I think by your (I forgot the name, that bar where you have the close and minimize) be different, ie a created by you do not have the property to move, that’s it ?

  • 1

    Enter details of how it is done. Give information that it is possible to evaluate what is happening.

  • Exactly Roberto, I removed it to be able to customize, and now I do not have this property.

  • @bigown is basically the fact that I have customized the bar and now have no property

  • I’ve seen a way to do it, but it’s been a long time and I remember it was complicated.

  • How do I answer here ? (found a code)

  • http://pastebin.com/SZcreAwe I haven’t had time to test, but I think it’ll work.

  • And put that code where? No header?

  • Unfortunately it didn’t work.

  • I used this code once and it worked 100%: http://stackoverflow.com/a/1592899/1274092. The only thing is that it is in C# and you will need to translate to VB. And it moves when you click on a form area; then you might want to use the evendo Mousedown of another component instead of using the form.

  • The thing is, I’m a beginner in VB.net. And I can’t translate that, but I appreciate your help.

  • @I can translate for you if you reopen the question. You would have to show how you developed this fictitious title bar, perhaps by pasting the design code of the form (file "Nomeformulario.Designer.Vb"; otherwise I can do it in a way that doesn’t work for you and you won’t be able to adapt.

  • Done! Edited question.

  • Now all that’s left is a good soul to reopen the question.

  • I’ll be waiting for you ^-^

Show 10 more comments

1 answer

2


You will need to transfer the drag messages received by the component that visually replaces the title bar to the actual title bar that you have hidden. To do so, you can:

Use the Windows API by importing the native library user32.dll.

In practice, you forward to the title bar the message that the mouse was clicked on, then the next messages (drag and drop) will also be sent to the title bar.

The final code stays like this:

Imports System.Runtime.InteropServices

Public Class Form1

    Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    Private Const HT_CAPTION As Integer = &H2

    <DllImport("user32.dll")> _
    Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function ReleaseCapture() As Boolean
    End Function

    Private Sub PictureBox3_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox3.MouseDown

        DelegaArrastarParaBarraTitulo(sender, e)
    End Sub

    Private Sub header_MouseDown(sender As Object, e As MouseEventArgs) Handles header.MouseDown

        DelegaArrastarParaBarraTitulo(sender, e)
    End Sub

    Private Sub DelegaArrastarParaBarraTitulo(sender As Object, e As MouseEventArgs)
        If e.Button = MouseButtons.Left Then
            ReleaseCapture()
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0)
        End If

    End Sub
End Class

I noticed that you a panel to visually represent the title bar that you hid, and on this panel you pasted an image (Picturebox) displaying the title "Moderation Wizard".

So that’s why I linked code to the event Mousedown of these two components.

Picturebox3_mousedown and header_MouseDown are methods associated with the respective events of the respective components.

The code of this reply was adatado of this other answer in C#: Make a Borderless form Movable.

  • http://prntscr.com/8oixah - Gave these 2 errors. Could you see if I have applied the code correctly? http://pastebin.com/jv5k2Azt

  • I updated the response including the line connector (space + underline) at the end of the declaration of each attribute: <DllImportAttribute("user32.dll")> _. Do this and check. The documentation says that the attribute and element it decorates must be on the same line or connected by the underline. You and I must be using different versions of the compiler, being my smartest and realizing that the element is on the next line without having to connect the lines.

  • 1

    It worked! Thank you for your support and dedication to my question, I am very grateful. :)

  • @Maradinhoph You were unhappy with the first version of your question, which did not have enough information, but proved quite interested and provided everything you were asked to get the solution. You also dedicated yourself - we’re even :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.