SizeToolControl.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. namespace Easychart.Finance.Win
  2. {
  3. using Easychart.Finance;
  4. using System;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using System.Resources;
  8. using System.Windows.Forms;
  9. public class SizeToolControl : UserControl
  10. {
  11. private ChartWinControl chartControl;
  12. private IContainer components;
  13. private HScrollBar hsbView;
  14. private ImageList ilToolBar;
  15. private int LastValue;
  16. private bool Scrolling;
  17. private ToolBarButton tbbSizeAll;
  18. private ToolBarButton tbbZoomIn;
  19. private ToolBarButton tbbZoomOut;
  20. private ToolBar tnControl;
  21. public SizeToolControl()
  22. {
  23. this.InitializeComponent();
  24. }
  25. private void AdjustSize(double Multiply)
  26. {
  27. this.ChartControl.ScaleChart(Multiply);
  28. }
  29. private void chartControl_ViewChanged(object sender, ViewChangedArgs e)
  30. {
  31. if (!this.Scrolling)
  32. {
  33. this.Scrolling = true;
  34. try
  35. {
  36. this.hsbView.Minimum = e.FirstBar;
  37. this.hsbView.Maximum = e.LastBar;
  38. this.hsbView.LargeChange = (e.EndBar - e.StartBar) + 1;
  39. this.hsbView.Value = e.StartBar;
  40. this.LastValue = e.StartBar;
  41. }
  42. catch
  43. {
  44. }
  45. finally
  46. {
  47. this.Scrolling = false;
  48. }
  49. }
  50. else
  51. {
  52. this.Scrolling = false;
  53. }
  54. }
  55. protected override void Dispose(bool disposing)
  56. {
  57. if (disposing && (this.components != null))
  58. {
  59. this.components.Dispose();
  60. }
  61. base.Dispose(disposing);
  62. }
  63. private void hsbView_ValueChanged(object sender, EventArgs e)
  64. {
  65. if (!this.Scrolling && (this.ChartControl != null))
  66. {
  67. this.Scrolling = true;
  68. this.ChartControl.MoveChartXBars(this.hsbView.Value - this.LastValue);
  69. this.LastValue = this.hsbView.Value;
  70. }
  71. }
  72. private void InitializeComponent()
  73. {
  74. this.components = new Container();
  75. ResourceManager manager = new ResourceManager(typeof(SizeToolControl));
  76. this.hsbView = new HScrollBar();
  77. this.tnControl = new ToolBar();
  78. this.tbbSizeAll = new ToolBarButton();
  79. this.tbbZoomIn = new ToolBarButton();
  80. this.tbbZoomOut = new ToolBarButton();
  81. this.ilToolBar = new ImageList(this.components);
  82. base.SuspendLayout();
  83. this.hsbView.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
  84. this.hsbView.Location = new Point(0, 0);
  85. this.hsbView.Name = "hsbView";
  86. this.hsbView.Size = new Size(0x288, 20);
  87. this.hsbView.TabIndex = 2;
  88. this.hsbView.ValueChanged += new EventHandler(this.hsbView_ValueChanged);
  89. this.tnControl.Anchor = AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top;
  90. this.tnControl.Appearance = ToolBarAppearance.Flat;
  91. this.tnControl.Buttons.AddRange(new ToolBarButton[] { this.tbbSizeAll, this.tbbZoomIn, this.tbbZoomOut });
  92. this.tnControl.ButtonSize = new Size(0x18, 0x18);
  93. this.tnControl.Divider = false;
  94. this.tnControl.Dock = DockStyle.None;
  95. this.tnControl.DropDownArrows = true;
  96. this.tnControl.ImageList = this.ilToolBar;
  97. this.tnControl.Location = new Point(0x290, -2);
  98. this.tnControl.Name = "tnControl";
  99. this.tnControl.ShowToolTips = true;
  100. this.tnControl.Size = new Size(80, 30);
  101. this.tnControl.TabIndex = 3;
  102. this.tnControl.Wrappable = false;
  103. this.tnControl.ButtonClick += new ToolBarButtonClickEventHandler(this.tnControl_ButtonClick);
  104. this.tbbSizeAll.ImageIndex = 0;
  105. this.tbbSizeAll.ToolTipText = "Reset";
  106. this.tbbZoomIn.ImageIndex = 1;
  107. this.tbbZoomIn.ToolTipText = "Zoom In";
  108. this.tbbZoomOut.ImageIndex = 2;
  109. this.tbbZoomOut.ToolTipText = "Zoom Out";
  110. this.ilToolBar.ImageSize = new Size(20, 20);
  111. this.ilToolBar.ImageStream = (ImageListStreamer) manager.GetObject("ilToolBar.ImageStream");
  112. this.ilToolBar.TransparentColor = Color.White;
  113. base.Controls.Add(this.tnControl);
  114. base.Controls.Add(this.hsbView);
  115. base.Name = "SizeToolControl";
  116. base.Size = new Size(0x2e0, 20);
  117. base.ResumeLayout(false);
  118. }
  119. private void tnControl_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
  120. {
  121. if (this.ChartControl != null)
  122. {
  123. if (e.Button == this.tbbSizeAll)
  124. {
  125. this.ChartControl.Reset(5);
  126. }
  127. else if (e.Button == this.tbbZoomIn)
  128. {
  129. this.AdjustSize(0.2);
  130. }
  131. else if (e.Button == this.tbbZoomOut)
  132. {
  133. this.AdjustSize(-0.2);
  134. }
  135. }
  136. }
  137. public ChartWinControl ChartControl
  138. {
  139. get
  140. {
  141. return this.chartControl;
  142. }
  143. set
  144. {
  145. this.chartControl = value;
  146. if (value != null)
  147. {
  148. this.chartControl.ViewChanged -= new ViewChangedHandler(this.chartControl_ViewChanged);
  149. this.chartControl.ViewChanged += new ViewChangedHandler(this.chartControl_ViewChanged);
  150. }
  151. }
  152. }
  153. }
  154. }