SkinEditor.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. namespace IndexFormula.Finance.Win
  2. {
  3. using IndexFormula.Finance;
  4. using IndexFormula.Finance.DataProvider;
  5. using System;
  6. using System.ComponentModel;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Windows.Forms;
  10. using System.Xml.Serialization;
  11. [ToolboxItem(false)]
  12. public class SkinEditor : Form
  13. {
  14. private Button btnCreateNew;
  15. private Button btnOK;
  16. private Button btnSave;
  17. private ComboBox cbSkin;
  18. private ChartWinControl ChartControl;
  19. private Container components = null;
  20. private Label lBuildin;
  21. private PropertyGrid pg;
  22. private Panel pnClient;
  23. private Panel pnRight;
  24. private Splitter spVerticle;
  25. public SkinEditor()
  26. {
  27. this.InitializeComponent();
  28. }
  29. private void btnCreateNew_Click(object sender, EventArgs e)
  30. {
  31. string str = "CustomSkin";
  32. for (int i = 1; i < 10; i++)
  33. {
  34. if (FormulaSkin.CheckSkinName(str + i))
  35. {
  36. FormulaSkin selectedObject = (FormulaSkin) this.pg.SelectedObject;
  37. selectedObject = selectedObject.Clone();
  38. selectedObject.SkinName = str + i;
  39. selectedObject.Save();
  40. this.cbSkin.Items.Add(selectedObject.SkinName);
  41. this.cbSkin.SelectedIndex = this.cbSkin.Items.Count - 1;
  42. this.cbSkin_SelectedIndexChanged(this, null);
  43. break;
  44. }
  45. }
  46. }
  47. private void btnOK_Click(object sender, EventArgs e)
  48. {
  49. base.Close();
  50. }
  51. private void btnSave_Click(object sender, EventArgs e)
  52. {
  53. XmlSerializer serializer = new XmlSerializer(typeof(FormulaSkin));
  54. Directory.CreateDirectory(FormulaHelper.SkinRoot);
  55. ((FormulaSkin) this.pg.SelectedObject).Save();
  56. }
  57. private void cbSkin_SelectedIndexChanged(object sender, EventArgs e)
  58. {
  59. FormulaSkin skinByName = FormulaSkin.GetSkinByName(this.cbSkin.SelectedItem.ToString());
  60. this.pg.SelectedObject = skinByName;
  61. skinByName.CollectionValueChanged -= new EventHandler(this.fs_CollectionValueChanged);
  62. skinByName.CollectionValueChanged += new EventHandler(this.fs_CollectionValueChanged);
  63. this.ChartControl.Skin = this.cbSkin.SelectedItem.ToString();
  64. }
  65. protected override void Dispose(bool disposing)
  66. {
  67. if (disposing && (this.components != null))
  68. {
  69. this.components.Dispose();
  70. }
  71. base.Dispose(disposing);
  72. }
  73. private void fs_CollectionValueChanged(object sender, EventArgs e)
  74. {
  75. this.ChartControl.ApplySkin((FormulaSkin) this.pg.SelectedObject);
  76. }
  77. private void InitializeComponent()
  78. {
  79. IndexFormula.Finance.ExchangeIntraday exchangeIntraday1 = new IndexFormula.Finance.ExchangeIntraday();
  80. this.pnClient = new System.Windows.Forms.Panel();
  81. this.pnRight = new System.Windows.Forms.Panel();
  82. this.lBuildin = new System.Windows.Forms.Label();
  83. this.ChartControl = new IndexFormula.Finance.Win.ChartWinControl();
  84. this.btnCreateNew = new System.Windows.Forms.Button();
  85. this.btnSave = new System.Windows.Forms.Button();
  86. this.btnOK = new System.Windows.Forms.Button();
  87. this.cbSkin = new System.Windows.Forms.ComboBox();
  88. this.spVerticle = new System.Windows.Forms.Splitter();
  89. this.pnClient.SuspendLayout();
  90. this.pnRight.SuspendLayout();
  91. this.SuspendLayout();
  92. //
  93. // pnClient
  94. //
  95. this.pnClient.Controls.Add(this.pnRight);
  96. this.pnClient.Dock = System.Windows.Forms.DockStyle.Fill;
  97. this.pnClient.Font = new System.Drawing.Font("Verdana", 8.5F);
  98. this.pnClient.Location = new System.Drawing.Point(0, 0);
  99. this.pnClient.Name = "pnClient";
  100. this.pnClient.Size = new System.Drawing.Size(720, 510);
  101. this.pnClient.TabIndex = 1;
  102. //
  103. // pnRight
  104. //
  105. this.pnRight.Controls.Add(this.lBuildin);
  106. this.pnRight.Controls.Add(this.ChartControl);
  107. this.pnRight.Controls.Add(this.btnCreateNew);
  108. this.pnRight.Controls.Add(this.btnSave);
  109. this.pnRight.Controls.Add(this.btnOK);
  110. this.pnRight.Controls.Add(this.cbSkin);
  111. this.pnRight.Dock = System.Windows.Forms.DockStyle.Fill;
  112. this.pnRight.Location = new System.Drawing.Point(0, 0);
  113. this.pnRight.Name = "pnRight";
  114. this.pnRight.Size = new System.Drawing.Size(720, 510);
  115. this.pnRight.TabIndex = 3;
  116. //
  117. // lBuildin
  118. //
  119. this.lBuildin.AutoSize = true;
  120. this.lBuildin.Location = new System.Drawing.Point(8, 8);
  121. this.lBuildin.Name = "lBuildin";
  122. this.lBuildin.Size = new System.Drawing.Size(94, 14);
  123. this.lBuildin.TabIndex = 6;
  124. this.lBuildin.Text = "Build-in skins:";
  125. //
  126. // ChartControl
  127. //
  128. this.ChartControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  129. | System.Windows.Forms.AnchorStyles.Left)
  130. | System.Windows.Forms.AnchorStyles.Right)));
  131. this.ChartControl.CausesValidation = false;
  132. this.ChartControl.ChartDragMode = IndexFormula.Finance.ChartDragMode.Axis;
  133. this.ChartControl.CrossCursorMouseMode = IndexFormula.Finance.MouseAction.MouseMove;
  134. this.ChartControl.DefaultFormulas = "MAIN;VOLMA;RSI(14)#RSI(28);MACD";
  135. this.ChartControl.Designing = false;
  136. this.ChartControl.EndTime = new System.DateTime(((long)(0)));
  137. this.ChartControl.FavoriteFormulas = "VOLMA;RSI;CCI;OBV;ATR;FastSTO;SlowSTO;ROC;TRIX;WR;AD;CMF;PPO;StochRSI;ULT;BBWidth" +
  138. ";PVO";
  139. exchangeIntraday1.TimeZone = -4D;
  140. this.ChartControl.IntradayInfo = exchangeIntraday1;
  141. this.ChartControl.LatestValueType = IndexFormula.Finance.LatestValueType.None;
  142. this.ChartControl.Location = new System.Drawing.Point(15, 36);
  143. this.ChartControl.MaxPrice = 0D;
  144. this.ChartControl.MinPrice = 0D;
  145. this.ChartControl.MouseWheelMode = IndexFormula.Finance.Win.MouseWheelMode.Scroll;
  146. this.ChartControl.MouseZoomMode = IndexFormula.Finance.Win.MouseZoomMode.Rect;
  147. this.ChartControl.Name = "ChartControl";
  148. this.ChartControl.PriceLabelFormat = null;
  149. this.ChartControl.ScaleType = IndexFormula.Finance.ScaleType.Default;
  150. this.ChartControl.SelectFormulaMouseMode = IndexFormula.Finance.MouseAction.MouseDown;
  151. this.ChartControl.ShowHorizontalGrid = IndexFormula.Finance.Win.ShowLineMode.Default;
  152. this.ChartControl.ShowStatistic = false;
  153. this.ChartControl.ShowVerticalGrid = IndexFormula.Finance.Win.ShowLineMode.Default;
  154. this.ChartControl.Size = new System.Drawing.Size(693, 428);
  155. this.ChartControl.StartTime = new System.DateTime(((long)(0)));
  156. this.ChartControl.StickRenderType = IndexFormula.Finance.StickRenderType.Default;
  157. this.ChartControl.StockBars = 70;
  158. this.ChartControl.StockRenderType = IndexFormula.Finance.StockRenderType.Default;
  159. this.ChartControl.Symbol = "Test";
  160. this.ChartControl.TabIndex = 5;
  161. this.ChartControl.ValueTextMode = IndexFormula.Finance.ValueTextMode.Default;
  162. this.ChartControl.ZoomPosition = IndexFormula.Finance.Win.ZoomCenterPosition.Center;
  163. //
  164. // btnCreateNew
  165. //
  166. this.btnCreateNew.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  167. this.btnCreateNew.Location = new System.Drawing.Point(444, 477);
  168. this.btnCreateNew.Name = "btnCreateNew";
  169. this.btnCreateNew.Size = new System.Drawing.Size(104, 23);
  170. this.btnCreateNew.TabIndex = 4;
  171. this.btnCreateNew.Text = "Create New";
  172. this.btnCreateNew.Click += new System.EventHandler(this.btnCreateNew_Click);
  173. //
  174. // btnSave
  175. //
  176. this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  177. this.btnSave.Location = new System.Drawing.Point(556, 477);
  178. this.btnSave.Name = "btnSave";
  179. this.btnSave.Size = new System.Drawing.Size(75, 23);
  180. this.btnSave.TabIndex = 3;
  181. this.btnSave.Text = "Save";
  182. this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  183. //
  184. // btnOK
  185. //
  186. this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  187. this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
  188. this.btnOK.Location = new System.Drawing.Point(636, 477);
  189. this.btnOK.Name = "btnOK";
  190. this.btnOK.Size = new System.Drawing.Size(75, 23);
  191. this.btnOK.TabIndex = 2;
  192. this.btnOK.Text = "Close";
  193. this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
  194. //
  195. // cbSkin
  196. //
  197. this.cbSkin.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  198. this.cbSkin.Location = new System.Drawing.Point(104, 3);
  199. this.cbSkin.Name = "cbSkin";
  200. this.cbSkin.Size = new System.Drawing.Size(121, 21);
  201. this.cbSkin.TabIndex = 0;
  202. this.cbSkin.SelectedIndexChanged += new System.EventHandler(this.cbSkin_SelectedIndexChanged);
  203. //
  204. // spVerticle
  205. //
  206. this.spVerticle.Location = new System.Drawing.Point(0, 0);
  207. this.spVerticle.Name = "spVerticle";
  208. this.spVerticle.Size = new System.Drawing.Size(3, 510);
  209. this.spVerticle.TabIndex = 2;
  210. this.spVerticle.TabStop = false;
  211. //
  212. // SkinEditor
  213. //
  214. this.AcceptButton = this.btnSave;
  215. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  216. this.CancelButton = this.btnOK;
  217. this.ClientSize = new System.Drawing.Size(720, 510);
  218. this.Controls.Add(this.spVerticle);
  219. this.Controls.Add(this.pnClient);
  220. this.Name = "SkinEditor";
  221. this.ShowInTaskbar = false;
  222. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  223. this.Text = "Skin Manager";
  224. this.Load += new System.EventHandler(this.SkinForm_Load);
  225. this.pnClient.ResumeLayout(false);
  226. this.pnRight.ResumeLayout(false);
  227. this.pnRight.PerformLayout();
  228. this.ResumeLayout(false);
  229. }
  230. private void pg_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
  231. {
  232. this.ChartControl.ApplySkin((FormulaSkin) this.pg.SelectedObject);
  233. }
  234. private void SkinForm_Load(object sender, EventArgs e)
  235. {
  236. this.cbSkin.Items.AddRange(FormulaSkin.GetBuildInSkins());
  237. this.ChartControl.DataManager = new RandomDataManager();
  238. }
  239. }
  240. }