1

I have inherited some C# source code written in Visual Studio 2010 targeting the .NET 2.0 framework. It comprises a simple Windows Forms application with a single form as its user interface.

The form contains a number of menu items, one of which allows the user to preview an image (acquired from a camera). An example of the program output is shown below, with the dark rectangle being the image.

NET2 Windows Form (VS 2010)

I wish to rewrite the application from scratch for the .NET 4.6.2 Framework using Visual Studio 2019.

Recreating the form is straightforward. However, the component MenuItem used for .NET 2.0 in VS2010 has been replaced by MenuStrip and ToolStripMenuItem in VS2019. When I build the updated version of the application, I can't make the menu strip operate in the same way. My output looks as shown below when the application runs.

NET4.6.2 Windows Form (VS2019)

As you can see, the top level menus are accessible but not visible. How can I locate the workspace image below the MenuStrip?

I am hoping that the answer will be some MenuStrip setting in Visual Studio's 'Properties' dialog box that I have overlooked.

Here's how the Properties currently appear in Form1.Designer.cs:

        // mainMenu1
        // 
        this.mainMenu1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.menuFile,
        this.menuView,
        this.menuSet,
        this.menuDLL,
        this.menuDevice});
        this.mainMenu1.Location = new System.Drawing.Point(0, 0);
        this.mainMenu1.Name = "mainMenu1";
        this.mainMenu1.Size = new System.Drawing.Size(641, 24);
        this.mainMenu1.TabIndex = 0;
        this.mainMenu1.Text = "menuMenu1";
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
DB17
  • 23
  • 6
  • When you have to rebuild the GUI anyway, why not use WPF instead of the outdated WinForms. – Bent Tranberg Dec 30 '21 at 18:40
  • I'd prefer to stick with 4.6.2 on this occasion. – DB17 Dec 30 '21 at 23:22
  • If that was a reply to my comment, then it's a bit confusing. WPF and WinForms are both available on all .NET platforms, at least from v 3. – Bent Tranberg Dec 31 '21 at 06:09
  • To clarify, I am familiar with WinForms and prefer to stick with it at the moment rather than go through the learning curve for WPF. Appreciate your interest. Are you able to help with the question? – DB17 Dec 31 '21 at 16:35
  • I would be more interested to see the designer code for the image than the menu code. My theory is as follows. The image is placed at position 0,0 just like the main menu. The image then covers the menu bar. That's why you don't see the menu bar in the screenshot. Place the image farther down, and the menu bar will probably appear. In my experience menu drop downs are placed above all other contents, so that's why you still see that. – Bent Tranberg Dec 31 '21 at 20:18
  • MainMenu works fundamentally different from MenuStrip, it reduces the client area of the window. The code you interop with thinks the entire client area is available, thus overlapping the MenuStrip. Simplest solution is to just keep using MainMenu. Right-click the toolbox and select Choose Items, tick "MainMenu" to add it to the toolbox. – Hans Passant Jan 04 '22 at 21:30
  • "Simplest solution is to just keep using MainMenu" This would have been the best solution @HansPassant! Unfortunately, there is no MainMenu option in the Visual Studio 2019 Toolbox :( You have to choose MenuStrip. – DB17 Jan 08 '22 at 14:15
  • I explained how to add it to the toolbox. – Hans Passant Jan 08 '22 at 14:16
  • Working now, thank you. Can you add your solution as an answer so that I can select it? – DB17 Jan 08 '22 at 22:38

1 Answers1

0

For anyone who may be interested in this problem, I didn't solve it but managed to find a workaround by offsetting the image by +25 along the y-axis.

I didn't use the WinForm Properties to do this. The code that I have inherited uses a third party dll to create the preview. I'm not sure how the dll handles the window size and positioning but I think that it overrides any WinForm property that I try to apply.

Sorry that my answer doesn't help those looking to solve their own version of this problem.

DB17
  • 23
  • 6