| |||||||
| Programming and Assembly Language Please read this Topic's rules!! |
![]() |
| | LinkBack | Thread Tools | Rate Thread |
| ||||
| I believe the only way to do what you want is to enumerate the controls in the Controls container, looking for the controls that are of the textbox type. That's not a terribly efficient way of getting there, though.
__________________ Avatar and sig graphic by Pitch. Subscribers! Ask about a custom graphic or avatar today! Gizmo Thermal Diode Mod and Direct-Die Water Block 8-Cheetah 18GiB U-2 SCSI MegaRAID Enterprise 1500/128MiB Samsung SyncMaster 955DF TTGI/Superflower TTS-520 PSU ![]() ![]() ![]() |
| ||||
| Kinda confusing.... If I do this then is it easy to rewrite the source code?
__________________ GRAB overclocking -->OcBible v1.55 Guidemania v1.21 CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20 |
| ||||
| TBH, the more I look at this, the less sense it makes to attack the problem the way you are asking. Here's why: If you enumerate all the controls in the container, you could have to go through potentially thousands of controls. You'll have to look at the properties of each of those controls (the control type and the control name) to see if it is one of the ones you are interested in. I don't really see any gain for you in doing this. MAYBE if you make the textbox controls part of another control container and put them in a group, so that you could enumerate the controls in that particular container rather than enumerating all the controls on the form, it would work. That's something you'd probably have to play with.
__________________ Avatar and sig graphic by Pitch. Subscribers! Ask about a custom graphic or avatar today! Gizmo Thermal Diode Mod and Direct-Die Water Block 8-Cheetah 18GiB U-2 SCSI MegaRAID Enterprise 1500/128MiB Samsung SyncMaster 955DF TTGI/Superflower TTS-520 PSU ![]() ![]() ![]() |
| ||||
| Mate could you rewrite the above code and upload it here. Please forgive me but I explained you at u2u.......Thanks in advance.
__________________ GRAB overclocking -->OcBible v1.55 Guidemania v1.21 CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20 Last edited by MrSeanKon; 15th February, 2007 at 05:41 AM. |
| ||||
| The basic idea would be like this: Assuming that you have a tab control, each tab on the tab control will itself also contain controls. Therefor, you iterate over each control on the tab, looking for the ones that are TextBox controls, like so: Code: private void button1_Click(object sender, System.EventArgs e)
{
double sum=0.0;
foreach (Control ctrl in this.tabpage1.Controls)
{
if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
sum=Read_textboxes(ctrl);
}
MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
}
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return 0.0;
}
}
}
Assuming you did the above, and placed all of the controls on tabpage1, inside a GroupBox called groupbox1, the code would look like this: Code: private void button1_Click(object sender, System.EventArgs e)
{
double sum=0.0;
foreach (Control ctrl in this.tabpage1.groupbox1.Controls)
{
if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
sum=Read_textboxes(ctrl);
}
MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
}
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return 0.0;
}
}
}
Hope that helps.
__________________ Avatar and sig graphic by Pitch. Subscribers! Ask about a custom graphic or avatar today! Gizmo Thermal Diode Mod and Direct-Die Water Block 8-Cheetah 18GiB U-2 SCSI MegaRAID Enterprise 1500/128MiB Samsung SyncMaster 955DF TTGI/Superflower TTS-520 PSU ![]() ![]() ![]() |
| ||||
| Teacher the above code has some mistakes thus I rewrote it and new capabilities added.Here it is: Code: using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
#region Form's variables
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btn_Add;
private System.Windows.Forms.Button btn_Clear;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label4;
private System.ComponentModel.Container components = null;
#endregion
#region Initialization and dispose
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.btn_Add = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.btn_Clear = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btn_Add
//
this.btn_Add.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btn_Add.Location = new System.Drawing.Point(48, 168);
this.btn_Add.Name = "btn_Add";
this.btn_Add.Size = new System.Drawing.Size(48, 23);
this.btn_Add.TabIndex = 0;
this.btn_Add.Text = "Add!";
this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox1); // We must sort the added textboxes cos when the measurements=2
this.groupBox1.Controls.Add(this.textBox2); // the program reads and adds the first and the second textboxes
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.groupBox1.ForeColor = System.Drawing.Color.Red;
this.groupBox1.Location = new System.Drawing.Point(16, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 128);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Card 1";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label3.Location = new System.Drawing.Point(22, 98);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(13, 18);
this.label3.TabIndex = 5;
this.label3.Text = "3";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label2.Location = new System.Drawing.Point(22, 66);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(13, 18);
this.label2.TabIndex = 4;
this.label2.Text = "2";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label1.Location = new System.Drawing.Point(22, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(13, 18);
this.label1.TabIndex = 3;
this.label1.Text = "1";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.textBox1.Location = new System.Drawing.Point(40, 32);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 22);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("Tempus Sans ITC", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBox2.Location = new System.Drawing.Point(40, 64);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(64, 24);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.textBox3.Location = new System.Drawing.Point(40, 96);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(64, 22);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// btn_Clear
//
this.btn_Clear.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btn_Clear.Location = new System.Drawing.Point(168, 168);
this.btn_Clear.Name = "btn_Clear";
this.btn_Clear.Size = new System.Drawing.Size(48, 23);
this.btn_Clear.TabIndex = 2;
this.btn_Clear.Text = "Clear!";
this.btn_Clear.Click += new System.EventHandler(this.btn_Clear_Click);
//
// comboBox1
//
this.comboBox1.Font = new System.Drawing.Font("Calisto MT", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.comboBox1.Items.AddRange(new object[] {
"1",
"2",
"3"});
this.comboBox1.Location = new System.Drawing.Point(184, 64);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(40, 25);
this.comboBox1.TabIndex = 3;
this.comboBox1.Text = "1";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(160, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(97, 18);
this.label4.TabIndex = 4;
this.label4.Text = "Measurements";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(266, 206);
this.Controls.Add(this.label4);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.btn_Clear);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btn_Add);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private double BAN=2310.2003; // The BANNED value in OcBible
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
/*********************************************** The read routine ***********************************************/
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return BAN;
}
}
/*********************************************** Perform addition ***********************************************/
private void btn_Add_Click(object sender, System.EventArgs e)
{
double sum=BAN;
bool flag=true;
int measurements=1, index=1;
try
{
measurements=int.Parse(comboBox1.Text);
}
catch
{
MessageBox.Show("The default measurements number is 1","Don't ZZZ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
foreach (Control ctrl in this.groupBox1.Controls)
{
if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
{
double read_value=Read_textboxes((TextBox) ctrl);
if (index++ <= measurements)
{
if (read_value != BAN)
sum+=read_value;
else
{
MessageBox.Show("GKR no *****ing data in boxes","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
flag=false;
}
}
}
}
if (sum == BAN)
MessageBox.Show("LOL enter something!","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
else
{
string result=(sum-BAN).ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
if (flag)
MessageBox.Show("summary is " + result,"Your",MessageBoxButtons.OK,MessageBoxIcon.Information);
else
MessageBox.Show("No output","Retry",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
/********************************************** Clear the textboxes **********************************************/
private void btn_Clear_Click(object sender, System.EventArgs e)
{
foreach (Control ctrl in this.groupBox1.Controls)
{
if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
{
TextBox txtbox=(TextBox) ctrl;
txtbox.Text="";
}
comboBox1.Text="1";
}
}
}
}
__________________ Last edited by MrSeanKon; 2nd March, 2007 at 04:28 AM. |
| ||||
| However it is not optimized. Imagine that the Card1 has many labels and textboxes. Therefore the program will spend some extra time cos the foreach loop checks all controls (labels + textboxes) and compares if it the control is a label or a textbox. This is not a big problem cos CPUs are very fast and the OcBible inputs are not millions. BTW how we can optimize it???? Can we use e.g. the Tabindex property GKR I am impatient.....P.S. Am I a good student?????? Leet! http://www.geocities.com/seankoniaris/Smiles/leet.gif
__________________ GRAB overclocking -->OcBible v1.55 Guidemania v1.21 CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20 |
| ||||
| Quote:
Quote:
At this point, you probably have a better knowledge of C# and .NET than I do. I just know programming.
__________________ Avatar and sig graphic by Pitch. Subscribers! Ask about a custom graphic or avatar today! Gizmo Thermal Diode Mod and Direct-Die Water Block 8-Cheetah 18GiB U-2 SCSI MegaRAID Enterprise 1500/128MiB Samsung SyncMaster 955DF TTGI/Superflower TTS-520 PSU ![]() ![]() ![]() |
| ||||
| gizmo the next code is based on the above but I also changed the tabindex values for textboxes and labels. Some of them have the same value; anyway the program is OK. Code: using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
#region Form's variables
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btn_Add;
private System.Windows.Forms.Button btn_Clear;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label4;
private System.ComponentModel.Container components = null;
#endregion
#region Initialization and dispose
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.btn_Add = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.btn_Clear = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btn_Add
//
this.btn_Add.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btn_Add.Location = new System.Drawing.Point(48, 168);
this.btn_Add.Name = "btn_Add";
this.btn_Add.Size = new System.Drawing.Size(48, 23);
this.btn_Add.TabIndex = 0;
this.btn_Add.Text = "Add!";
this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.groupBox1.ForeColor = System.Drawing.Color.Red;
this.groupBox1.Location = new System.Drawing.Point(16, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 128);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Card 1";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label3.Location = new System.Drawing.Point(22, 98);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(13, 18);
this.label3.TabIndex = 33;
this.label3.Text = "3";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label2.Location = new System.Drawing.Point(22, 66);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(13, 18);
this.label2.TabIndex = 4;
this.label2.Text = "2";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label1.Location = new System.Drawing.Point(22, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(13, 18);
this.label1.TabIndex = 32;
this.label1.Text = "1";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.textBox1.Location = new System.Drawing.Point(40, 32);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 22);
this.textBox1.TabIndex = 32;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold);
this.textBox2.Location = new System.Drawing.Point(40, 64);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(64, 22);
this.textBox2.TabIndex = 33;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.textBox3.Location = new System.Drawing.Point(40, 96);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(64, 22);
this.textBox3.TabIndex = 33;
this.textBox3.Text = "";
//
// btn_Clear
//
this.btn_Clear.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btn_Clear.Location = new System.Drawing.Point(168, 168);
this.btn_Clear.Name = "btn_Clear";
this.btn_Clear.Size = new System.Drawing.Size(48, 23);
this.btn_Clear.TabIndex = 2;
this.btn_Clear.Text = "Clear!";
this.btn_Clear.Click += new System.EventHandler(this.btn_Clear_Click);
//
// comboBox1
//
this.comboBox1.Font = new System.Drawing.Font("Calisto MT", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.comboBox1.Items.AddRange(new object[] {
"1",
"2",
"3"});
this.comboBox1.Location = new System.Drawing.Point(184, 64);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(40, 25);
this.comboBox1.TabIndex = 3;
this.comboBox1.Text = "1";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(160, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(97, 18);
this.label4.TabIndex = 4;
this.label4.Text = "Measurements";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(266, 206);
this.Controls.Add(this.label4);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.btn_Clear);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btn_Add);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private double BAN=2310.2003; // The BANNED value in OcBible
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
/*********************************************** The read routine ***********************************************/
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return BAN;
}
}
/*********************************************** Perform addition ***********************************************/
private void btn_Add_Click(object sender, System.EventArgs e)
{
double sum=BAN;
bool flag=true;
int measurements=1, index=1;
try
{
measurements=int.Parse(comboBox1.Text);
}
catch
{
MessageBox.Show("The default measurements number is 1","Don't ZZZ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
foreach (Control ctrl in this.groupBox1.Controls)
{
if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
{
double read_value=Read_textboxes((TextBox) ctrl);
if (index++ <= measurements)
{
if (read_value != BAN)
sum+=read_value;
else
{
MessageBox.Show("GKR no wrong data in boxes","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
flag=false;
}
}
}
}
if (sum == BAN)
MessageBox.Show("LOL enter something!","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
else
{
string result=(sum-BAN).ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
if (flag)
MessageBox.Show("summary is " + result,"Your",MessageBoxButtons.OK,MessageBoxIcon.Information);
else
MessageBox.Show("No output","Retry",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
/********************************************** Clear the textboxes **********************************************/
private void btn_Clear_Click(object sender, System.EventArgs e)
{
foreach (Control ctrl in this.groupBox1.Controls)
{
if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
{
TextBox txtbox=(TextBox) ctrl;
txtbox.Text="";
}
comboBox1.Text="1";
}
}
}
}
__________________ Last edited by MrSeanKon; 13th March, 2007 at 02:39 AM. |
| ||||
| However if we enter all textboxes (only the textboxes) in a panel (which is inside of groupbox) then no waste time and we can remove the if statement in foreach loop. Code: using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
#region Form's variables
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btn_Add;
private System.Windows.Forms.Button btn_Clear;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Panel panel1;
private System.ComponentModel.Container components = null;
#endregion
#region Initialization and dispose
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.btn_Add = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.btn_Clear = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.groupBox1.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// btn_Add
//
this.btn_Add.Cursor = System.Windows.Forms.Cursors.Hand;
this.btn_Add.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btn_Add.Location = new System.Drawing.Point(48, 168);
this.btn_Add.Name = "btn_Add";
this.btn_Add.Size = new System.Drawing.Size(48, 23);
this.btn_Add.TabIndex = 0;
this.btn_Add.Text = "Add!";
this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.panel1);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.groupBox1.ForeColor = System.Drawing.Color.Red;
this.groupBox1.Location = new System.Drawing.Point(16, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 128);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Card 1";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label3.Location = new System.Drawing.Point(22, 98);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(13, 18);
this.label3.TabIndex = 5;
this.label3.Text = "3";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label2.Location = new System.Drawing.Point(22, 66);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(13, 18);
this.label2.TabIndex = 4;
this.label2.Text = "2";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label1.Location = new System.Drawing.Point(22, 34);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(13, 18);
this.label1.TabIndex = 3;
this.label1.Text = "1";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.textBox1.Location = new System.Drawing.Point(0, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 22);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold);
this.textBox2.Location = new System.Drawing.Point(0, 40);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(64, 22);
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.textBox3.Location = new System.Drawing.Point(0, 72);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(64, 22);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// btn_Clear
//
this.btn_Clear.Cursor = System.Windows.Forms.Cursors.Hand;
this.btn_Clear.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btn_Clear.Location = new System.Drawing.Point(168, 168);
this.btn_Clear.Name = "btn_Clear";
this.btn_Clear.Size = new System.Drawing.Size(48, 23);
this.btn_Clear.TabIndex = 2;
this.btn_Clear.Text = "Clear!";
this.btn_Clear.Click += new System.EventHandler(this.btn_Clear_Click);
//
// comboBox1
//
this.comboBox1.Font = new System.Drawing.Font("Calisto MT", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.comboBox1.Items.AddRange(new object[] {
"1",
"2",
"3"});
this.comboBox1.Location = new System.Drawing.Point(176, 96);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(40, 25);
this.comboBox1.TabIndex = 3;
this.comboBox1.Text = "1";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(152, 72);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(97, 18);
this.label4.TabIndex = 4;
this.label4.Text = "Measurements";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// panel1
//
this.panel1.Controls.Add(this.textBox1);
this.panel1.Controls.Add(this.textBox2);
this.panel1.Controls.Add(this.textBox3);
this.panel1.Location = new System.Drawing.Point(38, 24);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(72, 96);
this.panel1.TabIndex = 6;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(258, 206);
this.Controls.Add(this.label4);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.btn_Clear);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btn_Add);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
double BAN=2310.2003; // The BANNED value in OcBible
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
/*********************************************** The read routine ***********************************************/
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return BAN;
}
}
/*********************************************** Perform addition ***********************************************/
private void btn_Add_Click(object sender, System.EventArgs e)
{
double sum=BAN;
bool flag=true;
int measurements=1, index=1;
try
{
measurements=int.Parse(comboBox1.Text);
}
catch
{
MessageBox.Show("The default measurements number is 1","Don't ZZZ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
foreach (Control ctrl in this.panel1.Controls)
{
double read_value=Read_textboxes((TextBox) ctrl);
if (index++ <= measurements)
{
if (read_value != BAN)
sum+=read_value;
else
{
MessageBox.Show("GKR no wrong data in boxes","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
flag=false;
}
}
}
if (sum == BAN)
MessageBox.Show("LOL enter something!","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
else
{
string result=(sum-BAN).ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
if (flag)
MessageBox.Show("summary is " + result,"Your",MessageBoxButtons.OK,MessageBoxIcon.Information);
else
MessageBox.Show("No output","Retry",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
/********************************************** Clear the textboxes **********************************************/
private void btn_Clear_Click(object sender, System.EventArgs e)
{
foreach (Control ctrl in this.panel1.Controls)
{
TextBox txtbox=(TextBox) ctrl;
txtbox.Text="";
}
comboBox1.Text="1";
}
}
}
Moreover when I add or remove some textboxes I must check some tabindexes. What's your opinion?
__________________ |
| ||||
| Quote:
__________________ Avatar and sig graphic by Pitch. Subscribers! Ask about a custom graphic or avatar today! Gizmo Thermal Diode Mod and Direct-Die Water Block 8-Cheetah 18GiB U-2 SCSI MegaRAID Enterprise 1500/128MiB Samsung SyncMaster 955DF TTGI/Superflower TTS-520 PSU ![]() ![]() ![]() |
| ||||
| Thus we agree gizmo that this is the one of the best solutions. Moreover two UK programmers posted some other tricks. I will play later with the code.
__________________ GRAB overclocking -->OcBible v1.55 Guidemania v1.21 CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20 Last edited by MrSeanKon; 14th March, 2007 at 02:38 AM. |
| |||
| Hi guys. I think i have a better and faster solution than crawling into controls. It's so simple as create a List<TextBox> at the program entry point, scan all the controls for textboxes and add them to the list. After that you will have a reference to all your textboxes into the list and enumerate the items of a list is faster than doing it into a control container. And if you want to have faster acces to individual elements by key then don't use the List class, use a SortedList or a Dictionary and then you can use the key given to the element or enumerate the values at the Value property. Hope it helps. P.D.: sorry for my bad english
__________________ |
| ||||
| Thanks for your reply. Cos I am being f_cked up with Micro$oft products I have no time to maintain and tweak this code.I'll do this later cos I must decide the next steps. If you can upload source code it will be appreciated. BTW welcome to Aoaforums.
__________________ |
| |||
| Hello Here is the code with the metod i exposed on the previous post: Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace testLoop
{
public class Form1 : Form
{
private List<TextBox> textBoxesList = new List<TextBox>();
#region Código generado por el Diseñador de Windows Forms
private TextBox textBox1;
private TextBox textBox2;
private TextBox textBox3;
private TextBox textBox4;
private TextBox textBox5;
private TextBox textBox6;
private TextBox textBox7;
private TextBox textBox8;
private TextBox textBox9;
private Button button1;
private Button button2;
/// <summary>
/// Variable del diseñador requerida.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Limpiar los recursos que se estén utilizando.
/// </summary>
/// <param name="disposing">true si los recursos administrados se deben eliminar; false en caso contrario, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Método necesario para admitir el Diseñador. No se puede modificar
/// el contenido del método con el editor de código.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.textBox6 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.textBox8 = new System.Windows.Forms.TextBox();
this.textBox9 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 12);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(315, 20);
this.textBox1.TabIndex = 0;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(12, 38);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(315, 20);
this.textBox2.TabIndex = 1;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(12, 64);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(315, 20);
this.textBox3.TabIndex = 2;
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(12, 90);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(315, 20);
this.textBox4.TabIndex = 3;
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(12, 116);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(315, 20);
this.textBox5.TabIndex = 4;
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(12, 142);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(315, 20);
this.textBox6.TabIndex = 5;
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(12, 168);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(315, 20);
this.textBox7.TabIndex = 6;
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(12, 194);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(315, 20);
this.textBox8.TabIndex = 7;
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(12, 220);
this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(315, 20);
this.textBox9.TabIndex = 8;
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 246);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(315, 25);
this.button1.TabIndex = 9;
this.button1.Text = "Read textBoxes";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(12, 277);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(315, 25);
this.button2.TabIndex = 10;
this.button2.Text = "Write textBoxes";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(339, 313);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox9);
this.Controls.Add(this.textBox8);
this.Controls.Add(this.textBox7);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "TextBox List";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
try {
textBoxesList.Add((TextBox)c);
}
catch { }
}
}
private void button1_Click(object sender, EventArgs e)
{
string message = "";
for (int buc = 0; buc < textBoxesList.Count; buc++)
message += "TextBox number " + buc.ToString() + ": " + textBoxesList[buc].Text + "\r\n";
MessageBox.Show(message);
}
private void button2_Click(object sender, EventArgs e)
{
for (int buc = 0; buc < textBoxesList.Count; buc++)
textBoxesList[buc].Text = "C# Rulez, i will say this " + (buc + 1).ToString() + (buc > 0 ? " times" : " time");
}
}
}
Hope it helps ![]() P.D. Sorry for my bad english, i'm Spanish
__________________ |
| ||||
| Quote:
__________________ Avatar and sig graphic by Pitch. Subscribers! Ask about a custom graphic or avatar today! Gizmo Thermal Diode Mod and Direct-Die Water Block 8-Cheetah 18GiB U-2 SCSI MegaRAID Enterprise 1500/128MiB Samsung SyncMaster 955DF TTGI/Superflower TTS-520 PSU ![]() ![]() ![]() |
| ||||
| WOW man=Gusman thanks for posting. I also don't speak perfect English cos I am European like you (I live in Greece). At least we can communicate. By the way you can translate the OcBible in Spanish. I am getting busy these days so I will check your code other day. Thanks for your effort.
__________________ GRAB overclocking -->OcBible v1.55 Guidemania v1.21 CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20 |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Rate This Thread | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hibernation loop in 2k | videobruce | OS, Software, Firmware, and BIOS | 3 | 10th October, 2005 11:24 AM |
| FAH client gets into endless loop | drow_elf | Samuknow's AOA FOLDING@HOME Team | 7 | 10th August, 2004 04:49 PM |
| system idle loop | shamrock_uk | General Hardware Discussion | 3 | 17th October, 2003 11:57 PM |
| reboot loop | mrands2 | EPoX MotherBoards | 3 | 9th May, 2003 04:57 PM |
| Infinite Loop possible cause... | Orbit | General Hardware Discussion | 3 | 23rd August, 2002 10:11 AM |