c# - calculations in dynamically generated controls in windows form applications -
I am creating a program to learn how to generate dynamically control inside the loop at the Button_Click event , Now I'm trying to multiply two fields and their output in the third text box
code:
for (int i = 0; i & lt; Ds.Tables [0] .Rows.Count; i ++) {Unit.Location = New System. Drawing Point (Unit Startup, Unit Startup V); Unit. Size = new system Drawing. Size (100, 30); Unit. Text = ""; Unit. Name = "Unit" + Eye. Toasting (); rate. Location = new system Drawing. Points (Rastestat position, Rastestat position V); Unit. Size = new system Drawing. Size (100, 30); rate. Text = ""; rate. Name = "rate" + i.ToString (); Amt.Location = New system. Drawing.Point (AMT Startup, AMTTartPision V); Amt.Size = New System Dropping Size (100, 30); Amt.Text = ""; Amt.Name = "amt" + i.ToString (); Panel1.Controls.Add (unit); Panel1.Controls.Add (rate); Panel1.Controls.Add (AMT); UnitstartpositionV + = 30; RatestartpositionV + = 30; AmtstartpositionV + = 30; Unit = new text box (); Rate = new text box (); AMT = new text box (); } Now I want to calculate it like
amt0.Text = (ConvertToInt32 (unit0.Text) * * ConvertToInt32 (rate0.Text) ). ToString (); Amt1.Text = (ConvertToInt32 (unit1.Text) * ConvertToInt32 (rate 1. text)). ToString (); and so on
In the end, I want to add all amt (i). Please help get it.
start from the line 'unitstartpositionV + = 30;' Next, I came here to solve it:
unitstartpositionV + = 30; RatestartpositionV + = 30; AmtstartpositionV + = 30; Unit = new text box (); Rate = new text box (); AMT = new text box (); Unit.Tag = Rate; rate. Tag = emt; Amt.Tag = Unit; Rate.TextChanged + = rate_TextChanged; Unit.TextChanged + = unit_TextChanged; }} Private Zero Rate Tag (object sender, EventArgs e) {var rate = Sender as text box; Var amt = rate.Tag as text box; Var unit = AMT Tag as text box; Calc (rate text, unit. Text, AMT); } Private Zero UnitTabut Change (Object Sender, EventAgds E) {var unit = Text box as sender; Var rate = unit.Tag as text box; Var amt = rate.Tag as text box; Calc (rate text, unit. Text, AMT); } Private Zero Calc (string rate, string unit, text box AMT) {int rateInt; If return (Int.TryParse (rate, rate rate)); Int unitInt; If return (Int.TryParse (unit, out unit unit)); Amt.Text = (rate IIMIT unit). Ostring (); } (Not included in all the zodiac sign)
I have solved this problem in an unusual way, the style you are fit with, Ve showed But in fact you should use arrays, or lists, or any kind of 'collection' to keep your control. By reviewing your other answers, I do not think that you have yet learned about IEnumerable, this is the concept that Which you are missing thus Mr. activity will make it very simple (especially "All You Need").
Comments
Post a Comment