Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IDrawStrategy
- {
- void Draw(FormType form);
- }
- public partial class MyForm : Form
- {
- public MyForm()
- {
- InitializeComponent();
- }
- public void Draw(IState state)
- {
- switch (state.Value)
- {
- case 1:
- DrawState1();
- break;
- case 2:
- DrawState2();
- break;
- }
- }
- private void DrawState1()
- {
- // design for state 1
- }
- private void DrawState2()
- {
- // design for state 2
- }
- ....
- }
- public void OnSomeControlClick(object sender, EventArgs e)
- {
- IState state = new State();
- // check which option has been selected
- if (Option1.Checked)
- {
- state.Value = 1;
- }
- else if (Option2.Checked)
- {
- state.Value = 2;
- }
- // if this method is inside the form itself
- this.Draw(state);
- }
Add Comment
Please, Sign In to add comment