Grid-snap subform to mainform's x,y location

Xancholy

Well-known member
Joined
Aug 29, 2006
Messages
143
Programming Experience
Beginner
I have mdi forms Main and Child

I expressly position smaller Child near Main's Close button with the following code

VB.NET:
Public Class Form1

    Private OwnedForm As Form
    Private bypass As Boolean = True

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        OwnedForm = New Form
        OwnedForm.BackColor = Color.Blue 'To distinguish it for this example

        OwnedForm.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow 'allow subform closing

        OwnedForm.Owner = Me
        OwnedForm.Size = New Size(170, 90)
        OwnedForm.Show()

        bypass = False
        SetOwnedForm()

    End Sub

 

    Private Sub SetOwnedForm()
        OwnedForm.Location = New Point(Me.Right - OwnedForm.Width - 4, Me.Top + 30) 'position it just inside the main form
    End Sub


    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize, Me.LocationChanged

        If Not bypass Then SetOwnedForm()

    End Sub

User can pull the Child form away from default location and set it anywhere on screen.

When user drags the Child near the default location, how can I implement grid-snap to snap the Child form back to original location ?
 

Latest posts

Back
Top