Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a moveable analog clock with a shaped form in VB .NET
DescriptionThis example shows how to make an analog clock with a shaped form in VB .NET. The user can click and drag on the center of the clock to move it.
Keywordsanalog, clock, time, position, lower right, rotated text, move, move form
CategoriesMultimedia, Graphics, Utilities, VB.NET
 
See the example Make an analog clock with a shaped form in VB .NET for the basics.

This version also watches MouseDown events. if the user presses the left mouse down on the form, the program calls OverCenter to see if the mouse is over the form's center. If it is, the program calls the ReleaseCapture API function to release the mouse down event. It then uses the SendMessage API function to send the form the WM_NCLBUTTONDOWN message with the HTCAPTION parameter. This makes the form behave as if the user had pressed the mouse down over the form's caption area, which starts moving the form.

 
' Let the user drag the form by left-clicking on the very
' center of the form,
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e _
    As System.Windows.Forms.MouseEventArgs) Handles _
    MyBase.MouseDown
    If e.Button = MouseButtons.Left Then
        If OverCenter(e.X, e.Y) Then
            ' Move the form.
            ReleaseCapture()
            SendMessage(Handle.ToInt32, WM_NCLBUTTONDOWN, _
                HTCAPTION, 0)
        End If
    End If

End Sub

' Return True if the mouse is near the center of the form.
Private Function OverCenter(ByVal X As Integer, ByVal Y As _
    Integer) As Boolean
    Const GRAB_RADIUS As Integer = 3
    Dim cx As Integer
    Dim cy As Integer
    Dim dx As Integer
    Dim dy As Integer

    ' See if the point is close enough to the center.
    cx = Me.ClientRectangle.Width \ 2
    cy = Me.ClientRectangle.Height \ 2
    dx = cx - X
    dy = cy - Y

    OverCenter = (dx * dx + dy * dy <= GRAB_RADIUS * _
        GRAB_RADIUS)
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated