An easy-to-use Wizard control: ETWizard

Source: Internet
Author: User
It involves user controls. Most of them only focus on the control itself, as well as the dll and source code, and seldom focus on the implementation process.
Wizard controls are frequently used in winform development. Recently I have referred to GuiWizard and implemented a wizard control myself. I think it is okay to use it. I will share it with you now.
First, let's talk about the key points of the control implementation.
1. user Control, you need to create a wizard interface (ETWizard), including the bottom (including the Back, Next, Cancel/Finish buttons), top (including the Title and Tip/Description of the Wizard Page ), the middle part (this part is used to display the specific Wizard Page ).
2. Implement a Wizard Page class: ETWizardPage, which inherits from the Panel. Used to add or edit the Wizard Page for the wizard control in design mode.
A) How to Implement page switching. I refer to the implementation idea of GuiWizard, that is, four events are added to the ETWizardPage: CloseWhenNext, CloseWhenBack, ShowWhenNext, and ShowWhenBack. Call these four events to switch between different pages.
B) In the Page turning event on the Wizard Page, a wizard event class is defined: ETPageEventArgs, which provides two public attributes: Page and PageIndex. This event uses the PageEventArgs class in GuiWizard directly.
C) how to verify the input of each page and perform operations on the page. I provide three events to complete: ValidateWhenNext, ExecuteWhenNext, and ExecuteWhenBack. Add these three events to the specified ETWizardPage to control the page verification and perform the operation.
D) to manage all the wizard pages, I directly used the PageCollection (: CollectionBase) Implementation in GuiWizard to manage the Wizard Page set.
E) add the designer ETPageDesigner to the Wizard Page. It mainly provides deletion of objects. The designer needs to override the Verbs attribute. Code
Public override DesignerVerbCollection Verbs
{
Get
{
DesignerVerbCollection verbs = new DesignerVerbCollection ();
Verbs. Add (new DesignerVerb ("Remove page", new EventHandler (ETWizardPage_Remove )));
Return verbs;
}
}

The ETWizardPage_Remove method is implemented as follows:
ETWizardPage page = Control as ETWizardPage;
If (page = null)
Return;
IDesignerHost host = (IDesignerHost) GetService (typeof (IDesignerHost ));
IComponentChangeService service = (IComponentChangeService) GetService (typeof (IComponentChangeService ));
DesignerTransaction transaction = host. CreateTransaction ("Remove page ");

If (page. Wizard = null)
Return;
Int iLoc =-1;
ETWizard wizard = page. Wizard;
Int index = wizard. Pages. IndexOf (page );
If (index <wizard. Pages. Count-1)
ILoc = index;
Else
ILoc = index-1;

Service. OnComponentChanging (wizard, null );
Wizard. Pages. Remove (page );
Wizard. Controls. Remove (page );
Service. OnComponentChanged (wizard, null );
Host. DestroyComponent (page );

If (iLoc> = 0 & wizard. Pages. Count> iLoc)
Wizard. ActivatePage (iLoc );
Transaction. Commit ();

3. Add the designer ETWizardDesigner to the wizard control (ETWizard.
Override attributes such as DrawGrid and Verbs, and methods such as CanParent, GetHitTest, OnDragEnter, and OnPaintAdornments.
The main part is to Add an "Add page" function to the designer. The basic implementation method is shown in the Remove page Implementation of ETWizardPageDesigner above.
To add the ETWizardPage to a specific panel in ETWizard, You need to override the OnControlAdded and OnControlRemoved events of ETWizard.
4. The difference between ETWizard and other wizard controls.
In terms of implementation, the control is concise and does not provide complicated Head implementation. It only provides simple top information (Title, Tip ). The Title/Tip of the control automatically displays the Title/Tip of the current displayed page. The Wizard Page verification and execution of two events are added, allowing users to write their own page verification functions and page execution methods. The entire control has few Code and is relatively simple.

Source code download: ETWizard

If you have any good comments or suggestions, you may wish to raise them so that we can make common progress. Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.