Move Form without title bar


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Move Form without title bar

Hybrid View

  1. #1
    Jonas Guest

    Move Form without title bar


    Hi folks

    Well, i have created a gradient elipsed winform without title bar. I couldn´t
    move the form, but i have used API and translated it (like in vb6) to move
    it:
    **************************
    Public Declare Function SendMessage Lib "User32" Alias "SendMessageA"
    (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal
    lParam As Integer) As Integer
    Public Declare Sub ReleaseCapture Lib "User32" () 'API que liberta o
    rato
    Public Const WM_NCLBUTTONDOWN = &HA1 'constatne que detecta o botăo primido
    Public Const HTCAPTION = 2 'constante que faz mover o formulário
    *************************
    On MouseDownd of the form:

    ************************************
    Private Sub Form1_MouseDown(blah blah)
    Dim valor_retorno As Integer
    'libertar rato
    Call ReleaseCapture()

    'mover o formulário com HTCAPTION
    valor_retorno = SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    End Sub

    *****************

    Well, the form moves, but there´s any way to move it without using API? It
    is kind of lame not?

    By the way, i think .NET ignores a little the win32 API functions, like the
    processing of sending and capture windows messages (sub and hiper classing)...

    Jonas




  2. #2
    Rob Teixeira Guest

    Re: Move Form without title bar



    Not true at all Jonas (fortunately!)

    .NET has much better native support for message processing.
    There is a Message class that encapsulates and represents windows messages.
    Every Control and Form has a protected OnNotifyMessage method. You can also
    override the WndProc method to provide custom message handling (call MyBase.WndProc
    for messages you don't process). You can also call WndProc yourself to send
    a message. You can also call DefWndProc to use the default message processing.

    -Rob

    "Jonas" <portugal@portugal.com> wrote:
    >
    >
    >By the way, i think .NET ignores a little the win32 API functions, like

    the
    >processing of sending and capture windows messages (sub and hiper classing)...
    >
    >Jonas
    >
    >
    >



  3. #3
    Jacob Grass Guest

    Re: Move Form without title bar

    Jonas-

    Here is how to handle it without the API:

    Private blnMoving As Boolean = False
    Private MouseDownX As Integer
    Private MouseDownY As Integer

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As
    MouseEventArgs) _
    Handles MyBase.MouseDown

    If e.Button = MouseButtons.Left Then
    blnMoving = True
    MouseDownX = e.X
    MouseDownY = e.Y
    End If
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
    _
    Handles MyBase.MouseUp

    If e.Button = MouseButtons.Left Then
    blnMoving = False
    End If
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As
    MouseEventArgs) _
    Handles MyBase.MouseMove

    If blnMoving Then
    Dim temp As Point = New Point()

    temp.X = Me.Location.X + (e.X - MouseDownX)
    temp.Y = Me.Location.Y + (e.Y - MouseDownY)
    Me.Location = temp
    End If
    End Sub

    --
    Jacob Grass
    Microsoft .NET MVP

    "Jonas" <portugal@portugal.com> wrote in message
    news:3bee8d94$1@147.208.176.211...
    >
    > Hi folks
    >
    > Well, i have created a gradient elipsed winform without title bar. I

    couldn´t
    > move the form, but i have used API and translated it (like in vb6) to move
    > it:
    > **************************
    > Public Declare Function SendMessage Lib "User32" Alias "SendMessageA"
    > (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer,

    ByVal
    > lParam As Integer) As Integer
    > Public Declare Sub ReleaseCapture Lib "User32" () 'API que liberta o
    > rato
    > Public Const WM_NCLBUTTONDOWN = &HA1 'constatne que detecta o botăo

    primido
    > Public Const HTCAPTION = 2 'constante que faz mover o formulário
    > *************************
    > On MouseDownd of the form:
    >
    > ************************************
    > Private Sub Form1_MouseDown(blah blah)
    > Dim valor_retorno As Integer
    > 'libertar rato
    > Call ReleaseCapture()
    >
    > 'mover o formulário com HTCAPTION
    > valor_retorno = SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    > End Sub
    >
    > *****************
    >
    > Well, the form moves, but there´s any way to move it without using API? It
    > is kind of lame not?
    >
    > By the way, i think .NET ignores a little the win32 API functions, like

    the
    > processing of sending and capture windows messages (sub and hiper

    classing)...
    >
    > Jonas
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center