We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to initialize Menus through code?

 

Each and every component of menu has to be individually initialized through code and finally add the MainFrameBarManager to the form. Please refer the below code snippet which illustrates this:

C#

this.mainFrameBarManager1 = new Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager(this.components, this);

this.mainFrameBarManager1.Categories.Add("MainMenu");

this.parentBarItem1 = new Syncfusion.Windows.Forms.Tools.XPMenus.ParentBarItem();

this.barItem1 = new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem();

this.barItem2 = new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem();

this.barItem3 = new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem();

this.mainFrameBarManager1.Items.AddRange(new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem[] { this.parentBarItem1, this.barItem1, this.barItem2, this.barItem3 });

this.bar1 = new Syncfusion.Windows.Forms.Tools.XPMenus.Bar(this.mainFrameBarManager1, "MainMenu");

this.mainFrameBarManager1.Bars.Add(this.bar1);

this.bar1.Manager = this.mainFrameBarManager1;

this.parentBarItem1.Items.AddRange(new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem[] { this.barItem1, this.barItem2, this.barItem3 });

this.bar1.Items.AddRange(new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem[] { this.parentBarItem1 });

this.parentBarItem1.Text = "File";

this.barItem1.Text = "New";

this.barItem2.Text = "Open";

this.barItem3.Text = "Save";

((System.ComponentModel.ISupportInitialize)(this.mainFrameBarManager1)).EndInit();

VB

Me.mainFrameBarManager1 = New Syncfusion.Windows.Forms.Tools.XPMenus.MainFrameBarManager(Me.components, Me)

Me.mainFrameBarManager1.Categories.Add("MainMenu")

Me.parentBarItem1 = New Syncfusion.Windows.Forms.Tools.XPMenus.ParentBarItem()

Me.barItem1 = New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem()

Me.barItem2 = New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem()

Me.barItem3 = New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem()

Me.mainFrameBarManager1.Items.AddRange(New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem() {Me.parentBarItem1, Me.barItem1, Me.barItem2, Me.barItem3})

Me.bar1 = New Syncfusion.Windows.Forms.Tools.XPMenus.Bar(Me.mainFrameBarManager1, "MainMenu")

Me.mainFrameBarManager1.Bars.Add(Me.bar1)

Me.bar1.Manager = Me.mainFrameBarManager1

Me.parentBarItem1.Items.AddRange(New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem() (Me.barItem1, Me.barItem2, Me.barItem3})

Me.bar1.Items.AddRange(New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem() {Me.parentBarItem1})

Me.parentBarItem1.Text = "File"

Me.barItem1.Text = "New"

Me.barItem2.Text = "Open"

Me.barItem3.Text = "Save"

CType(Me.mainFrameBarManager1, System.ComponentModel.ISupportInitialize).EndInit()

Sample:

http://websamples.syncfusion.com/samples/KB/Tools.Windows/TThruCode/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
1161 04/30/2011 07/10/2014 Windows Forms XPToolbar
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon