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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Windows.Forms.Design.Behavior;
using System.Collections.ObjectModel;
using System.Collections;

namespace CustomSnapline
{
    [Designer(typeof(ControlWithCustomSnaplineDesigner))]
    public partial class ControlWithCustomSnapline : UserControl
    {
        public ControlWithCustomSnapline()
        {
            InitializeComponent();
        }
    }

    // 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 : ControlDesigner
    {
        public override System.Collections.IList SnapLines
        {
            get
            {
                ArrayList snapLines = base.SnapLines as ArrayList;

                foreach (Control c in Control.Controls)
                {
                    if (c is Label)
                    {
                        snapLines.Add(new SnapLine(SnapLineType.Baseline, c.Top + c.Height));
                    }
                }

                return snapLines;
            }
        }
    }
}