winforms - c# Determine button function according to previous action -
i have 1 win form 4 panels in it, each panel seeing separately if independent forms, created function control it.
public void panelview(int pw) { if (pw == 1) { panelmenu.visible == true; /*panelmenu - main menu*/ panel2.visible == false; /*panel2 - has textbox , "ok" button*/ panel3.visible == false; /*panel3 - see product details*/ panel4.visible == false; /*panel4 - see products within order*/ } if (pw == 2) { panelmenu.visible == false; panel2.visible == true; panel3.visible == false; panel4.visible == false; } if (pw == 3) { panelmenu.visible == false; panel2.visible == false; panel3.visible == true; panel4.visible == false; } if (pw == 4) { panelmenu.visible == false; panel2.visible == false; panel3.visible == false; panel4.visible == true; } } private void btncheck_click(object sender, eventargs e) { panelview(2); } private void btnorder_click(object sender, eventargs e) { panelview(2); }
so when click on "btncheck", goes "panel2" can input product code, press "ok" send message server requesting product details specific product's , show product details on "panel3".
if decided check items within order, instead of pressing "btncheck", press "btnorder", lead "panel2" input order code, when press "ok", time want have different function instead of requesting server product details code entered on "panel2", request items within order corresponding order code entered on "panel2", information shown on "panel4".
i don't know how let "panel2" know clicked on "panelmenu" "ok" button can take textbox.text , perform task chose in "panelmenu". help?
one possible solution pass panelview method additional parameter, indicates state in want particular panel appear. if you're going have 2 possible states panel 2, int or boolean, might better off defining kind of state enum if there going multiple states per panel.
for example:
public void panelview(int pw, int state) { switch (pw) { case 1: // stuff break; case 2: if (state == 1) // check { // check setup code } else // order { // order setup code } break; case 3: // stuff break; // etc. etc. } }
so, when calling btncheck so:
panelview(2, 1);
..and when btnorder:
panelview(2, 2);
i highly recommend make states more readable somehow though, if you're not going use enums maybe define constants pass in makes things more readable:
int orderstate = 2; int checkstate = 1; panelview(2, orderstate)
if have public properties on panels, can set flags control how behave depending on state specified.
Comments
Post a Comment