question

MRUTYUNJAYAMAHAPATRA-6389 avatar image
0 Votes"
MRUTYUNJAYAMAHAPATRA-6389 asked DanielZhang-MSFT commented

menuitems.addrange in .Net 5

Hi, I am migrating our project to .Net 5.

As per documentation menuitem is deprecated in .Net5 and ToolStripMenuItem is used instead, which replaces the MenuItem control.

I was using Addrange function of menuitem . Can anybody please suggest that what is the corresponding of Addrange in ToolStripMenuItem. How can I migrate this ?


following are code snippets below ....

private System.Windows.Forms.MenuStrip MainMenu;
private System.Windows.Forms.ToolStripMenuItem mnuFile;


this.MainMenu.Items.AddRange(new System.Windows.Forms.ToolStripMenuItem[] { this.mnuFile});
//
// mnuFile
//
this.mnuFile.MergeIndex = 0;
this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.ToolStripMenuItem[] {

dotnet-csharpwindows-wpfwindows-formsdotnet-runtimewindows-platform-network
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MRUTYUNJAYAMAHAPATRA-6389,
please try the following code:

 MenuStrip ms = new MenuStrip();
 ms.Items.AddRange(new ToolStripItem[] {contextMenuStrip1.Items[0],contextMenuStrip1.Items[1] });

Best Regards,
Daniel Zhang

0 Votes 0 ·

this.MainMenu.Items.AddRange(new System.Windows.Forms.ToolStripMenuItem[] { this.mnuFile}); -> MainMenu is menustrip (Tis is already migrated as per your above code)
//
// mnuFile
//
this.mnuFile.MergeIndex = 0;
this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.ToolStripMenuItem[] { -> mnuFile is ToolStripMenuItem I would like to know, how can I migrate same AddRange for ToolStripMenuItem () because mnuFile is ToolStripMenuItem )

0 Votes 0 ·
DanielZhang-MSFT avatar image DanielZhang-MSFT MRUTYUNJAYAMAHAPATRA-6389 ·

Hi @MRUTYUNJAYAMAHAPATRA-6389,
About some properties and methods of ToolStripMenuItem, please refer to this document.
Best Regards,
Daniel Zhang


0 Votes 0 ·

0 Answers