P
.pd.
Hello,
I've got a Form with a MainMenu and a Panel. I want the panel to appear
just above the MainMenu bar at the bottom of the form so I set the
Location. This works fine.
If I add a Toolbar to the form, the panel doesn't appear. BUT - if I
stick a button on the Form and have the click event set the location to
the same exact place it then appears.
Can anyone explain this or tell me how to fix it?
Thanks for any help,
..pd.
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace MenuHidesControl
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.ToolBar toolBar1;
Panel p;
public Form1()
{
InitializeComponent();
Button b = new Button();
b.Location = new Point(20, 20);
this.Controls.Add(b);
b.Text = "Dock";
b.Click += new EventHandler(b_Click);
/* the red panel appears in the centre just above the menu bar
* but when a toolbar is added, the panel doesn't appear until
* the "Dock" button is clicked. but Dock click event positions
* panel in exactly the same place as the constructor.
*
* huh?
*/
p = new Panel();
p.Size = new Size(128,20);
p.BackColor = Color.Red;
p.Location = new Point((this.Width - p.Width) / 2,
this.Height - p.Height);
this.Controls.Add(p);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.mainMenu1.MenuItems.Add(this.menuItem1);
this.mainMenu1.MenuItems.Add(this.menuItem2);
this.mainMenu1.MenuItems.Add(this.menuItem3);
this.mainMenu1.MenuItems.Add(this.menuItem4);
this.mainMenu1.MenuItems.Add(this.menuItem5);
this.menuItem1.Text = "one";
this.menuItem2.Text = "two";
this.menuItem3.Text = "three";
this.menuItem4.Text = "four";
this.menuItem5.Text = "five";
this.Controls.Add(this.toolBar1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void b_Click(object sender, EventArgs e)
{
p.Location = new Point((this.Width - p.Width) / 2,
this.Height - p.Height);
}
}
}
I've got a Form with a MainMenu and a Panel. I want the panel to appear
just above the MainMenu bar at the bottom of the form so I set the
Location. This works fine.
If I add a Toolbar to the form, the panel doesn't appear. BUT - if I
stick a button on the Form and have the click event set the location to
the same exact place it then appears.
Can anyone explain this or tell me how to fix it?
Thanks for any help,
..pd.
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace MenuHidesControl
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.ToolBar toolBar1;
Panel p;
public Form1()
{
InitializeComponent();
Button b = new Button();
b.Location = new Point(20, 20);
this.Controls.Add(b);
b.Text = "Dock";
b.Click += new EventHandler(b_Click);
/* the red panel appears in the centre just above the menu bar
* but when a toolbar is added, the panel doesn't appear until
* the "Dock" button is clicked. but Dock click event positions
* panel in exactly the same place as the constructor.
*
* huh?
*/
p = new Panel();
p.Size = new Size(128,20);
p.BackColor = Color.Red;
p.Location = new Point((this.Width - p.Width) / 2,
this.Height - p.Height);
this.Controls.Add(p);
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.mainMenu1.MenuItems.Add(this.menuItem1);
this.mainMenu1.MenuItems.Add(this.menuItem2);
this.mainMenu1.MenuItems.Add(this.menuItem3);
this.mainMenu1.MenuItems.Add(this.menuItem4);
this.mainMenu1.MenuItems.Add(this.menuItem5);
this.menuItem1.Text = "one";
this.menuItem2.Text = "two";
this.menuItem3.Text = "three";
this.menuItem4.Text = "four";
this.menuItem5.Text = "five";
this.Controls.Add(this.toolBar1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void b_Click(object sender, EventArgs e)
{
p.Location = new Point((this.Width - p.Width) / 2,
this.Height - p.Height);
}
}
}