c# - Button Click to Swtich -
can give me helping hand convert sequence switch. tried tries fails.
private void buttontouch ( edittext x) { if (i==2) { button1.click += delegate { x.text = x.text + "1"; }; button2.click += delegate { x.text = x.text + "2"; }; button3.click += delegate { x.text = x.text + "3"; }; button4.click += delegate { x.text = x.text + "4"; }; button5.click += delegate { x.text = x.text + "5"; }; button6.click += delegate { x.text = x.text + "6"; }; button7.click += delegate { x.text = x.text + "7"; }; button8.click += delegate { x.text = x.text + "8"; }; button9.click += delegate { x.text = x.text + "9"; }; button0.click += delegate { x.text = x.text + "0"; }; } a.click += delegate { i=0; = + 1; this.buttontouch (a); }; b.click += delegate { i=0; = + 1; this.buttontouch (b); }; c.click += delegate { i=0; = + 1; this.buttontouch (c); }; }
tries like:
switch (button) { case 'button1.click':....... ; break; ....... ....... }
or
switch (true) { case 'button1':........; break; ........ ........ }
and i'm out of ideas ... relevant ideas. appreciate if disturb me. thank in advance.
try dont think solve problem, problem must else:
if (i==2) { var listbuttons = new list<button> { { button1 }, { button2 }, { button3 }, { button4 }, { button5 }, { button6 }, { button7 }, { button8 }, { button9 }, { button0 }, }; for(int i=0; i<=9; i++) { switch (i) { case 0: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 1: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 2: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 3: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 4: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 5: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 6: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 7: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 8: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } case 9: { listbuttons[i].click += delegate { x.text = x.text + i; }; break; } } } }
Comments
Post a Comment