I'm trying to hide tab headers in the tabControl, like it's shown here in this link, but I am getting an error in the designer's code. Once I change both lines, I get this:
Severity Code Description Project File Line
Message The designer cannot process unknown name 'SelectedIndex' at line 43. The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. c:\users\krzysztof\documents\visual studio 2015\Projects\DaneUzytkownika3\DaneUzytkownika3\TabController.Designer.cs 44
Severity Code Description Project File Line
Error CS1061 'TabController' does not contain a definition for 'SelectedIndex' and no extension method 'SelectedIndex' accepting a first argument of type 'TabController' could be found (are you missing a using directive or an assembly reference?) DaneUzytkownika3 c:\users\krzysztof\documents\visual studio 2015\Projects\DaneUzytkownika3\DaneUzytkownika3\TabController.Designer.cs 43
Line 43 in the designer's code of the form is:
this.tabControl1.SelectedIndex = 0;
Could someone please tell me, how do I fix it?
TablessTabControl.cs
namespace hiding
{
class TablessTabControl : Form1
{
protected override void WndProc(ref Message m)
{
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode)
m.Result = (IntPtr)1;
else
base.WndProc(ref m);
}
}
}
Form1.Designer.cs
namespace hiding
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tabControl1 = new TablessTabControl();
//this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(31, 12);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;//line with the error
this.tabControl1.Size = new System.Drawing.Size(200, 100);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(192, 74);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(192, 74);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private TablessTabControl tabControl1;
//private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
}
}
I have created a project and implemented the tab control as given in your example as follows:
class TablessTabControl : TabControl
{
protected override void WndProc(ref Message m)
{
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode)
m.Result = (IntPtr)1;
else
base.WndProc(ref m);
}
}
Then upon rebuilding the project I add my new TablessTabControl to a test form using the designer. Within the designer, I can switch between the tabs using the visible headers.
At runtime, the headers disappear as intended. I have two tabs; I am able to select between the tabs by using the following code:
// Selects the first tab:
tablessTabControl1.SelectedIndex = 0;
// Selects the second tab:
tablessTabControl1.SelectedIndex = 1;
Additionally, in Form1.Designer.cs, I have line 48 as follows:
this.tablessTabControl1.SelectedIndex = 0;
which poses no difficulty for me.
Have you tried closing all documents, cleaning the solution, rebuilding and reopening the designer?
Related
For instance, if there is a push button, when the user press the button, the system should detect and record the time in dd-mm-yy. However, if the user press the button many time in 2 second, the system should only record the first time when the user press the button.
Assumption: you want to collect clicks but no more often than every 2 seconds. This simple form will do it.
Code:
namespace RecordClicks {
public partial class Form1 : Form {
private DateTime _recordedClick = DateTime.MinValue;
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
DateTime currentClickTime = DateTime.Now;
if (currentClickTime.Subtract(_recordedClick).TotalMilliseconds > 2000 ) {
_recordedClick = currentClickTime;
lblClick.Text = currentClickTime.ToString();
// TODO: add code to record this click
}
}
}
}
Designer:
namespace RecordClicks {
partial class Form1 {
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.lblClick = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(121, 241);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(132, 53);
this.button1.TabIndex = 0;
this.button1.Text = "Clicker";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// lblClick
//
this.lblClick.AutoSize = true;
this.lblClick.Font = new System.Drawing.Font("Segoe UI", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.lblClick.Location = new System.Drawing.Point(121, 127);
this.lblClick.Name = "lblClick";
this.lblClick.Size = new System.Drawing.Size(90, 45);
this.lblClick.TabIndex = 1;
this.lblClick.Text = "Time";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.lblClick);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Clicker Test";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button button1;
private Label lblClick;
}
}
Whereas MSDN suggests that some incompatible behavior might also cause this issue
In my case, The incompatible behavior is caused by some possibly weird(messed up mappings) on Entity Framework.
I have done due diligence to ensure one-to-one correspondence between the data model and the EF model(even recreated it twice, ground up)
The project builds and runs when I comment out a certain section of code.
public partial class TestForm : SecureForm
{
private myEntities _db = new myEntities();
public TestForm()
{
InitializeComponent();
PopulateTestsList();
}
private void PopulateTestsList()
{
listViewTypes.Items.Clear();
var query = from q in _db.Types orderby q.TypeName select q;
foreach (Type dt in query)
{
ListViewItem lvi = new ListViewItem(new string[]
{
dt.TypeName
});
lvi.Tag = dt;
listViewTypes.Items.Add(lvi);
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
TestEditForm myEditForm = new TestEditForm(_db);
if (myEditForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
PopulateTestsList();
}
private void buttonEdit_Click(object sender, EventArgs e)
{
if (listViewTypes.SelectedItems.Count > 0)
{
Test tsdt = listViewTypes.SelectedItems[0].Tag as Test;
if (myEditForm != null)
{
TestEditForm myEditForm = new TestEditForm(_db, mysForm);
if (myEditForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
PopulateTestsList();
}
}
}
}
It still does not show up the designer.
Here's the designer.cs for reference
partial class TestForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.listViewTypes = new System.Windows.Forms.ListView();
this.columnName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(304, 86);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(75, 23);
this.buttonDelete.TabIndex = 9;
this.buttonDelete.Text = "Delete";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(304, 56);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(75, 23);
this.buttonEdit.TabIndex = 8;
this.buttonEdit.Text = "Edit";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(304, 26);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(75, 23);
this.buttonAdd.TabIndex = 7;
this.buttonAdd.Text = "Add";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
//
// listViewTypes
//
this.listViewTypes.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnName});
this.listViewTypes.FullRowSelect = true;
this.listViewTypes.HideSelection = false;
this.listViewTypes.Location = new System.Drawing.Point(12, 26);
this.listViewTypes.Name = "listViewTypes";
this.listViewTypes.Size = new System.Drawing.Size(274, 205);
this.listViewTypes.TabIndex = 6;
this.listViewTypes.UseCompatibleStateImageBehavior = false;
this.listViewTypes.View = System.Windows.Forms.View.Details;
//
// columnName
//
this.columnName.Text = "Document Type";
this.columnName.Width = 270;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(79, 13);
this.label1.TabIndex = 5;
this.label1.Text = "Test Standards";
//
// TestsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(395, 242);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.listViewTypes);
this.Controls.Add(this.label1);
this.Name = "TestsForm";
this.Opacity = 1D;
this.Text = "Test Standards";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button buttonDelete;
private System.Windows.Forms.Button buttonEdit;
private System.Windows.Forms.Button buttonAdd;
private System.Windows.Forms.ListView listViewTypes;
private System.Windows.Forms.ColumnHeader columnName;
private System.Windows.Forms.Label label1;
}
Code analysis shows that the form is missing,(MSBuild does not). MSBUILD compiles the form into an exe thats kinda defunct(on the broken entity)
The entity in question has Name & ID properties. Both Name and ID are mapped properly, The collection is pluralized and loaded into a list.
How to identify the broken entity and/or
How to Identify the non-compatible behavior in the code
I have an issue with C# richtextbox and Microsoft equation editor. My goal is to read, modify and save changes in rtf file.
I followed tutorial below:
C# Tutorial : How to insert Math Equation to RichTextBox | FoxLearn
I can read and modify equation in editor, however I can't update richtextbox after modification, modified value is not changed in richtboxtext.
Initial state
Modification
Update(F3) and exit in equation editor doesn't cause change in richtextbox.
However when I double click equation in editor there is changed value.
Here is my code:
using System;
using System.Windows.Forms;
namespace Panel.Views
{
public partial class Axis : Form
{
public Axis()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectedRtf = Panel.Properties.Resources.Plot1_x_axis;
}
}
}
namespace Panel.Views
{
partial class Axis
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(723, 431);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(28, 36);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(770, 372);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "";
//
// Axis
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(822, 478);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button1);
this.Name = "Axis";
this.Text = "Axis";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
I would be appreciated for any help, hints or suggestions how to solve this issue.
Thank you in advance.
I am developing a windows forms application for Windows Mobile 6 in Visual Studio 2008. There is a requirement to have some common controls on each form, such as Logo (PictureBox), Title (Label) and a small description (also Label). I decided to make a FormBase with those controls and inherit other forms from that base.
The problem is that for some reason, when I drop a Button or another control on that inherited form, I cannot resize it with my mouse. I can press Shift+Arrow to resize anything with my keyboard shortcuts, but the mouse does not work.
It's not very convenient neither for me nor for other developers in my team.
Any suggestions?
Update 1
the base form:
public class FormBase : Form
{
public FormBase()
{
InitializeComponent();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBase));
this.pictureLogo = new System.Windows.Forms.PictureBox();
this.labelTitle = new System.Windows.Forms.Label();
this.panelSeparator = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// pictureLogo
//
this.pictureLogo.Image = ((System.Drawing.Image)(resources.GetObject("pictureLogo.Image")));
this.pictureLogo.Location = new System.Drawing.Point(0, 0);
this.pictureLogo.Name = "pictureLogo";
this.pictureLogo.Size = new System.Drawing.Size(48, 48);
//
// labelTitle
//
this.labelTitle.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Bold);
this.labelTitle.ForeColor = System.Drawing.Color.Black;
this.labelTitle.Location = new System.Drawing.Point(54, 2);
this.labelTitle.Name = "labelTitle";
this.labelTitle.Size = new System.Drawing.Size(183, 16);
this.labelTitle.Text = "Title";
//
// panelSeparator
//
this.panelSeparator.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panelSeparator.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(35)))), ((int)(((byte)(44)))), ((int)(((byte)(75)))));
this.panelSeparator.Location = new System.Drawing.Point(3, 50);
this.panelSeparator.Name = "panelSeparator";
this.panelSeparator.Size = new System.Drawing.Size(234, 1);
//
// FormBase
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 320);
this.ControlBox = false;
this.Controls.Add(this.panelSeparator);
this.Controls.Add(this.labelTitle);
this.Controls.Add(this.pictureLogo);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.KeyPreview = true;
this.Location = new System.Drawing.Point(0, 0);
this.MinimizeBox = false;
this.Name = "FormBase";
this.Text = "FormBase";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureLogo;
private System.Windows.Forms.Label labelTitle;
private System.Windows.Forms.Panel panelSeparator;
}
the inherited form:
public class FrontDoorForm : FormBase
{
public FrontDoorForm()
{
InitializeComponent();
}
private void buttonQuit_Click(object sender, EventArgs e)
{
Close();
}
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonQuit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// buttonQuit
//
this.buttonQuit.Location = new System.Drawing.Point(3, 54);
this.buttonQuit.Name = "buttonQuit";
this.buttonQuit.Size = new System.Drawing.Size(115, 46);
this.buttonQuit.TabIndex = 2;
this.buttonQuit.Text = "Quit";
this.buttonQuit.Click += new System.EventHandler(this.buttonQuit_Click);
//
// FrontDoorForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(240, 320);
this.Controls.Add(this.buttonQuit);
this.Font = new System.Drawing.Font("Tahoma", 10F, System.Drawing.FontStyle.Regular);
this.ForeColor = System.Drawing.Color.Black;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Location = new System.Drawing.Point(0, 0);
this.MinimizeBox = true;
this.Name = "FrontDoorForm";
this.Text = "FrontDoorForm";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Controls.SetChildIndex(this.buttonQuit, 0);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button buttonQuit;
}
Just to close the question I will quote the answer from the comment:
Change the base form's WindowState back to Normal for a workaround. You can still get it Maximized in the derived form. Hans Passant
I have been writing a lot of code in Java and find that it is really easy to create either a console or form application. In fact, all one has to do is add a form and display that form. Simple as a cookie, so to speak. But now I have a big project coming up in Visual C# and I have not used it all that much. I think, I am not sure if I am right, but a console application is C# is just that, a console application which cannot accept any mouse action events. I want to be able to add controls to C# from inside of the form, just like in Java. Add a button, or add a menu. But in C# there are several files that open, properties, assemblyinfo.cs, form1.cs, etc. The code below is in form designer.cs.
So where is the best way to add components from the programming point of view and not the design visual stand point of view?
namespace WindowsFormsTestMenuApplication
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.openToolStripMenuItem,
this.optionsToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(284, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aToolStripMenuItem,
this.bToolStripMenuItem,
this.cToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
this.openToolStripMenuItem.Text = "Open";
//
// optionsToolStripMenuItem
//
this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem";
this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20);
this.optionsToolStripMenuItem.Text = "Options";
//
// aToolStripMenuItem
//
this.aToolStripMenuItem.Name = "aToolStripMenuItem";
this.aToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aToolStripMenuItem.Text = "A";
//
// bToolStripMenuItem
//
this.bToolStripMenuItem.Name = "bToolStripMenuItem";
this.bToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.bToolStripMenuItem.Text = "B";
//
// cToolStripMenuItem
//
this.cToolStripMenuItem.Name = "cToolStripMenuItem";
this.cToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.cToolStripMenuItem.Text = "C";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem aToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem cToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem;
}
}
Sounds somehow like a general design/approach question to me.
Why don't you use WPF over WinForms? Gives you a quite handy designer in Visual Studio. You can comfortably build your GUI in WYSIWYG-style. Supports data binding, which - once familiar with - is pretty convenient.
However, later you can still add controls etc. at runtime, see Breems answer.
Note: If you use WPF, you need to use the Windows's dispatcher if you want to add controls from another thread than the Windows's one.
Are you trying to add controls at runtime? If so, as SLaks stated, you will simply need to create a new instance of the control and add it to your form.
// Add a menustrip to the form.
MenuStrip menuStrip = new MenuStrip();
menuStrip.Dock = DockStyle.Top;
this.Controls.Add(menuStrip);
Otherwise, why not utilize the visual designer to add controls to your form?
WinForms controls are regular objects, just like AWT or Swing.
You can create a new ToolStripItem(), set its properties, then add it to a DropDownItems collection.