Open existing Windows Forms in CAB

Topics: CAB & Smart Client Software Factory
Jan 17, 2007 at 5:30 PM
I am trying to figure out how to migrate a humongous application to CAB. This application was ported over from VB6 to VB.NET and is now being re-written in C# using CAB. As a part of the design, we need to ensure that the old forms that are not currently ported over to the new environment still be accessible since we are doing development in phases.

Is it possible to invoke regular forms using CAB? These forms pretty much have the entire code written in them (since it's been around since the VB6 days). Can anyone who has had such kind of an experience tell me if this is feasible? Any kinds of suggestions would be highly appreciated.

Thank You
Anup
Coordinator
Jan 17, 2007 at 11:08 PM
I would recommend you extract each form to a usercontrol. Then you will just show those usercontorls in a workspace. There is nothing in CAB that will prevent you to show a regular usercontrol in a workspace.

Matias
http://staff.southworks.net/blogs/matiaswoloski
Jan 18, 2007 at 9:00 AM
Yes this is possible.

Form1 frm=WorkItem.Items.AddNew<Form1>("Form1");
frm.ShowDialog();

//Certany after closing the form you should remove this form from Items list!
WorkItem.Items.Remove(frm);

Or when you have a presenter form this Form1, the presenter may also remove the view from WorkItem
(Form1Presenter.cs)
...
OnViewClose()
{
WorkItem.Items.Remove(View);
}
Jan 19, 2007 at 1:52 AM
Where do you want the form to be displayed if you want the form to be displayed in the workpaces means you need to convert the form to usercontrol.But you can do that using the mdiworkspace for that you need to tweak GoCreateForm method in the WindowsWorkspace to accept the Form instead of COntrol.I hv done this for my project and works very well.And no other workspace support the Form to be diplayed in it.

Mani


Jan 22, 2007 at 1:22 AM
Thanks for the reply guys. I will look into this and come back with questions if I have any.

Cheerz
Anup
Jan 24, 2007 at 10:58 PM
I was able to accomplish this without changing anything in the original form using the following code:

In the AddViews Method in the ModuleController class:

MainForm form = new MainForm();
WorkItem.Items.Add(form, "InvoiceManager");
form.TopLevel = false;
form.FormBorderStyle = FormBorderStyle.None;

In an EventSubscription subscribing to the click of a menuitem to launch the previously added form:

MainForm form = WorkItem.Items.Get<MainForm>("InvoiceManager");
WorkItem.WorkspacesWorkspaceNames.ContentWorkspace.Show(form);
form.Show();

The only issue with this is that the Menu for the form is nested in the content workspace, where it would be if it were a standalone form.

Hope this helps.

Jon King
jonk@hpsionline.com