1: using System;
2: using System.Collections.Generic;
3: using System.Windows.Forms;
4:
5: namespace MessageFilterDemos
6: {
7: public partial class MainForm : Form
8: {
9: public static TabPage ActiveTabPage
10: { get;private set; }
11:
12: private IDictionary<string, UserControl> keyedViews
13: { get; set; }
14:
15: public MainForm()
16: {
17: InitializeComponent();
18: this.keyedViews = new Dictionary<string, UserControl>();
19: }
20:
21: protected override void OnLoad(EventArgs e)
22: {
23: base.OnLoad(e);
24: this.keyedViews.Add("CustomerInfo", new CustomerInfo());
25: this.keyedViews.Add("OrderInfo", new OrderInfo());
26: }
27:
28: private void Show(string key, string text, UserControl view)
29: {
30: if (!this.mainWorkspace.TabPages.ContainsKey(key))
31: {
32: this.mainWorkspace.TabPages.Add(key, text);
33: this.mainWorkspace.TabPages[key].Controls.Add(view);
34: this.mainWorkspace.TabPages[key].AutoScroll = true;
35: }
36: this.mainWorkspace.SelectedTab = this.mainWorkspace.TabPages[key];
37: ActiveTabPage = this.mainWorkspace.TabPages[key];
38: }
39:
40: private void ordeToolStripMenuItem_Click(object sender, EventArgs e)
41: {
42: this.Show("OrderInfo", "Order", keyedViews["OrderInfo"]);
43: }
44:
45: private void customerToolStripMenuItem_Click(object sender, EventArgs e)
46: {
47: this.Show("CustomerInfo", "Customer", keyedViews["CustomerInfo"]);
48: }
49:
50: private void mainWorkspace_SelectedIndexChanged(object sender, EventArgs e)
51: {
52: ActiveTabPage = this.mainWorkspace.SelectedTab;
53: }
54: }
55: }