Click here to Skip to main content
16,004,452 members
Articles / Programming Languages / C#

Have a Great DesignTime Experience with a Powerful DesignSurface (Extended) Class

Rate me:
Please Sign up or sign in to vote.
4.93/5 (54 votes)
14 Mar 2008CPOL3 min read 181.7K   7.3K   142  
Use design facilities (TabOrder, UndoEngine, SnapLines / Grid alignment) to design WinForms
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
using System.Drawing;


namespace DesignSurfaceExt {

internal class DesignerOptionServiceExt4SnapLines : DesignerOptionService {
public DesignerOptionServiceExt4SnapLines() : base() { }

    protected override void PopulateOptionCollection ( DesignerOptionCollection options ) {
        if ( null != options.Parent ) return;

        DesignerOptions ops = new DesignerOptions();
        ops.UseSnapLines = true;
        ops.UseSmartTags = true;
        DesignerOptionCollection wfd = this.CreateOptionCollection ( options, "WindowsFormsDesigner", null );
        this.CreateOptionCollection ( wfd, "General", ops );
    }
}//end_class

internal class DesignerOptionServiceExt4Grid : DesignerOptionService {
    private System.Drawing.Size _gridSize;

    public DesignerOptionServiceExt4Grid ( System.Drawing.Size gridSize ) : base() { _gridSize = gridSize; }

    protected override void PopulateOptionCollection ( DesignerOptionCollection options ) {
        if ( null != options.Parent ) return;

        DesignerOptions ops = new DesignerOptions();
        ops.GridSize = _gridSize;
        ops.SnapToGrid = true;
        ops.ShowGrid = true;
        ops.UseSnapLines = false;
        ops.UseSmartTags = true;
        DesignerOptionCollection wfd = this.CreateOptionCollection ( options, "WindowsFormsDesigner", null );
        this.CreateOptionCollection ( wfd, "General", ops );
    }
}//end_class

internal class DesignerOptionServiceExt4GridWithoutSnapping : DesignerOptionService {
    private System.Drawing.Size _gridSize;

    public DesignerOptionServiceExt4GridWithoutSnapping ( System.Drawing.Size gridSize ) : base() { _gridSize = gridSize; }

    protected override void PopulateOptionCollection ( DesignerOptionCollection options ) {
        if ( null != options.Parent ) return;

        DesignerOptions ops = new DesignerOptions();
        ops.GridSize = _gridSize;
        ops.SnapToGrid = false;
        ops.ShowGrid = true;
        ops.UseSnapLines = false;
        ops.UseSmartTags = true;
        DesignerOptionCollection wfd = this.CreateOptionCollection ( options, "WindowsFormsDesigner", null );
        this.CreateOptionCollection ( wfd, "General", ops );
    }
}//end_class

internal class DesignerOptionServiceExt4NoGuides : DesignerOptionService {
    public DesignerOptionServiceExt4NoGuides() : base() { }

    protected override void PopulateOptionCollection ( DesignerOptionCollection options ) {
        if ( null != options.Parent ) return;

        DesignerOptions ops = new DesignerOptions();
        ops.GridSize = new System.Drawing.Size ( 8, 8 );
        ops.SnapToGrid = false;
        ops.ShowGrid = false;
        ops.UseSnapLines = false;
        ops.UseSmartTags = true;
        DesignerOptionCollection wfd = this.CreateOptionCollection ( options, "WindowsFormsDesigner", null );
        this.CreateOptionCollection ( wfd, "General", ops );
    }
}//end_class

}//end_namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Italy Italy
I started coding in 1984 on a ZX Spectrum. From the Sinclair Basic I jumped straight to C++ (which I use since 1992). I wrote code in assembly 386, ANSI C++ (I love it) and VisualBasic 6.0 (urgh!!!); nowadays I write code in C# 4.0!

I was born in 1968 in Italy and I live in the north west of my country (near Venice). I work as a Project Leader/Senior Developer.

Computer Science interests: I like coding 3D-GameEngine and OpenGL applications.

Sport and hobbies: Martial Arts, Latino Dance, travels, reading and writing novels.

Comments and Discussions