By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

position of controls on the form

100+
P: 153
I am making one form by hand (without vs 2005).
i am positioning the menustrip above the toolstrip but still bue to some reason the menu strip is below it.

I inseted breakpoint and when the code goes through this
the data is
MainMenu.Location = {X = 0 Y = 25}
OneToolStrip.Location = {X = 0 Y = 0}

why is this happening ?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5.  
  6. namespace Consolepractice
  7. {
  8.     class MyForm : Form
  9.     {
  10.         MenuStrip MainMenu;
  11.  
  12.         ToolStripMenuItem MainMenuItemfile;
  13.         ToolStripMenuItem Itemsave;
  14.         ToolStripMenuItem ItemSaveAs;
  15.  
  16.         ToolStripMenuItem MainMenuItemEdit;
  17.  
  18.         ContextMenuStrip MainContextMenu;
  19.         ToolStripMenuItem MainContextMenuCopy;
  20.         ToolStripMenuItem MainContextMenuItemCut;
  21.         ToolStripMenuItem MainContextMenuItemPaste;
  22.  
  23.         Button OneButton;
  24.  
  25.         ToolStrip OneToolStrip;
  26.         ToolStripButton OneTSButton;
  27.         public MyForm()
  28.         {
  29.             initialisecomponents();
  30.             Application.EnableVisualStyles();
  31.         }
  32.  
  33.         void initialisecomponents()
  34.         {
  35.             MainMenu = new MenuStrip();
  36.                 MainMenuItemfile = new ToolStripMenuItem();
  37.                     Itemsave = new ToolStripMenuItem();
  38.                     ItemSaveAs = new ToolStripMenuItem();
  39.                 MainMenuItemEdit = new ToolStripMenuItem();
  40.             MainContextMenu = new ContextMenuStrip();
  41.                 MainContextMenuItemCut = new ToolStripMenuItem();
  42.                 MainContextMenuCopy = new ToolStripMenuItem();
  43.                 MainContextMenuItemPaste = new ToolStripMenuItem();
  44.  
  45.             OneButton = new Button();
  46.  
  47.             OneToolStrip = new ToolStrip();
  48.             OneTSButton = new ToolStripButton();
  49.  
  50.  
  51.             this.MainMenuStrip = MainMenu;
  52.             this.Text = "Hand made form !";
  53.             this.Text = "Main menu:" + MainMenu.Location.ToString() + " toolstrip" + OneToolStrip.Location.ToString();
  54.             this.ContextMenuStrip = MainContextMenu;
  55.             //this.Controls.Add(ContextMenu); (Dont need to "add" a contextmenu !)
  56.             this.Controls.Add(MainMenu);
  57.             this.Controls.Add(OneButton);
  58.             this.Controls.Add(OneToolStrip);
  59.  
  60.             MainMenuItemfile.Text = "File";
  61.             MainMenuItemfile.Size= new System.Drawing.Size(152, 22);
  62.             MainMenuItemfile.DropDownItems.Add(Itemsave);
  63.             MainMenuItemfile.DropDownItems.Add(ItemSaveAs);
  64.  
  65.                 Itemsave.Text = "Save";
  66.                 Itemsave.Size = new System.Drawing.Size(152, 22); ;
  67.  
  68.                 ItemSaveAs.Text = "Save as";
  69.                 ItemSaveAs.Size = new System.Drawing.Size(152, 22);
  70.  
  71.             MainMenuItemEdit.Text = "Edit";
  72.             MainMenuItemEdit.Size = new System.Drawing.Size(152, 22);
  73.  
  74.             MainContextMenu.Size = new System.Drawing.Size(114, 26);
  75.             MainContextMenu.Items.Add(MainContextMenuItemCut);
  76.             MainContextMenu.Items.Add(MainContextMenuCopy);
  77.             MainContextMenu.Items.Add(MainContextMenuItemPaste);
  78.  
  79.             MainContextMenuCopy.Size = new System.Drawing.Size(113, 22);
  80.             MainContextMenuCopy.Text = "Copy";
  81.  
  82.             MainContextMenuItemCut.Size = new System.Drawing.Size(113, 22);
  83.             MainContextMenuItemCut.Text = "Cut";
  84.  
  85.             MainContextMenuItemPaste.Size = new System.Drawing.Size(113, 22);
  86.             MainContextMenuItemPaste.Text = "Paste";
  87.  
  88.             MainMenu.Items.Add(MainMenuItemfile);
  89.             MainMenu.Items.Add(MainMenuItemEdit);
  90.             MainMenu.Location = new System.Drawing.Point(0, 0);
  91.  
  92.             OneButton.Text = "Click me !";
  93.             OneButton.Size = new System.Drawing.Size(75, 23);
  94.             OneButton.Location = new System.Drawing.Point(10,0);
  95.  
  96.             OneToolStrip.Items.Add(OneTSButton);
  97.             OneToolStrip.Text = "Hey !";
  98.             OneToolStrip.Location = new System.Drawing.Point(0, 55);
  99.  
  100.             OneTSButton.Text = "Click me too !";
  101.  
  102.  
  103.         }
  104.     }
  105.  
  106.     class Program
  107.     {
  108.         static void Main(string[] args)
  109.         {
  110.             MyForm frm = new MyForm();
  111.             Application.Run(frm);
  112.         }
  113.     }
  114. }
Dec 4 '08 #1
Share this Question
Share on Google+
7 Replies


100+
P: 153
Now i have added two buttons one of which increases the postion of menustrip and other of toolstrip.

But these buttons fail to change their location !
it seems as if they come down but again go to original position.
Dec 4 '08 #2

Plater
Expert 5K+
P: 7,872
Well a menu strip by definition is "docked" to its parent control I believe.
Try putting it in a panel and then moving the panel around?
Dec 4 '08 #3

100+
P: 153
I dont want to move anything.
I just want to have menustrip at top and below it the toolstrip.
How to do that ?
Dec 5 '08 #4

P: 5
Hi Akshay,

Every control will have bring to front property try that may be it will work.

Uday
Dec 5 '08 #5

100+
P: 153
I am asking why the menustrip is not positioned at the top ?
Where am i wrong ?
Dec 5 '08 #6

Plater
Expert 5K+
P: 7,872
You have a lot of positioning out of whack in there. Your regular button covers your tooltip button.
You know you can use the designer to place everything where you want it, then open the designer code and see how they did it.

The menu strip IS at the top, its just covered by the toolstrip.
Just put in this:
OneToolStrip.Dock = DockStyle.None;
Dec 5 '08 #7

vekipeki
Expert 100+
P: 229
Oops, I made a mistake, never mind.
Dec 24 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.