The CustomSnapline project shows how to add a text baseline snapline to a UserControl with a Label on it.

5,000 times
Add to favorites
E-mail Twitter Digg Facebook

Solution explorer

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Windows.Forms.Design.Behavior
Imports System.Collections.ObjectModel
Imports System.Collections

<Designer(GetType(ControlWithCustomSnaplineDesigner))> _
Partial Class ControlWithCustomSnapline
    Inherits UserControl

    Friend WithEvents label1 As Label

    Public Sub New()
    End Sub

End Class

' To provide a custom snapline for your control you need to 
' override the SnapLines property on ControlDesigner
' This simple example adds a text baseline snapline to a
' UserControl with a Label on it.
Public Class ControlWithCustomSnaplineDesigner
    Inherits ControlDesigner

    Public Overrides ReadOnly Property SnapLines() As System.Collections.IList
            Dim snapLines1 As ArrayList = CType(MyBase.SnapLines, ArrayList)
            For Each c As Control In Control.Controls
                If (TypeOf (c) Is Label) Then
                    snapLines1.Add(New SnapLine(SnapLineType.Baseline, c.Top + c.Height))
                End If
            Return snapLines1
        End Get
    End Property

End Class