Victorier програмно.. возьму пример, массив groupBox я пошел по варианту чисто программного решения, приведу как пример текст одной своей (работающей!) программы:
| Код | string[] sIps=ips.GetValueNames();
System.Windows.Forms.GroupBox[] frm_Host=new System.Windows.Forms.GroupBox[sIps.Length];// System.Windows.Forms.Label[] lblOutgoing = new System.Windows.Forms.Label[sIps.Length]; System.Windows.Forms.Label[] label1 = new System.Windows.Forms.Label[sIps.Length]; System.Windows.Forms.Label[] lblIngoing = new System.Windows.Forms.Label[sIps.Length]; System.Windows.Forms.Label[] lblStat = new System.Windows.Forms.Label[sIps.Length]; ColorProgressBar.ColorProgressBar[] pbIngoing = new ColorProgressBar.ColorProgressBar[sIps.Length], pbOutPlan = new ColorProgressBar.ColorProgressBar[sIps.Length], pbInPlan = new ColorProgressBar.ColorProgressBar[sIps.Length], pbOutgoing = new ColorProgressBar.ColorProgressBar[sIps.Length];
for(i=0;i<sIps.Length;i++) {////// frm_Host[i]=new System.Windows.Forms.GroupBox(); frm_Host[i].SuspendLayout(); frm_Host[i].Location=new Point(2,y); frm_Host[i].Size=new Size(this.Width-10,83); y+=85; frm_Host[i].Text=sIps[i]; frm_Host[i].Name = "Host"+sIps[i]; frm_Host[i].Anchor=(System.Windows.Forms.AnchorStyles.Top| System.Windows.Forms.AnchorStyles.Left| System.Windows.Forms.AnchorStyles.Right); frm_Host[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); frm_Host[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
#region Create Elements lblOutgoing[i] = new System.Windows.Forms.Label(); label1[i] = new System.Windows.Forms.Label(); lblIngoing[i]= new System.Windows.Forms.Label(); lblStat[i] = new System.Windows.Forms.Label(); pbIngoing[i] = new ColorProgressBar.ColorProgressBar(); pbOutPlan[i] = new ColorProgressBar.ColorProgressBar(); pbInPlan[i] = new ColorProgressBar.ColorProgressBar(); pbOutgoing[i] = new ColorProgressBar.ColorProgressBar(); // // // pbOutPlan // pbOutPlan[i].Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); pbOutPlan[i].BarColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192))); pbOutPlan[i].BorderColor = System.Drawing.Color.Transparent; pbOutPlan[i].FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Solid; pbOutPlan[i].Location = new System.Drawing.Point(83, 60); pbOutPlan[i].Maximum = 100; pbOutPlan[i].Minimum = 0; pbOutPlan[i].Name = "pbOutPlan"; pbOutPlan[i].Size = new System.Drawing.Size(this.Width-98, 4); pbOutPlan[i].Step = 10; pbOutPlan[i].TabIndex = 17; pbOutPlan[i].Value = 100; pbOutPlan[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); pbOutPlan[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
// // lblOutgoing // lblOutgoing[i].Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); lblOutgoing[i].ContextMenu = contextMenu1; lblOutgoing[i].Location = new System.Drawing.Point(3, 64); lblOutgoing[i].Name = "lblOutgoing"; lblOutgoing[i].Size = new System.Drawing.Size(this.Width-18, 16); lblOutgoing[i].TabIndex = 15; lblOutgoing[i].Text = "подождите..."; lblOutgoing[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter; lblOutgoing[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); lblOutgoing[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
// // pbOutgoing // pbOutgoing[i].Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); pbOutgoing[i].BarColor = System.Drawing.Color.Gold; pbOutgoing[i].BorderColor = System.Drawing.Color.Transparent; pbOutgoing[i].FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Solid; pbOutgoing[i].Location = new System.Drawing.Point(83, 48); pbOutgoing[i].Maximum = 100; pbOutgoing[i].Minimum = 0; pbOutgoing[i].Name = "pbOutgoing"; pbOutgoing[i].Size = new System.Drawing.Size(this.Width-98, 12); pbOutgoing[i].Step = 10; pbOutgoing[i].TabIndex = 14; pbOutgoing[i].Value = 100; pbOutgoing[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); pbOutgoing[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
// // label1 // label1[i].ContextMenu = contextMenu1; label1[i].Location = new System.Drawing.Point(3, 48); label1[i].Name = "label1"; label1[i].Size = new System.Drawing.Size(80, 16); label1[i].TabIndex = 13; label1[i].Text = "Исходящего: "; label1[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); label1[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
// // lblIngoing // lblIngoing[i].Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); lblIngoing[i].ContextMenu = contextMenu1; lblIngoing[i].Location = new System.Drawing.Point(3, 32); lblIngoing[i].Name = "lblIngoing"; lblIngoing[i].Size = new System.Drawing.Size(this.Width-18, 16); lblIngoing[i].TabIndex = 12; lblIngoing[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter; lblIngoing[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); lblIngoing[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
//lblIngoing[i].BorderStyle=System.Windows.Forms.BorderStyle.FixedSingle; // // pbInPlan // pbInPlan[i].Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); pbInPlan[i].BarColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(255)), ((System.Byte)(192))); pbInPlan[i].FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Solid; pbInPlan[i].Location = new System.Drawing.Point(83, 26); pbInPlan[i].Maximum = 100; pbInPlan[i].Minimum = 0; pbInPlan[i].Name = "pbInPlan"; pbInPlan[i].Size = new System.Drawing.Size(this.Width-98, 4); pbInPlan[i].Step = 10; pbInPlan[i].TabIndex = 16; pbInPlan[i].Value = 100; pbInPlan[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); pbInPlan[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
// // pbIngoing // pbIngoing[i].Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); pbIngoing[i].BarColor = System.Drawing.Color.Lime; pbIngoing[i].BorderColor = System.Drawing.Color.Transparent; pbIngoing[i].FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Solid; pbIngoing[i].Location = new System.Drawing.Point(83, 16); pbIngoing[i].Maximum = 100; pbIngoing[i].Minimum = 0; pbIngoing[i].Name = "pbIngoing"; pbIngoing[i].Size = new System.Drawing.Size(this.Width-98, 12); pbIngoing[i].Step = 10; pbIngoing[i].TabIndex = 11; pbIngoing[i].Value = 100; pbIngoing[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); pbIngoing[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
// // lblStat // lblStat[i].ContextMenu = contextMenu1; lblStat[i].Location = new System.Drawing.Point(3, 16); lblStat[i].Name = "lblStat"; lblStat[i].Size = new System.Drawing.Size(80, 16); lblStat[i].TabIndex = 10; //lblStat.BorderStyle=BorderStyle.FixedSingle; lblStat[i].Text = "Входящего: "; lblStat[i].MouseMove += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseMove); lblStat[i].MouseDown += new System.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
#endregion
frm_Host[i].Controls.AddRange(new System.Windows.Forms.Control[] { pbOutPlan[i], pbInPlan[i], lblOutgoing[i], pbOutgoing[i], label1[i], lblIngoing[i], pbIngoing[i], lblStat[i]}); frm_Host[i].ResumeLayout();
}
|
это создание... массива frm_Host. немного конечно запутанный пример, но я взял код без изменений. а обращение к элементам тогда будет:
| Код | System.Windows.Forms.GroupBox gpbParent=(GroupBox)this.Controls[i];// i - это конечно переменная цикла по всем групбоксам- тут он убран. ColorProgressBar.ColorProgressBar pbIngoing=((ColorProgressBar.ColorProgressBar)(gpbParent.Controls[6])), pbInPlan=((ColorProgressBar.ColorProgressBar)(gpbParent.Controls[1])), pbOutPlan=((ColorProgressBar.ColorProgressBar)(gpbParent.Controls[0])), pbOutgoing=((ColorProgressBar.ColorProgressBar)(gpbParent.Controls[3])); System.Windows.Forms.Label lblIngoing=((System.Windows.Forms.Label)gpbParent.Controls[5]); System.Windows.Forms.Label lblOutgoing=((System.Windows.Forms.Label)gpbParent.Controls[2]);//тут надо знать в каком порядке мы их добавляли: /*0- pbOutPlan, 1 - pbInPlan, 2 - lblOutgoing, 3 - pbOutgoing, 4 - label1, 5 - lblIngoing, 6 - pbIngoing, 7 - lblStat*/
|
вопросы ;) |