How to add a menu to a C# windows app

P

paulotuatail

Hi. I would like to add a simple menu to my app. For starters the simple Help -> about my app with copy write info. I take it this is a pop up form?

TIA

Desmond.
 
A

Arne Vajhøj

Hi. I would like to add a simple menu to my app. For starters the
simple Help -> about my app with copy write info. I take it this is a
pop up form?

Win forms or WPF?

For win forms see the code snippet below.

Arne

====

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace E
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
MainMenu mm = new MainMenu();
MenuItem ma = new MenuItem("A");
MenuItem ma1 = new MenuItem("A1");
MenuItem ma1a = new MenuItem("A1a");
ma1.MenuItems.Add(ma1a);
MenuItem ma1b = new MenuItem("A1b");
ma1.MenuItems.Add(ma1b);
ma.MenuItems.Add(ma1);
MenuItem ma2 = new MenuItem("A2");
ma.MenuItems.Add(ma2);
mm.MenuItems.Add(ma);
MenuItem mb = new MenuItem("B");
MenuItem mb1 = new MenuItem("B1");
MenuItem mb1a = new MenuItem("B1a");
mb1.MenuItems.Add(mb1a);
MenuItem mb1b = new MenuItem("B1b");
mb1.MenuItems.Add(mb1b);
mb.MenuItems.Add(mb1);
MenuItem mb2 = new MenuItem("B2");
mb.MenuItems.Add(mb2);
mm.MenuItems.Add(mb);
this.Menu = mm;
}
}
}
 
A

Arne Vajhøj

[...]
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
MainMenu mm = new MainMenu(); [...]

Note that MainMenu is unofficially deprecated in favor of the newer
MenuStrip functionality.

Not that any of the Windows Forms API is really anything other than
backward-compatibility at this point, but a MenuStrip-based menu is
technically the "more current" paradigm to use in .NET.

OK.

I am not really that much into Win Forms.
And of course, whichever one uses, it's easier to configure the menu in the
Designer itself, rather than hard-coding everything in the constructor.

The designer generate similar "hard coded" code.

Arne
 
P

paulotuatail

Depends on the kind of menu and what you're using for your GUI. If you're

actually using the System.Windows.Forms objects (as your posts seem to

imply), then you're looking the MenuStrip control in the VS Designer

Toolbox. Once you've dragged that to the window, then you can start adding

menu commands just by clicking in the MenuStrip at the appropriate places.



By the way, note that for Windows Forms applications, when you use the "Add

New Item" dialog, there's an "About Box" type (found in the "Windows Forms"

category) that automatically populates itself with information in your

application properties.



Pete

Hi thanks for this. I have located the Menu Stip. I have added a help -> about.
I wanted to have a pop up similar to Windows About Windows.

I was looking into adding another item that would bring up some instructions. I went to Add file and it allowed me to add a html file but this does not apear in the solution box.

The simple code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CompIntCalculator
{

public partial class Calculator : Form
{

public void AddMenu()
{
MainMenu mnuFileMenu = new MainMenu();
this.Menu = mnuFileMenu;
MenuItem myMenuItemFile = new MenuItem("&File");
MenuItem myMenuItemNew = new MenuItem("&New");

}

public Calculator()
{
InitializeComponent();
txtInterest.Text = "1.382";
txtInitial.Text = "1000";
txtMonths.Text = "12";

}

private void cmdCalculate_Click(object sender, EventArgs e)
{
decimal cInitial;
decimal cCurrent;
decimal val;
int counter;

cInitial = decimal.Parse(txtInitial.Text);
cCurrent = cInitial;

val = (decimal.Parse(txtInterest.Text) / 100) + 1;

for (counter = 0; counter < int.Parse(txtMonths.Text); counter++)
{
cCurrent = cCurrent * val;
}

cCurrent = cCurrent - cInitial;
txtResult.Text = cCurrent.ToString("#,###0.00");

}

private void Help_MenuItem_Click(object sender, EventArgs e)
{

}

private void About_MenuItem_Click(object sender, EventArgs e)
{

}

private void Calculator_Load(object sender, EventArgs e)
{

}

}
}

Any help on bringing this to life would be apreciated. Has this got to be an MDI for the pop up window?


TIA

Desmond.
 
P

paulotuatail

Hi. I would like to add a simple menu to my app. For starters the simple Help -> about my app with copy write info. I take it this is a pop up form?



TIA



Desmond.

++++++++++++++

Ok I am getting closer now. Some of thouse google websites are rubbish. I have an about box: AboutInterest.cs and a html page: Support.html
I added the L on the end as i like that way. So to the very few problems

1) When I run the program I get the default about box from Microsoft which is strange.
2) I would like to position the About box ofset by 50 pixels so tha app can be slightly visible. Problems with .Right propery here
3) I would like to pop ub the html instructions preferably resizing and positioning th browser.

