Snap to Control : Frame Form « GUI « VB.Net






Snap to Control

  

Imports System.Windows.Forms
Imports System.Drawing
Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Button1 = New System.Windows.Forms.Button()
        Me.LinkLabel1 = New System.Windows.Forms.LinkLabel()
        Me.SuspendLayout()
        '
        Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Bitmap)
        Me.Button1.Location = New System.Drawing.Point(192, 48)
        Me.Button1.Size = New System.Drawing.Size(168, 64)
        '
        Me.LinkLabel1.Location = New System.Drawing.Point(24, 16)
        Me.LinkLabel1.Text = "Click here to snap!"
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(544, 182)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.LinkLabel1, Me.Button1})
        Me.Text = "Snapping to a Control"
        Me.ResumeLayout(False)

    End Sub
    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        SnapToControl(Button1)
    End Sub

    Public Sub SnapToControl(ByVal Control As Control)
        Dim objPoint As Point = Control.PointToScreen(New Point(0, 0))
        Cursor.Position = objPoint
    End Sub
End Class

   
    
  








Related examples in the same category

1.Simple window frameSimple window frame
2.Form Opacity in VBForm Opacity in VB
3.Non rectangle window in VBNon rectangle window in VB
4.Get Frame Client Rectangle SizeGet Frame Client Rectangle Size
5.Resetting a Form