Having trouble with the simplest thing it seems

Topics: CAB & Smart Client Software Factory
Aug 19, 2006 at 2:04 AM
originally posted by: mistergraviton

I read the documentation but it not clear to me about how I add UIELEMENTS

when I try to add extension sites in the AfterShellCreated method it gives me a
Object refrence not set to an instance of an object error
I just wanted to add a menu bar and menus to the form using cab but I don't understand how
this is supposed to be done

here's the code from the AfterShellCreated Method

ToolStripMenuItem fileItem = (ToolStripMenuItem)Shell.MainMenuStrip.Items"File";
RootWorkItem.UIExtensionSites.RegisterSite("File", fileItem.DropDownItems);
ToolStripMenuItem item = new ToolStripMenuItem("ShowCustomer");
RootWorkItem.UIExtensionSites"File".Add(item);

I tried this aswell in the AfterShellCreated

RootWorkItem.UIExtensionSites.RegisterSite("ms", Shell.MainMenuStrip);
ToolStripMenuItem signInItem = new ToolStripMenuItem("SIGN IN");
RootWorkItem.UIExtensionSites"ms".Add(signInItem);
RootWorkItem.UIExtensionSites.RegisterSite("ms", Shell.MainMenuStrip);
ToolStripMenuItem helpItem = (ToolStripMenuItem)Shell.MainMenuStrip.Items"helpToolStripMenuItem";

if (signInItem != null && signInItem.DropDownItems != null)
{
ToolStripItem aboutItem = signInItem.DropDownItems"aboutToolStripMenuItem";
}

I'm supposed to add a menustrip to the form control part right?
SmartPart
public partial class Form1 : Form
{

public MenuStrip ms;

public Form1()
{
ms = new MenuStrip();
ToolStripMenuItem fileMenu = new ToolStripMenuItem("File");
// ms.Items.Add(fileMenu);

ms.Dock = DockStyle.Top;
this.Controls.Add(ms);
InitializeComponent();

}
}

public class SmartCabWorkItem : Microsoft.Practices.CompositeUI.WorkItem
{
protected override void OnRunStarted()
{
base.OnRunStarted();
// ToolStripMenuItem signInItem = new ToolStripMenuItem("SIGN IN");
// UIExtensionSites"ms".Add(signInItem);
}

}
I did that but it still doesn't work can someone please help
Aug 19, 2006 at 5:22 AM
originally posted by: JKraft4PIT

Did you set the shells "MainMenuStrip" to be a main menu on the form. I had trouble with this too and I found out there is a property on the Shell form called "MainMenuStrip" and you assign a menustrip to it.
Aug 19, 2006 at 8:38 AM
originally posted by: mistergraviton

Actually I thought that I did that in the aftershellcreated method
with this
RootWorkItem.UIExtensionSites.RegisterSite("ms", Shell.MainMenuStrip);

in the form class I have something like this
SmartPart
public partial class Form1 : Form
{

public MenuStrip ms;

public Form1()
{
ms = new MenuStrip();
ToolStripMenuItem fileMenu = new ToolStripMenuItem("File");
// ms.Items.Add(fileMenu);

ms.Dock = DockStyle.Top;
this.Controls.Add(ms);
InitializeComponent();

but I still get a an error
Aug 19, 2006 at 8:51 AM
originally posted by: JKraft4PIT

You are not looking at the right spot.

Not quite, change your code from this:
(but only if the form1 class is your shell form)

the Shell.MainMenuStrip is still null you have to initialize it to your main menu, it gets this main menu from the Shell form.

public Form1()
{
ms = new MenuStrip();
ToolStripMenuItem fileMenu = new ToolStripMenuItem("File");
.
.
.


To:

public Form1()
{
ms = new MenuStrip();
this.MainMenuStrip = ms;
ToolStripMenuItem fileMenu = new ToolStripMenuItem("File");
.
.
.
.

You can do this in Visual Studio when you have the shell selected, pop up the properties and find "MainMenuStrip" and select your mainmenu. If one isn't present then add one to your form, or do it in code like shown above.
Aug 19, 2006 at 11:52 AM
originally posted by: mistergraviton

Thank you, It worked now I can try to figure out the rest of CAB! :)