|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
AbstractThe article describes a IntroductionThe .NET 2.0 Framework introduces the DesignSurface class which implements what the user perceives as a designer. This class is an improvement over the .NET 1.0 one, but it is still missing some design facilities which are very useful for the user who wants to design Forms. I'm talking about: TabOrder, UndoEngine and SnapLines/Grid alignment. All these features can be added with little effort (except maybe the TabOrder), nevertheless I want to make life a little easier for anyone who wants to make her/his own "designer". BackgroundYou should be familiar with basic C# programming and with some concepts used by the .NET designer (especially if you dive into the source code). How to Use DesignSurfaceExtIn short: using DesignSurfaceExt;
...
Form frm = new Form();
IDesignSurfaceExt surface = new DesignSurfaceExt.DesignSurfaceExt();
surface.CreateRootComponent( typeof( Form ), new Size( 400, 400 ) );
surface.CreateControl( typeof( Button ), new Size( 100, 40 ), new Point( 10, 10 ) );
TextBox t1 = (TextBox) surface.CreateControl( typeof( TextBox ),
new Size( 300, 20 ), new Point( 10, 80 ) );
t1.Text = "Hello World by DesignSurfaceExt";
surface.GetView().Parent = frm;
frm.ShowDialog();
The above code snippet simply creates a new Tiny Form Designer, a Simple Demo Project to Show You the Power of the DesignSurfaceExtObviously you can do anything you want as I show you in the The InterfaceThe really useful features are exposed through public interface IDesignSurfaceExt {
//- perform Cut/Copy/Paste/Delete commands
void DoAction( string command );
//- de/activate the TabOrder facility
void SwitchTabOrder();
//- select the controls alignment mode
void UseSnapLines();
void UseGrid ( System.Drawing.Size gridSize );
void UseGridWithoutSnapping ( System.Drawing.Size gridSize );
void UseNoGuides();
//- method useful to create control without the ToolBox facility
IComponent CreateRootComponent ( Type controlType, Size controlSize );
Control CreateControl ( Type controlType, Size controlSize, Point controlLocation );
//- Get the UndoEngineExtended object
UndoEngineExt GetUndoEngineExt();
//- Get the IDesignerHost of the .NET 2.0 DesignSurface
IDesignerHost GetIDesignerHost();
//- the View of the .NET 2.0 DesignSurface is just a Control
//- you can manipulate this Control just like any other WinForms Control
//- (you can dock it and add it to another Control just to display it)
//- Get the View
Control GetView();
}//end_interface
The SnapLines/Grid Alignment GuidesThe use of the Snaplines to align the controls hosted by the surface.UseSnapLines();
If you prefer to use the Grid to align the controls hosted by the surface.UseGrid ( new System.Drawing.Size ( 16, 16 ) );
You can also align the control with no guides at all: surface.UseGridWithoutSnapping ( new System.Drawing.Size ( 32, 32 ) );
surface.UseNoGuides();
The TabOrderAnd what about the Taborder? Simply call the surface.SwitchTabOrder();
The UndoEngineNow the UndoEngine! Get it via the Property: surface.GetUndoEngineExt().Undo();
surface.GetUndoEngineExt().Redo();
Cut/Copy/Paste/Delete the ControlsFinally use the cut/copy/paste and delete as usual: surface.DoAction( "Cut" );
surface.DoAction( "Copy" );
surface.DoAction( "Paste" );
surface.DoAction( "Del" );
Conclusion
History
|
||||||||||||||||||||||