Guest User

Untitled

a guest
May 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. interface IDrawStrategy
  2. {
  3. void Draw(FormType form);
  4. }
  5.  
  6. public partial class MyForm : Form
  7. {
  8. public MyForm()
  9. {
  10. InitializeComponent();
  11. }
  12.  
  13. public void Draw(IState state)
  14. {
  15. switch (state.Value)
  16. {
  17. case 1:
  18. DrawState1();
  19. break;
  20. case 2:
  21. DrawState2();
  22. break;
  23. }
  24. }
  25.  
  26. private void DrawState1()
  27. {
  28. // design for state 1
  29. }
  30.  
  31. private void DrawState2()
  32. {
  33. // design for state 2
  34. }
  35.  
  36. ....
  37. }
  38.  
  39. public void OnSomeControlClick(object sender, EventArgs e)
  40. {
  41. IState state = new State();
  42. // check which option has been selected
  43. if (Option1.Checked)
  44. {
  45. state.Value = 1;
  46. }
  47. else if (Option2.Checked)
  48. {
  49. state.Value = 2;
  50. }
  51.  
  52. // if this method is inside the form itself
  53. this.Draw(state);
  54. }
Add Comment
Please, Sign In to add comment