Any one who has used asp.net mvc will have be entranced by the “Add View” and “Add Controller” features. This is implemented using Visual Studio Wizards, today we will look into how we can implement such a wizard. We will be using this wizard at SyneITY for our development process.
Since Visual Studio uses COM to display this wizard, we have to make this dll visible to COM. For this we have to do the following:
and save this as SynWizard.vsz in “Program Files\Microsoft Visual Studio 10.0\VC#\CSharpProjectItems\Windows Forms”
On selecting SynWizard, you will find the form that we added in the above project
Here we have just shown a form and shown it. In future blogs we will see how we can extend this and generate code and add them to the project.
What will this wizard do?
This wizard will just display a windows form when we add a new item.So how do we develop such a wizard?
- Open a new Visual Studio Instance as an administrator.
- Create a new Visual Studio Class Library.
Mine was named “BlgVsWizard”.
- Add references to
- envdte
- envdte80
- envdte
- Added a windows form to the project.
public partial class frmWizard : Form
{
public frmWizard()
{
InitializeComponent();
}
private void btnCreate_Click(object sender, EventArgs e)
{
MessageBox.Show("You can create over here!!!!!!");
}
}
- Add a class SynWizard, Inherit this class from the IDTWizard and implement its method
public class SynWizard :
IDTWizard
{
public void Execute(object Application, int hwndOwner, ref object[] ContextParams,
ref object[] CustomParams, ref wizardResult retval)
{
frmWizard obj = new frmWizard();
obj.ShowDialog();
}
}
Since Visual Studio uses COM to display this wizard, we have to make this dll visible to COM. For this we have to do the following:
- In the project Properties Folder in Solution Explorer open the AssemblyInfo.cs file and make the
[assembly: ComVisible(false)] as
[assembly: ComVisible(true)]
- Then take the project properties and in Build Tab, check the “Register for Com” checkbox.
- Now build this and then open a new instance of notepad and type the following in
VSWIZARD 7.0
Wizard=BlgVsWizard.SynWizard
Param=First Item
Param=Second Item
and save this as SynWizard.vsz in “Program Files\Microsoft Visual Studio 10.0\VC#\CSharpProjectItems\Windows Forms”
- Now close visual studio and reopen it, now add a new project and in that project select “add New item”, you will find “SynWizard” in the windows form folder.
On selecting SynWizard, you will find the form that we added in the above project
Here we have just shown a form and shown it. In future blogs we will see how we can extend this and generate code and add them to the project.
No comments:
Post a Comment