open a men without a click

E

Ernst Sauer

Hello,

I have a Windows-Forms-Appl.
When I start my program I want to show me the open
menu-list for lets say the menu Job, without clicking
on the menu button Job.

Something like

public Form1()
{ ...
Job.ShowDropDown(); // did not work
}

Thanks
Ernst
 
A

Arne Vajhøj

I have a Windows-Forms-Appl.
When I start my program I want to show me the open
menu-list for lets say the menu Job, without clicking
on the menu button Job.

Something like

public Form1()
{ ...
Job.ShowDropDown(); // did not work
}

Try:

this.GotFocus += delegate(object sender, EventArgs e) {
Job.ShowDropDown(); };

Arne
 
B

bradbury9

El sábado, 24 de noviembre de 2012 18:39:20 UTC+1, Ernst Sauer escribió:
Hello,



I have a Windows-Forms-Appl.

When I start my program I want to show me the open

menu-list for lets say the menu Job, without clicking

on the menu button Job.



Something like



public Form1()

{ ...

Job.ShowDropDown(); // did not work

}



Thanks

Ernst

The reason why it did not work is that the code was in the constructor, before all controls are being initialized and when the Form still has no focus.. Check Arne's response to see when should be put that code.
 
E

Ernst Sauer

Am 24.11.2012 23:43, schrieb Arne Vajhøj:
Try:

this.GotFocus += delegate(object sender, EventArgs e) {
Job.ShowDropDown(); };

Great, thanks,
can you explain this a little bit?

Ernst
 
A

Arne Vajhøj

Am 24.11.2012 23:43, schrieb Arne Vajhøj:

Great, thanks,
can you explain this a little bit?

Instead of calling ShowDropDown in the form constructor - it
is called when the form get focused.

Either it is not ready to show the menu in the constructor
or something gets rid of it again after the constructor call.

Focus event seems to work. Note that there may be other places
to put it than the focus event that fits your specific needs
better. But you definitely need to do it after the constructor.

Arne
 
B

bradbury9

El domingo, 25 de noviembre de 2012 15:23:22 UTC+1, Arne Vajhøj escribió:
Instead of calling ShowDropDown in the form constructor - it

is called when the form get focused.



Either it is not ready to show the menu in the constructor

or something gets rid of it again after the constructor call.



Focus event seems to work. Note that there may be other places

to put it than the focus event that fits your specific needs

better. But you definitely need to do it after the constructor.



Arne

In the form InitializeComponent() method, witch is called after the constructor, the menu is being filled with the submenu items, so any call must be done after the InitializeComponent method is called. This is a sample code of the autogenerated code of one app using the MenuStrip.

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
..... lots of code ....

this.barraMenus = new System.Windows.Forms.MenuStrip();
..... lots of code ....
//
// barraMenus
//
this.barraMenus.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuSalir,
this.mnuGuardar,
this.mnuCambioDepartamento,
this.mnuAjustar,
this.cbCambioEstado});


That's the reason the code Ernst posted does not work in the constructor. It should be put in one of the Form events and, as Arne suggested, The Form_Focus is a good choice.
 

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