OutlookBar.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace Core.LZMes.Client.UIM.comm
  5. {
  6. internal class BandTagInfo
  7. {
  8. public OutlookBar outlookBar;
  9. public int index;
  10. public BandTagInfo(OutlookBar ob, int index)
  11. {
  12. outlookBar = ob;
  13. this.index = index;
  14. }
  15. }
  16. public class OutlookBar : Panel
  17. {
  18. private int buttonHeight;
  19. private int selectedBand;
  20. private int selectedBandHeight;
  21. public int ButtonHeight
  22. {
  23. get
  24. {
  25. return buttonHeight;
  26. }
  27. set
  28. {
  29. buttonHeight = value;
  30. // do recalc layout for entire bar
  31. }
  32. }
  33. public int SelectedBand
  34. {
  35. get
  36. {
  37. return selectedBand;
  38. }
  39. set
  40. {
  41. SelectBand(value);
  42. }
  43. }
  44. public OutlookBar()
  45. {
  46. buttonHeight = 25;
  47. selectedBand = 0;
  48. selectedBandHeight = 0;
  49. }
  50. public void Initialize()
  51. {
  52. // parent must exist!
  53. Parent.SizeChanged += new EventHandler(SizeChangedEvent);
  54. }
  55. public void AddBand(string caption, ContentPanel content, EventHandler onClickEvent)
  56. {
  57. content.outlookBar = this;
  58. int index = Controls.Count;
  59. BandTagInfo bti = new BandTagInfo(this, index);
  60. BandPanel bandPanel = new BandPanel(caption, content, bti,onClickEvent);
  61. bandPanel.Text = caption;
  62. Controls.Add(bandPanel);
  63. UpdateBarInfo();
  64. RecalcLayout(bandPanel, index);
  65. }
  66. public void SelectBand(int index)
  67. {
  68. selectedBand = index;
  69. RedrawBands();
  70. }
  71. private void RedrawBands()
  72. {
  73. for (int i = 0; i < Controls.Count; i++)
  74. {
  75. BandPanel bp = Controls[i] as BandPanel;
  76. RecalcLayout(bp, i);
  77. }
  78. }
  79. private void UpdateBarInfo()
  80. {
  81. selectedBandHeight = ClientRectangle.Height - (Controls.Count * buttonHeight);
  82. }
  83. private void RecalcLayout(BandPanel bandPanel, int index)
  84. {
  85. int vPos = (index <= selectedBand) ? buttonHeight * index : buttonHeight * index + selectedBandHeight;
  86. int height = selectedBand == index ? selectedBandHeight + buttonHeight : buttonHeight;
  87. // the band dimensions
  88. bandPanel.Location = new Point(0, vPos);
  89. bandPanel.Size = new Size(ClientRectangle.Width, height);
  90. // the contained button dimensions
  91. bandPanel.Controls[0].Location = new Point(0, 0);
  92. bandPanel.Controls[0].Size = new Size(ClientRectangle.Width, buttonHeight);
  93. // the contained content panel dimensions
  94. bandPanel.Controls[1].Location = new Point(0, buttonHeight);
  95. bandPanel.Controls[1].Size = new Size(ClientRectangle.Width - 2, height - 8);
  96. }
  97. private void SizeChangedEvent(object sender, EventArgs e)
  98. {
  99. Size = new Size(Size.Width, ((Control)sender).ClientRectangle.Size.Height);
  100. UpdateBarInfo();
  101. RedrawBands();
  102. }
  103. }
  104. internal class BandPanel : Panel
  105. {
  106. private string text;
  107. public string TextBox
  108. {
  109. get
  110. {
  111. return text;
  112. }
  113. }
  114. public BandPanel(string caption, ContentPanel content, BandTagInfo bti, EventHandler onClickEvent)
  115. {
  116. BandButton bandButton = new BandButton(caption, bti);
  117. bandButton.Click += onClickEvent;
  118. text = caption;
  119. Controls.Add(bandButton);
  120. Controls.Add(content);
  121. }
  122. }
  123. internal class BandButton : Button
  124. {
  125. private BandTagInfo bti;
  126. public BandButton(string caption, BandTagInfo bti)
  127. {
  128. Text = caption;
  129. FlatStyle = FlatStyle.Standard;
  130. Visible = true;
  131. this.bti = bti;
  132. Click += new EventHandler(SelectBand);
  133. }
  134. private void SelectBand(object sender, EventArgs e)
  135. {
  136. bti.outlookBar.SelectBand(bti.index);
  137. }
  138. }
  139. public abstract class ContentPanel : Panel
  140. {
  141. public OutlookBar outlookBar;
  142. public ContentPanel()
  143. {
  144. // initial state
  145. Visible = true;
  146. }
  147. }
  148. public class IconPanel : ContentPanel
  149. {
  150. protected int iconSpacing;
  151. protected int margin;
  152. public int IconSpacing
  153. {
  154. get
  155. {
  156. return iconSpacing;
  157. }
  158. }
  159. public int Margin
  160. {
  161. get
  162. {
  163. return margin;
  164. }
  165. }
  166. public IconPanel()
  167. {
  168. margin = 10;
  169. iconSpacing = 32 + 15 + 10; // icon height + text height + margin
  170. BackColor = Color.LightBlue;
  171. AutoScroll = true;
  172. }
  173. public void AddIcon(string caption, Image image, EventHandler onClickEvent)
  174. {
  175. int index = Controls.Count / 2; // two entries per icon
  176. PanelIcon panelIcon = new PanelIcon(this, image, index, onClickEvent);
  177. panelIcon.Text = caption;
  178. Controls.Add(panelIcon);
  179. Label label = new Label();
  180. label.Text = caption;
  181. label.Visible = true;
  182. label.Location = new Point(0, margin + image.Size.Height + index * iconSpacing);
  183. label.Size = new Size(Size.Width, 15);
  184. label.TextAlign = ContentAlignment.TopCenter;
  185. label.Click += onClickEvent;
  186. label.Tag = panelIcon;
  187. Controls.Add(label);
  188. }
  189. }
  190. public class PanelIcon : PictureBox
  191. {
  192. public int index;
  193. public IconPanel iconPanel;
  194. private Color bckgColor;
  195. private bool mouseEnter;
  196. private string text;
  197. public int Index
  198. {
  199. get
  200. {
  201. return index;
  202. }
  203. }
  204. public string Text
  205. {
  206. get
  207. {
  208. return text;
  209. }
  210. set
  211. {
  212. text = value;
  213. }
  214. }
  215. public PanelIcon(IconPanel parent, Image image, int index, EventHandler onClickEvent)
  216. {
  217. this.index = index;
  218. this.iconPanel = parent;
  219. Image = image;
  220. Visible = true;
  221. Location = new Point(iconPanel.outlookBar.Size.Width / 2 - image.Size.Width / 2,
  222. iconPanel.Margin + index * iconPanel.IconSpacing);
  223. Size = image.Size;
  224. Click += onClickEvent;
  225. Tag = this;
  226. MouseEnter += new EventHandler(OnMouseEnter);
  227. MouseLeave += new EventHandler(OnMouseLeave);
  228. MouseMove += new MouseEventHandler(OnMouseMove);
  229. bckgColor = iconPanel.BackColor;
  230. mouseEnter = false;
  231. }
  232. private void OnMouseMove(object sender, MouseEventArgs args)
  233. {
  234. if ((args.X < Size.Width - 2) &&
  235. (args.Y < Size.Width - 2) &&
  236. (!mouseEnter))
  237. {
  238. BackColor = Color.LightCyan;
  239. BorderStyle = BorderStyle.FixedSingle;
  240. Location = Location - new Size(1, 1);
  241. mouseEnter = true;
  242. }
  243. }
  244. private void OnMouseEnter(object sender, EventArgs e)
  245. {
  246. }
  247. private void OnMouseLeave(object sender, EventArgs e)
  248. {
  249. if (mouseEnter)
  250. {
  251. BackColor = bckgColor;
  252. BorderStyle = BorderStyle.None;
  253. Location = Location + new Size(1, 1);
  254. mouseEnter = false;
  255. }
  256. }
  257. }
  258. }