Thanks for all your help here. I wrote this originaly in VB^ and it worked fine. Here is the code section I need help with

Thanks

private void About_MenuItem_Click(object sender, EventArgs e)
{
Form frm = new AboutInterest();
//int x = (this).Left;
//int y = (this).Right;
frm.Left = (this).Left + 50;
//frm.Right = (this).Right + 50; // Doesn't like this line?
frm.ShowDialog(this);
}

private void instructions_MenuItem_Click(object sender, EventArgs e)
{
// HtmlDocument h = new HtmlDocument();
}

Desmond.
 
A

Arne Vajhøj

Ok I am getting closer now. Some of thouse google websites are rubbish. I have an about box: AboutInterest.cs and a html page: Support.html
I added the L on the end as i like that way. So to the very few problems

1) When I run the program I get the default about box from Microsoft which is strange.
2) I would like to position the About box ofset by 50 pixels so tha app can be slightly visible. Problems with .Right propery here
3) I would like to pop ub the html instructions preferably resizing and positioning th browser.

Thanks for all your help here. I wrote this originaly in VB^ and it worked fine. Here is the code section I need help with

Thanks

private void About_MenuItem_Click(object sender, EventArgs e)
{
Form frm = new AboutInterest();
//int x = (this).Left;
//int y = (this).Right;
frm.Left = (this).Left + 50;
//frm.Right = (this).Right + 50; // Doesn't like this line?

What does "Doesn't like this line" mean?
frm.ShowDialog(this);
}

Arne
 
A

Arne Vajhøj

Yes, true it does. I'm not saying the code itself is different. It's just
easier to "write" the code via the Designer than to do it all by hand.

It is definitely very widely used in win forms.

And it is certainly easier for the simpler usage. I am not
fully convinced that it is faster for non simple usage.

Arne
 
P

paulotuatail

Hi. I would like to add a simple menu to my app. For starters the simple Help -> about my app with copy write info. I take it this is a pop up form?



TIA



Desmond.

Hi
I just want help with this code fragment to open up MY about box when I click on the menu item About. It wants to pop up the microsoft one.

I want to open up a html page in IE or whatever browser when I click on theInstructions drop down menu.

What does "Doesn't like this line" mean?
frm.ShowDialog(this);

I changed this line to
frm.ShowDialog();

But this brings up the Microsoft About dialog box
Copywrite © Microsoft 2012
Microsoft


I am a newby to this please understand. I have a drop down menu
Help
About
Instructions

TIA

Desmond.



frm.Right = (this).Right + 50; // Doesn't like this line?
// Error 1 Property or indexer 'System.Windows.Forms.Control.Right' cannot be assigned to -- it is read only G:\Vb Apps.Net\CompundInterestCalculator\Calculator.cs 67 13 CompIntCalculator


Code:
private void About_MenuItem_Click(object sender, EventArgs e)
{
Form frm = new AboutInterest();
//int x = (this).Left;
//int y = (this).Right;
frm.Left = (this).Left + 50;
frm.Right = (this).Right + 50;  // Doesn't like this line?
frm.ShowDialog();
}

private void instructions_MenuItem_Click(object sender, EventArgs e)
{
// HtmlDocument h = new HtmlDocument();
}
 
A

Arne Vajhøj

frm.Right = (this).Right + 50; // Doesn't like this line?
# What does "Doesn't like this line" mean?
I am a newby to this please understand.

You will not get anywhere unless you learn to describe
the problems precisely (compile error with exact error
message, runtime error with exact error message,
unexpected behavior with explanation of expected and
actual behavior).

Arne
 
A

Arne Vajhøj

I don't know what you consider the dividing line between "simpler" and "non
simple" usage. But I can tell you that I've never had to code a
non-dynamic menu in Windows Forms that would have been faster to do by hand
than to just configure it in the Designer.

How do you tell the designer to use the result from a method to generate
a menu?
But regardless, I think it's safe to assume that the OP is interested in
"simpler" usage, and so it makes more sense to focus answers with that in
mind.

You may want to limit information provided to OP to what you assume OP
is interested in and completely ignore the possibility of other than OP
reading.

But I don't.

Arne
 
A

Arne Vajhøj

[...]
I don't know what you consider the dividing line between "simpler" and "non
simple" usage. But I can tell you that I've never had to code a
non-dynamic menu in Windows Forms that would have been faster to do by hand
than to just configure it in the Designer.

How do you tell the designer to use the result from a method to generate
a menu?

<sigh>

What do you think I mean by "non-dynamic"?

Something that would make your statement relevant maybe.

There were already agreement about the simple cases.
Whatever.

I didn't _assume_ anything about what the OP is interested in.

So "I think it's safe to assume that the OP is interested in" is
not "_assume_ anything about what the OP is interested in".

You certainly fooled me with that one.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top