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.