MainView.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.ServiceModel;
  10. using System.Threading;
  11. using System.Configuration;
  12. using Aitex.Core.RT.OperationCenter;
  13. namespace Aitex.Core.Backend
  14. {
  15. public partial class MainView : Form
  16. {
  17. private NotifyIcon _notifyIcon = new NotifyIcon();
  18. Dictionary<string,UserControl> _views;
  19. object _msgLock = new object();
  20. List<string> _events = new List<string>();
  21. public MainView()
  22. {
  23. InitializeComponent();
  24. _views = new Dictionary<string, UserControl>();
  25. _views.Add("About",new AboutView());
  26. foreach(var item in _views)
  27. splitContainer2.Panel2.Controls.Add(item.Value);
  28. ////defaut view
  29. ShowView("About");
  30. this.SizeChanged += new EventHandler(MainView_SizeChanged);
  31. }
  32. void MainView_SizeChanged(object sender, EventArgs e)
  33. {
  34. foreach (var item in _views)
  35. {
  36. item.Value.Width = this.splitContainer1.Panel2.Width;
  37. item.Value.Height = this.splitContainer1.Panel2.Height;
  38. }
  39. }
  40. /// <summary>
  41. /// 不允许用户直接关闭后台界面窗口程序,退出PM程序必须通过点击任务栏图标实现程序退出
  42. /// </summary>
  43. /// <param name="e"></param>
  44. protected override void OnFormClosing(FormClosingEventArgs e)
  45. {
  46. if (e.CloseReason == CloseReason.UserClosing)
  47. {
  48. e.Cancel = true;
  49. Hide();
  50. return;
  51. }
  52. }
  53. public void AddCustomView(string name, UserControl uc)
  54. {
  55. if (uc == null)
  56. return;
  57. this.treeView1.Nodes.Add(new TreeNode() { Tag = name, Text = name });
  58. uc.Show();
  59. uc.Hide();
  60. _views.Add(name, uc);
  61. splitContainer2.Panel2.Controls.Add(uc);
  62. uc.Width = splitContainer2.Panel2.Width;
  63. uc.Height = splitContainer2.Panel2.Height;
  64. }
  65. protected override CreateParams CreateParams
  66. {
  67. get
  68. {
  69. int CS_NOCLOSE = 0x200;
  70. CreateParams parameters = base.CreateParams;
  71. parameters.ClassStyle |= CS_NOCLOSE;
  72. return parameters;
  73. }
  74. }
  75. private void ShowView(string viewName)
  76. {
  77. foreach (var item in _views)
  78. {
  79. if (item.Key != viewName)
  80. item.Value.Hide();
  81. else
  82. item.Value.Show();
  83. }
  84. }
  85. private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
  86. {
  87. var viewName = (string)e.Node.Tag;
  88. ShowView(viewName);
  89. }
  90. private void btnLogout_Click(object sender, EventArgs e)
  91. {
  92. Hide();
  93. }
  94. private void btnReset_Click(object sender, EventArgs e)
  95. {
  96. OP.DoOperation("Reset");
  97. }
  98. }
  99. }