CustomSnapline

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

 
 
 
 
 
(0)
5,000 times
Add to favorites
2/4/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
VB.NET
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()
        InitializeComponent()
    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
        Get
            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
            Next
            Return snapLines1
        End Get
    End Property

End Class