ChartWinControl.cs 124 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512
  1. using Easychart.Finance.DataProvider;
  2. using System;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Drawing.Imaging;
  8. using System.Drawing.Printing;
  9. using System.Globalization;
  10. using System.IO;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. namespace Easychart.Finance.Win
  14. {
  15. public class ChartWinControl : UserControl, IObjectCanvas, IDisposable
  16. {
  17. #region Events of ChartWinControl (12)
  18. [Description("Occurs after apply skin"), Category("Stock Chart")]
  19. public event EventHandler AfterApplySkin;
  20. [Description("Occurs after data bind"), Category("Stock Chart")]
  21. public event Easychart.Finance.Win.AfterBindData AfterBindData;
  22. [Category("Stock Chart"), Description("Occurs after data cycle changed")]
  23. public event EventHandler AfterCycleChange;
  24. [Description("Occurs after mouse move"), Category("Stock Chart")]
  25. public event Easychart.Finance.Win.AfterMouseMove AfterMouseMove;
  26. [Description("Occurs before apply skin"), Category("Stock Chart")]
  27. public event ApplySkinHandler BeforeApplySkin;
  28. [Description("Occurs before data cycle changed"), Category("Stock Chart")]
  29. public event EventHandler BeforeCycleChange;
  30. [Description("Occurs when cursor pos changed"), Category("Stock Chart")]
  31. public event Easychart.Finance.Win.CursorPosChanged CursorPosChanged;
  32. [Category("Stock Chart"), Description("Occurs when stock data or data cycle changed")]
  33. public event EventHandler DataChanged;
  34. [Category("Stock Chart"), Description("Occurs when paint extra informations on the chart, it was used by Easy Stock Object")]
  35. public event NativePaintHandler ExtraPaint;
  36. [Category("Stock Chart"), Description("Occurs when paint the chart on native canvas")]
  37. public event NativePaintHandler NativePaint;
  38. [Description("Occurs when the value of ShowStatistic Changed"), Category("Stock Chart")]
  39. public event EventHandler ShowStatisticChanged;
  40. [Category("Stock Chart"), Description("Occurs when stock view changed")]
  41. public event ViewChangedHandler ViewChanged;
  42. #endregion Events of ChartWinControl (12)
  43. #region Members of ChartWinControl (114)
  44. private bool adjustData = true;
  45. private double afterBars = 0.1;
  46. private string areaPercent = "3;1;1;1;1";
  47. private FormulaChart chart;
  48. private Easychart.Finance.ChartDragMode chartDragMode = Easychart.Finance.ChartDragMode.Axis;
  49. private ContextMenu cmMain;
  50. public ContextMenu cmRight;
  51. private double columnWidth = 4.0;
  52. private IContainer components;
  53. private Graphics ControlGraphics;
  54. private MouseAction crossCursorMouseMode = MouseAction.MouseMove;
  55. private Bitmap CrossMemBmp;
  56. private Graphics CrossMemBmpG;
  57. private DataCycle currentDataCycle = DataCycle.Day;
  58. private DataManagerBase CurrentDataManager;
  59. private Cursor defaultCursor = null;
  60. private const string defaultFavoriteCycles = "MINUTE1;MINUTE5;MINUTE15;MINUTE30;HOUR1;DAY1;WEEK1;MONTH1;YEAR1";
  61. private string defaultFormulas;
  62. private static Color defaultZoomBackColor = Color.FromArgb(0x20, Color.Green);
  63. private bool designing;
  64. private ChartDragInfo DragInfo;
  65. private EventHandler ehFavoriteIndicator;
  66. private bool EnableResize;
  67. private bool EnableXScale;
  68. private bool EnableYScale;
  69. private DateTime endTime;
  70. private string favoriteCycles = "MINUTE1;MINUTE5;MINUTE15;MINUTE30;HOUR1;DAY1;WEEK1;MONTH1;YEAR1";
  71. private ArrayList favoriteFormulas;
  72. private bool fixedTime;
  73. private Rectangle fixedZoomRect = Rectangle.Empty;
  74. private DataManagerBase historyDataManager;
  75. private DataManagerBase intraDataManager;
  76. private ExchangeIntraday intradayInfo = ExchangeIntraday.US;
  77. private int LastCursorPos;
  78. private FormulaHitInfo LastHitInfo;
  79. private IDataProvider LastProvider;
  80. private int LastX;
  81. private int LastY;
  82. private Easychart.Finance.LatestValueType latestValueType = Easychart.Finance.LatestValueType.All;
  83. private double maxColumnWidth = 500.0;
  84. private double maxPrice;
  85. private Bitmap MemBmp;
  86. private bool memoryCrossCursor;
  87. private MenuItem miAddFormula;
  88. private MenuItem miAdjust;
  89. private MenuItem miAxisType;
  90. private MenuItem miCalculator;
  91. private MenuItem miChart;
  92. private MenuItem miChartCopy;
  93. private MenuItem miChartEdit;
  94. private MenuItem miCloseFormula;
  95. private MenuItem miCopy;
  96. private MenuItem miCrossCursor;
  97. private MenuItem miCycle;
  98. private MenuItem miEdit;
  99. private MenuItem miFavorite;
  100. private MenuItem miFormulaManager;
  101. private MenuItem miIndicator;
  102. private MenuItem miLog;
  103. private double minColumnWidth = 0.01;
  104. private MenuItem miNormal;
  105. private double minPrice;
  106. private MenuItem miSkin;
  107. private MenuItem miSp1;
  108. private MenuItem miSp2;
  109. private MenuItem miSp4;
  110. private MenuItem miStatistic;
  111. private MenuItem miStatisticWindow;
  112. private MenuItem miView;
  113. private FormulaHitInfo MouseDownInfo;
  114. private Easychart.Finance.Win.MouseWheelMode mouseWheelMode = Easychart.Finance.Win.MouseWheelMode.Scroll;
  115. private Color mouseZoomBackColor = defaultZoomBackColor;
  116. private Bitmap MouseZoomBmp;
  117. private Graphics MouseZoomBmpG;
  118. private Easychart.Finance.Win.MouseZoomMode mouseZoomMode = Easychart.Finance.Win.MouseZoomMode.Rect;
  119. private RectangleF MouseZoomRect;
  120. private bool nativeContextMenu = true;
  121. private bool needAutoScaleY = true;
  122. private bool needDrawCursor;
  123. private bool needDrawLastBarOnly = false;
  124. private bool needRebind;
  125. private bool needRedraw;
  126. private bool needRefresh;
  127. private bool needResetCursorPos;
  128. private bool needSetDefaultFormulas;
  129. public static Easychart.Finance.Win.OnSelectFormula OnSelectFormula = new Easychart.Finance.Win.OnSelectFormula(ChartWinControl.DefaultSelectFormula);
  130. public static OnSelectString OnSelectMethod = new OnSelectString(ChartWinControl.DefaultSelectMethod);
  131. public static OnSelectString OnSelectSymbol = null;
  132. private int Page;
  133. private PrintPreviewDialog previewDialog;
  134. private PrintDialog printDialog;
  135. private PrintDocument printDocument;
  136. private bool resetYAfterXChanged = true;
  137. private Easychart.Finance.ScaleType scaleType = Easychart.Finance.ScaleType.Default;
  138. private MouseAction selectFormulaMouseMode = MouseAction.MouseDown;
  139. private PageSetupDialog setupDialog;
  140. private bool showCrossCursor = true;
  141. private bool showCursorLabel = true;
  142. private ShowLineMode showHorizontalGrid;
  143. private bool showIndicatorValues = true;
  144. private bool showOverlayValues = true;
  145. private bool showStatistic = true;
  146. private bool showTopLine = true;
  147. private ShowLineMode showVerticalGrid;
  148. private string skin = "RedWhite";
  149. private DateTime startTime;
  150. public StatisticControl StatisticWindow = null;
  151. private Easychart.Finance.StickRenderType stickRenderType = Easychart.Finance.StickRenderType.Default;
  152. private int stockBars = 150;
  153. private Easychart.Finance.StockRenderType stockRenderType = Easychart.Finance.StockRenderType.Default;
  154. private string symbol = "MSFT";
  155. public FormulaUserSkin UserSkin = new FormulaUserSkin();
  156. private Easychart.Finance.ValueTextMode valueTextMode = Easychart.Finance.ValueTextMode.Default;
  157. private ZoomCenterPosition zoomPosition = ZoomCenterPosition.Center;
  158. public DateTime[] openCloseArray; //开收盘时间
  159. public double LastClose; //昨收
  160. public double Highest; //当天最高价
  161. public double Lowsest; //当天最低价
  162. private const string tickChartFormulas = "C#CAVG"; //分时图公式
  163. private FormulaChart temKChartFormula;
  164. private FormulaChart tickChart;
  165. #endregion Members of ChartWinControl (114)
  166. #region Properties of ChartWinControl (55)
  167. [Category("Stock Chart"), DefaultValue(true), Description("Adjust the data automatically when there is price split")]
  168. public bool AdjustData
  169. {
  170. get
  171. {
  172. return this.adjustData;
  173. }
  174. set
  175. {
  176. this.adjustData = value;
  177. this.NeedRebind();
  178. }
  179. }
  180. [DefaultValue((double)0.1), Category("Stock Chart Time"), Description("How many right space after the last bar of the chart. If the value between 0 and 1, it means the percentage of the bar.")]
  181. public double AfterBars
  182. {
  183. get
  184. {
  185. return this.afterBars;
  186. }
  187. set
  188. {
  189. this.afterBars = value;
  190. }
  191. }
  192. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  193. public int AreaCount
  194. {
  195. get
  196. {
  197. return this.chart.Areas.Count;
  198. }
  199. set
  200. {
  201. this.SetAreaCount(value);
  202. }
  203. }
  204. [Category("Stock Chart"), DefaultValue("3;1;1;1;1"), Description("Height percentage of each area,separated by semi colon.")]
  205. public string AreaPercent
  206. {
  207. get
  208. {
  209. return this.areaPercent;
  210. }
  211. set
  212. {
  213. this.areaPercent = value;
  214. }
  215. }
  216. [Browsable(false)]
  217. public string Caption
  218. {
  219. get
  220. {
  221. IDataProvider dataProvider = this.chart.DataProvider;
  222. string stringData = dataProvider.GetStringData("Code");
  223. string str2 = dataProvider.GetStringData("Name");
  224. if (str2 != null)
  225. {
  226. stringData = stringData + "(" + str2 + ")";
  227. }
  228. string str3 = dataProvider.GetStringData("Exchange");
  229. if (str3 != null)
  230. {
  231. stringData = stringData + "@" + str3;
  232. }
  233. return (stringData + " - " + this.CurrentDataCycle);
  234. }
  235. }
  236. [Browsable(false)]
  237. public FormulaChart Chart
  238. {
  239. get
  240. {
  241. return this.chart;
  242. }
  243. }
  244. [DefaultValue(1), Description("Behaver when drag the chart"), Category("Stock Chart")]
  245. public Easychart.Finance.ChartDragMode ChartDragMode
  246. {
  247. get
  248. {
  249. return this.chartDragMode;
  250. }
  251. set
  252. {
  253. this.chartDragMode = value;
  254. }
  255. }
  256. [Browsable(false), DefaultValue((double)4.0), Category("Stock Chart Time")]
  257. public double ColumnWidth
  258. {
  259. get
  260. {
  261. return this.columnWidth;
  262. }
  263. set
  264. {
  265. this.columnWidth = value;
  266. }
  267. }
  268. [DefaultValue(1), Category("Stock Chart"), Description("How to show the cross cursor according mouse action, mouse move or mouse down")]
  269. public MouseAction CrossCursorMouseMode
  270. {
  271. get
  272. {
  273. return this.crossCursorMouseMode;
  274. }
  275. set
  276. {
  277. this.crossCursorMouseMode = value;
  278. }
  279. }
  280. [Description("Data Cycle"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), DefaultValue(typeof(DataCycle), "DAY1"), Category("Stock Chart")]
  281. public DataCycle CurrentDataCycle
  282. {
  283. get
  284. {
  285. return this.currentDataCycle;
  286. }
  287. set
  288. {
  289. if (this.currentDataCycle != value)
  290. {
  291. if (this.BeforeCycleChange != null)
  292. {
  293. this.BeforeCycleChange(this, new EventArgs());
  294. }
  295. if (DataCycle.TimeChart.Equals(currentDataCycle)&&!DataCycle.TimeChart.Equals(value))
  296. {
  297. this.chart.NativePaint -= new NativePaintHandler(this.Chart_NativePaint);
  298. this.chart.ExtraPaint -= new NativePaintHandler(this.Chart_ExtraPaint);
  299. this.chart.ViewChanged -= new ViewChangedHandler(this.Chart_ViewChanged);
  300. this.chart = this.temKChartFormula;
  301. this.chart.NativePaint += new NativePaintHandler(this.Chart_NativePaint);
  302. this.chart.ExtraPaint += new NativePaintHandler(this.Chart_ExtraPaint);
  303. this.chart.ViewChanged += new ViewChangedHandler(this.Chart_ViewChanged);
  304. }
  305. if ((value.CycleBase >= DataCycleBase.DAY) && this.chart.FixedTime)
  306. {
  307. this.fixedTime = false;
  308. this.chart.FixedTime = false;
  309. }
  310. else if (DataCycle.TimeChart.Equals(value))
  311. {
  312. this.temKChartFormula = this.chart;
  313. this.chart.NativePaint -= new NativePaintHandler(this.Chart_NativePaint);
  314. this.chart.ExtraPaint -= new NativePaintHandler(this.Chart_ExtraPaint);
  315. this.chart.ViewChanged -= new ViewChangedHandler(this.Chart_ViewChanged);
  316. tickChart.Rect = this.chart.Rect;
  317. this.chart = tickChart;
  318. tickChart.Areas.Clear();
  319. tickChart.StringsToArea(tickChartFormulas.Split(new char[] { ';' }));
  320. this.chart.NativePaint += new NativePaintHandler(this.Chart_NativePaint);
  321. this.chart.ExtraPaint += new NativePaintHandler(this.Chart_ExtraPaint);
  322. this.chart.ViewChanged += new ViewChangedHandler(this.Chart_ViewChanged);
  323. tickChart.LastClose = this.LastClose;
  324. tickChart.Highest = this.Highest;
  325. tickChart.Lowsest = this.Lowsest;
  326. tickChart.openCloseArray = this.openCloseArray;
  327. this.chart.DataCycle = value;
  328. }
  329. this.NeedRebind();
  330. this.currentDataCycle = value;
  331. if (this.AfterCycleChange != null)
  332. {
  333. this.AfterCycleChange(this, new EventArgs());
  334. }
  335. }
  336. }
  337. }
  338. [Browsable(false)]
  339. public DataManagerBase DataManager
  340. {
  341. set
  342. {
  343. this.HistoryDataManager = value;
  344. this.IntraDataManager = value;
  345. }
  346. }
  347. [Description("Default cursor"), DefaultValue((string)null), Category("Stock Chart")]
  348. public Cursor DefaultCursor
  349. {
  350. get
  351. {
  352. return this.defaultCursor;
  353. }
  354. set
  355. {
  356. this.defaultCursor = value;
  357. }
  358. }
  359. [Category("Stock Chart"), DefaultValue("VOLMA;RSI(14)#RSI(28);MACD;SlowSTO")]
  360. public string DefaultFormulas
  361. {
  362. get
  363. {
  364. return this.defaultFormulas;
  365. }
  366. set
  367. {
  368. this.defaultFormulas = value;
  369. this.needSetDefaultFormulas = true;
  370. this.NeedRebind();
  371. }
  372. }
  373. [Browsable(false)]
  374. public Control DesignerControl
  375. {
  376. get
  377. {
  378. return this;
  379. }
  380. }
  381. [Browsable(false)]
  382. public bool Designing
  383. {
  384. get
  385. {
  386. return this.designing;
  387. }
  388. set
  389. {
  390. this.designing = value;
  391. }
  392. }
  393. [Description("End time of the chart, if leave this field empty, will use StockBars instead"), DefaultValue(typeof(DateTime), "1-1-1"), Category("Stock Chart Time")]
  394. public DateTime EndTime
  395. {
  396. get
  397. {
  398. return this.endTime;
  399. }
  400. set
  401. {
  402. this.endTime = value;
  403. if (this.fixedTime || ((this.CurrentDataManager != null) && this.CurrentDataManager.VirtualFetch))
  404. {
  405. this.NeedRebind();
  406. }
  407. else
  408. {
  409. this.NeedRedraw();
  410. }
  411. if (this.memoryCrossCursor)
  412. {
  413. this.needDrawCursor = true;
  414. }
  415. }
  416. }
  417. [Category("Stock Chart"), DefaultValue("MINUTE1;MINUTE5;MINUTE15;MINUTE30;HOUR1;DAY1;WEEK1;MONTH1;YEAR1")]
  418. public string FavoriteCycles
  419. {
  420. get
  421. {
  422. return this.favoriteCycles;
  423. }
  424. set
  425. {
  426. this.favoriteCycles = value;
  427. this.CreateCycleMenu();
  428. }
  429. }
  430. [Category("Stock Chart")]
  431. public string FavoriteFormulas
  432. {
  433. get
  434. {
  435. return string.Join(";", (string[])this.favoriteFormulas.ToArray(typeof(string)));
  436. }
  437. set
  438. {
  439. if ((value != null) && (value != ""))
  440. {
  441. this.favoriteFormulas.Clear();
  442. this.favoriteFormulas.AddRange(value.Split(new char[] { ';' }));
  443. this.BuildFavoriteMenu();
  444. }
  445. }
  446. }
  447. [DefaultValue(false), Category("Stock Chart"), Description("Fixed time frame between StartTime and EndTime, used for intraday chart")]
  448. public bool FixedTime
  449. {
  450. get
  451. {
  452. return this.fixedTime;
  453. }
  454. set
  455. {
  456. this.fixedTime = value;
  457. this.NeedRebind();
  458. }
  459. }
  460. [Category("Stock Chart Mouse Zoom"), Description("Rectangle for fixed zoom box. Empty box will draw the zoom box by hand. Center fixed zoom box (-150,-150,300,300), TopLeft fixed zoom box (0,0,300,300)"), DefaultValue(typeof(Rectangle), "0, 0, 0, 0")]
  461. public Rectangle FixedZoomRect
  462. {
  463. get
  464. {
  465. return this.fixedZoomRect;
  466. }
  467. set
  468. {
  469. this.fixedZoomRect = value;
  470. }
  471. }
  472. [DefaultValue((string)null), Browsable(false)]
  473. public DataManagerBase HistoryDataManager
  474. {
  475. get
  476. {
  477. return this.historyDataManager;
  478. }
  479. set
  480. {
  481. if (value != this.historyDataManager)
  482. {
  483. this.historyDataManager = value;
  484. this.NeedRebind();
  485. }
  486. }
  487. }
  488. [Browsable(false), DefaultValue((string)null)]
  489. public DataManagerBase IntraDataManager
  490. {
  491. get
  492. {
  493. return this.intraDataManager;
  494. }
  495. set
  496. {
  497. if (value != this.intraDataManager)
  498. {
  499. this.intraDataManager = value;
  500. this.NeedRebind();
  501. }
  502. }
  503. }
  504. [Description("Intraday exchange informations"), Browsable(false)]
  505. public ExchangeIntraday IntradayInfo
  506. {
  507. get
  508. {
  509. return this.intradayInfo;
  510. }
  511. set
  512. {
  513. this.intradayInfo = value;
  514. this.NeedRebind();
  515. }
  516. }
  517. [Browsable(false)]
  518. public bool IsDragging
  519. {
  520. get
  521. {
  522. return (this.DragInfo != null);
  523. }
  524. }
  525. [Category("Stock Chart"), DefaultValue(2), Description("How to show the latest value in the axis-Y")]
  526. public Easychart.Finance.LatestValueType LatestValueType
  527. {
  528. get
  529. {
  530. return this.latestValueType;
  531. }
  532. set
  533. {
  534. this.latestValueType = value;
  535. this.NeedRedraw();
  536. }
  537. }
  538. [DefaultValue((double)500.0), Category("Stock Chart")]
  539. public double MaxColumnWidth
  540. {
  541. get
  542. {
  543. return this.maxColumnWidth;
  544. }
  545. set
  546. {
  547. this.maxColumnWidth = value;
  548. }
  549. }
  550. [Browsable(false)]
  551. public double MaxPrice
  552. {
  553. get
  554. {
  555. return this.maxPrice;
  556. }
  557. set
  558. {
  559. this.maxPrice = value;
  560. }
  561. }
  562. [DefaultValue(false), Description("Draw cross cursor in memory , this will prevent flicker"), Category("Stock Chart")]
  563. public bool MemoryCrossCursor
  564. {
  565. get
  566. {
  567. return this.memoryCrossCursor;
  568. }
  569. set
  570. {
  571. this.memoryCrossCursor = value;
  572. }
  573. }
  574. [Category("Stock Chart"), DefaultValue((double)0.01)]
  575. public double MinColumnWidth
  576. {
  577. get
  578. {
  579. return this.minColumnWidth;
  580. }
  581. set
  582. {
  583. this.minColumnWidth = value;
  584. }
  585. }
  586. [Browsable(false)]
  587. public double MinPrice
  588. {
  589. get
  590. {
  591. return this.minPrice;
  592. }
  593. set
  594. {
  595. this.minPrice = value;
  596. }
  597. }
  598. [Description("Use mouse wheel to scroll or zoom the chart"), DefaultValue(1), Category("Stock Chart")]
  599. public Easychart.Finance.Win.MouseWheelMode MouseWheelMode
  600. {
  601. get
  602. {
  603. return this.mouseWheelMode;
  604. }
  605. set
  606. {
  607. this.mouseWheelMode = value;
  608. }
  609. }
  610. [DefaultValue(typeof(Color), "32, 0, 128, 0"), Description("The background color of the mouse zoom"), Category("Stock Chart Mouse Zoom")]
  611. public Color MouseZoomBackColor
  612. {
  613. get
  614. {
  615. return this.mouseZoomBackColor;
  616. }
  617. set
  618. {
  619. this.mouseZoomBackColor = value;
  620. }
  621. }
  622. [Description("Use mouse to zoom the chart"), DefaultValue(1), Category("Stock Chart Mouse Zoom")]
  623. public Easychart.Finance.Win.MouseZoomMode MouseZoomMode
  624. {
  625. get
  626. {
  627. return this.mouseZoomMode;
  628. }
  629. set
  630. {
  631. this.mouseZoomMode = value;
  632. }
  633. }
  634. [Description("Use native context menu"), Category("Stock Chart"), DefaultValue(true)]
  635. public bool NativeContextMenu
  636. {
  637. get
  638. {
  639. return this.nativeContextMenu;
  640. }
  641. set
  642. {
  643. this.nativeContextMenu = value;
  644. }
  645. }
  646. [Description("If you specify this, will add these text in the price area,Sample format:Prev Close:{LC}O:{OPEN}H:{HIGH}L:{LOW}C:{CLOSE}V:{VOLUME}Chg:{Change} {D:yyyy-MM-dd}"), Category("Stock Chart")]
  647. public string PriceLabelFormat
  648. {
  649. get
  650. {
  651. return this.chart.PriceLabelFormat;
  652. }
  653. set
  654. {
  655. this.chart.PriceLabelFormat = value;
  656. }
  657. }
  658. [Category("Stock Chart"), DefaultValue(true), Description("Reset Y-axis to auto scale when X-axis changed.")]
  659. public bool ResetYAfterXChanged
  660. {
  661. get
  662. {
  663. return this.resetYAfterXChanged;
  664. }
  665. set
  666. {
  667. this.resetYAfterXChanged = value;
  668. }
  669. }
  670. [DefaultValue(3), Category("Stock Chart"), Description("Get or set the scale type of main stock area")]
  671. public Easychart.Finance.ScaleType ScaleType
  672. {
  673. get
  674. {
  675. return this.scaleType;
  676. }
  677. set
  678. {
  679. this.scaleType = value;
  680. this.NeedRedraw();
  681. }
  682. }
  683. [DefaultValue(2), Description("How to select a formula through mouse"), Category("Stock Chart")]
  684. public MouseAction SelectFormulaMouseMode
  685. {
  686. get
  687. {
  688. return this.selectFormulaMouseMode;
  689. }
  690. set
  691. {
  692. this.selectFormulaMouseMode = value;
  693. }
  694. }
  695. [DefaultValue(true), Description("Show cross cursor on the chart"), Category("Stock Chart")]
  696. public bool ShowCrossCursor
  697. {
  698. get
  699. {
  700. return this.showCrossCursor;
  701. }
  702. set
  703. {
  704. this.showCrossCursor = value;
  705. this.miCrossCursor.Checked = value;
  706. this.chart.ShowHLine = value;
  707. this.chart.ShowVLine = value;
  708. if (!value)
  709. {
  710. base.Invalidate();
  711. }
  712. }
  713. }
  714. [DefaultValue(true), Category("Stock Chart")]
  715. public bool ShowCursorLabel
  716. {
  717. get
  718. {
  719. return this.showCursorLabel;
  720. }
  721. set
  722. {
  723. this.showCursorLabel = value;
  724. this.NeedRebind();
  725. }
  726. }
  727. [Category("Stock Chart"), Description("How to show the horizontal grid line"), DefaultValue(0)]
  728. public ShowLineMode ShowHorizontalGrid
  729. {
  730. get
  731. {
  732. return this.showHorizontalGrid;
  733. }
  734. set
  735. {
  736. this.showHorizontalGrid = value;
  737. this.NeedRedraw();
  738. }
  739. }
  740. [DefaultValue(true), Category("Stock Chart"), Description("Show indicator values in the statistic window")]
  741. public bool ShowIndicatorValues
  742. {
  743. get
  744. {
  745. return this.showIndicatorValues;
  746. }
  747. set
  748. {
  749. this.showIndicatorValues = value;
  750. }
  751. }
  752. [DefaultValue(true), Description("Show overlay values in the statistic window"), Category("Stock Chart")]
  753. public bool ShowOverlayValues
  754. {
  755. get
  756. {
  757. return this.showOverlayValues;
  758. }
  759. set
  760. {
  761. this.showOverlayValues = value;
  762. }
  763. }
  764. [Category("Stock Chart"), DefaultValue(true), Description("Show statistic windows on the chart")]
  765. public bool ShowStatistic
  766. {
  767. get
  768. {
  769. return this.showStatistic;
  770. }
  771. set
  772. {
  773. bool flag = (this.showStatistic != value) && (this.ShowStatisticChanged != null);
  774. this.showStatistic = value;
  775. if (flag)
  776. {
  777. this.ShowStatisticChanged(this, new EventArgs());
  778. }
  779. }
  780. }
  781. [Description("Draw a line on top of the chart control"), Category("Stock Chart"), DefaultValue(true)]
  782. public bool ShowTopLine
  783. {
  784. get
  785. {
  786. return this.showTopLine;
  787. }
  788. set
  789. {
  790. this.showTopLine = value;
  791. }
  792. }
  793. [Description("How to show the vertical grid line"), DefaultValue(0), Category("Stock Chart")]
  794. public ShowLineMode ShowVerticalGrid
  795. {
  796. get
  797. {
  798. return this.showVerticalGrid;
  799. }
  800. set
  801. {
  802. this.showVerticalGrid = value;
  803. this.NeedRedraw();
  804. }
  805. }
  806. [TypeConverter(typeof(SkinConverter)), Category("Stock Chart"), DefaultValue("RedWhite")]
  807. public string Skin
  808. {
  809. get
  810. {
  811. return this.skin;
  812. }
  813. set
  814. {
  815. this.skin = value;
  816. this.NeedRebind();
  817. }
  818. }
  819. [Browsable(false), DefaultValue(0), Category("Stock Chart Time")]
  820. public int StartBar
  821. {
  822. get
  823. {
  824. return this.chart.Start;
  825. }
  826. set
  827. {
  828. if (value < 0)
  829. {
  830. value = 0;
  831. }
  832. this.chart.Start = value;
  833. if (!this.chart.FixedTime)
  834. {
  835. this.chart.StartTime = DateTime.MinValue;
  836. this.chart.EndTime = DateTime.MaxValue;
  837. }
  838. this.NeedRedraw();
  839. }
  840. }
  841. [Category("Stock Chart Time"), Description("Start time of the chart"), DefaultValue(typeof(DateTime), "1-1-1")]
  842. public DateTime StartTime
  843. {
  844. get
  845. {
  846. return this.startTime;
  847. }
  848. set
  849. {
  850. this.startTime = value;
  851. if (this.fixedTime || ((this.CurrentDataManager != null) && this.CurrentDataManager.VirtualFetch))
  852. {
  853. this.NeedRebind();
  854. }
  855. else
  856. {
  857. this.NeedRedraw();
  858. }
  859. if (this.memoryCrossCursor)
  860. {
  861. this.needDrawCursor = true;
  862. }
  863. }
  864. }
  865. [DefaultValue(4), Description("Stick render type is used for Volumn Stick,Color Stick and Stick Line"), Category("Stock Chart")]
  866. public Easychart.Finance.StickRenderType StickRenderType
  867. {
  868. get
  869. {
  870. return this.stickRenderType;
  871. }
  872. set
  873. {
  874. this.stickRenderType = value;
  875. this.NeedRebind();
  876. }
  877. }
  878. [Category("Stock Chart Time"), Description("This will take effect when EndTime is empty."), DefaultValue(150)]
  879. public int StockBars
  880. {
  881. get
  882. {
  883. return this.stockBars;
  884. }
  885. set
  886. {
  887. if (value < 1)
  888. {
  889. value = 1;
  890. }
  891. this.stockBars = value;
  892. this.NeedRedraw();
  893. this.EndTime = DateTime.MinValue;
  894. }
  895. }
  896. [Description("Stock chart render type"), Category("Stock Chart"), DefaultValue(4)]
  897. public Easychart.Finance.StockRenderType StockRenderType
  898. {
  899. get
  900. {
  901. return this.stockRenderType;
  902. }
  903. set
  904. {
  905. this.stockRenderType = value;
  906. this.NeedRebind();
  907. }
  908. }
  909. [DefaultValue("MSFT"), Description("Stock Symbol"), Category("Stock Chart")]
  910. public string Symbol
  911. {
  912. get
  913. {
  914. return this.symbol;
  915. }
  916. set
  917. {
  918. if (value != this.symbol)
  919. {
  920. this.symbol = value;
  921. this.NeedRebind();
  922. }
  923. }
  924. }
  925. [Description("How to draw the value text"), DefaultValue(4), Category("Stock Chart")]
  926. public Easychart.Finance.ValueTextMode ValueTextMode
  927. {
  928. get
  929. {
  930. return this.valueTextMode;
  931. }
  932. set
  933. {
  934. this.valueTextMode = value;
  935. this.NeedRebind();
  936. }
  937. }
  938. [Category("Stock Chart Mouse Zoom"), DefaultValue(0), Description("Position of the zoom center")]
  939. public ZoomCenterPosition ZoomPosition
  940. {
  941. get
  942. {
  943. return this.zoomPosition;
  944. }
  945. set
  946. {
  947. this.zoomPosition = value;
  948. }
  949. }
  950. #endregion Properties of ChartWinControl (55)
  951. #region Constructors of ChartWinControl (1)
  952. public ChartWinControl()
  953. {
  954. this.InitializeComponent();
  955. this.Page = 10;
  956. this.LastCursorPos = -1;
  957. this.favoriteFormulas = new ArrayList();
  958. this.EnableYScale = true;
  959. this.EnableXScale = true;
  960. this.EnableResize = true;
  961. this.chart = new FormulaChart
  962. {
  963. BitmapCache = true,
  964. LatestValueType = this.LatestValueType
  965. };
  966. tickChart = new FormulaChart
  967. {
  968. BitmapCache = true,
  969. LatestValueType = this.LatestValueType
  970. };
  971. tickChart.Areas.Clear();
  972. tickChart.StringsToArea(tickChartFormulas.Split(new char[] { ';' }));
  973. this.showHorizontalGrid = ShowLineMode.HideAll;
  974. base.MouseWheel += new MouseEventHandler(this.ChartWinControl_MouseWheel);
  975. this.AfterApplySkin = (EventHandler)Delegate.Combine(this.AfterApplySkin, new EventHandler(this.ChartWinControl_AfterApplySkin));
  976. this.chart.NativePaint += new NativePaintHandler(this.Chart_NativePaint);
  977. this.chart.ExtraPaint += new NativePaintHandler(this.Chart_ExtraPaint);
  978. this.chart.ViewChanged += new ViewChangedHandler(this.Chart_ViewChanged);
  979. this.chart.AddArea("MAIN", 3.0);
  980. this.FavoriteFormulas = "VOLMA;RSI;CCI;OBV;ATR;FastSTO;SlowSTO;ROC;TRIX;WR;AD;CMF;PPO;StochRSI;ULT;BBWidth;PVO";
  981. this.CursorPosChanged = (Easychart.Finance.Win.CursorPosChanged)Delegate.Combine(this.CursorPosChanged, new Easychart.Finance.Win.CursorPosChanged(this.ShowStatisticWindow));
  982. this.ehFavoriteIndicator = new EventHandler(this.mmFavorite_SelectedIndexChanged);
  983. this.CreateCycleMenu();
  984. this.StatisticWindow.OnHide += new EventHandler(this.StatisticWindow_OnHide);
  985. }
  986. public ChartWinControl(DateTime[] openCloses,double lastClose)
  987. : this()
  988. {
  989. openCloseArray = openCloses;
  990. LastClose = lastClose;
  991. }
  992. #endregion Constructors of ChartWinControl (1)
  993. #region Methods of ChartWinControl (126)
  994. /// <summary>
  995. /// 销毁对象
  996. /// </summary>
  997. public new void Dispose()
  998. {
  999. this.MouseWheel -= this.ChartWinControl_MouseWheel;
  1000. this.StatisticWindow.OnHide -= this.StatisticWindow_OnHide;
  1001. this.StatisticWindow.Dispose();
  1002. if (this.cmMain != null) this.cmMain.Dispose();
  1003. this.cmMain = null;
  1004. if (this.cmRight != null) this.cmRight.Dispose();
  1005. this.cmRight = null;
  1006. if (this.chart == null) return;
  1007. this.chart.NativePaint -= this.Chart_NativePaint;
  1008. this.chart.ExtraPaint -= this.Chart_ExtraPaint;
  1009. this.chart.ViewChanged -= this.Chart_ViewChanged;
  1010. this.chart.Dispose();
  1011. this.chart = null;
  1012. if (ControlGraphics != null) ControlGraphics.Dispose();
  1013. ControlGraphics = null;
  1014. if (components != null) components.Dispose();
  1015. components = null;
  1016. if (CrossMemBmp != null) CrossMemBmp.Dispose();
  1017. CrossMemBmp = null;
  1018. if (currentDataCycle != null) currentDataCycle.Dispose();
  1019. currentDataCycle = null;
  1020. if (CurrentDataManager != null) CurrentDataManager.Dispose();
  1021. CurrentDataManager = null;
  1022. if (defaultCursor != null) defaultCursor.Dispose();
  1023. defaultCursor = null;
  1024. defaultFormulas = null;
  1025. if (DragInfo != null) DragInfo.Dispose();
  1026. DragInfo = null;
  1027. if (favoriteFormulas != null) favoriteFormulas.Clear();
  1028. favoriteFormulas = null;
  1029. if (historyDataManager != null) historyDataManager.Dispose();
  1030. historyDataManager = null;
  1031. if (intraDataManager != null) intraDataManager.Dispose();
  1032. intraDataManager = null;
  1033. if (intradayInfo != null) intradayInfo.Dispose();
  1034. intradayInfo = null;
  1035. LastProvider = null;
  1036. if (MemBmp != null) MemBmp.Dispose();
  1037. MemBmp = null;
  1038. if (miAddFormula != null) miAddFormula.Dispose();
  1039. miAddFormula = null;
  1040. if (miAdjust != null) miAdjust.Dispose();
  1041. miAdjust = null;
  1042. if (miAxisType != null) miAxisType.Dispose();
  1043. miAxisType = null;
  1044. if (miCalculator != null) miCalculator.Dispose();
  1045. miCalculator = null;
  1046. if (miChart != null) miChart.Dispose();
  1047. miChart = null;
  1048. if (miChartCopy != null) miChartCopy.Dispose();
  1049. miChartCopy = null;
  1050. if (miChartEdit != null) miChartEdit.Dispose();
  1051. miChartEdit = null;
  1052. if (miCloseFormula != null) miCloseFormula.Dispose();
  1053. miCloseFormula = null;
  1054. if (miCopy != null) miCopy.Dispose();
  1055. miCopy = null;
  1056. if (miCrossCursor != null) miCrossCursor.Dispose();
  1057. miCrossCursor = null;
  1058. if (miCycle != null) miCycle.Dispose();
  1059. miCycle = null;
  1060. if (miEdit != null) miEdit.Dispose();
  1061. miEdit = null;
  1062. if (miFavorite != null) miFavorite.Dispose();
  1063. miFavorite = null;
  1064. if (miFormulaManager != null) miFormulaManager.Dispose();
  1065. miFormulaManager = null;
  1066. if (miIndicator != null) miIndicator.Dispose();
  1067. miIndicator = null;
  1068. if (miLog != null) miLog.Dispose();
  1069. miLog = null;
  1070. if (miNormal != null) miNormal.Dispose();
  1071. miNormal = null;
  1072. if (miSkin != null) miSkin.Dispose();
  1073. miSkin = null;
  1074. if (miSp1 != null) miSp1.Dispose();
  1075. miSp1 = null;
  1076. if (miSp2 != null) miSp2.Dispose();
  1077. miSp2 = null;
  1078. if (miSp4 != null) miSp4.Dispose();
  1079. miSp4 = null;
  1080. if (miStatistic != null) miStatistic.Dispose();
  1081. miStatistic = null;
  1082. if (miStatisticWindow != null) miStatisticWindow.Dispose();
  1083. miStatisticWindow = null;
  1084. if (miView != null) miView.Dispose();
  1085. miView = null;
  1086. if (MouseZoomBmp != null) MouseZoomBmp.Dispose();
  1087. MouseZoomBmp = null;
  1088. if (MouseZoomBmpG != null) MouseZoomBmpG.Dispose();
  1089. MouseZoomBmpG = null;
  1090. if (previewDialog != null) previewDialog.Dispose();
  1091. previewDialog = null;
  1092. if (printDialog != null) printDialog.Dispose();
  1093. printDialog = null;
  1094. if (printDocument != null) printDocument.Dispose();
  1095. printDocument = null;
  1096. if (setupDialog != null) setupDialog.Dispose();
  1097. setupDialog = null;
  1098. if (UserSkin != null) UserSkin.Dispose();
  1099. UserSkin = null;
  1100. base.Dispose();
  1101. }
  1102. private void ApplySkin()
  1103. {
  1104. FormulaSkin skinByName = FormulaSkin.GetSkinByName(this.skin);
  1105. this.ApplySkin(skinByName);
  1106. }
  1107. public void ApplySkin(FormulaSkin fs)
  1108. {
  1109. if (fs != null)
  1110. {
  1111. if (this.BeforeApplySkin != null)
  1112. {
  1113. this.BeforeApplySkin(this, fs);
  1114. }
  1115. this.chart.SetSkin(fs);
  1116. this.chart[0].Back.TopPen.Width = this.ShowTopLine ? 1 : 0;
  1117. this.chart[0].AxisY.Back.TopPen.Width = this.ShowTopLine ? 1 : 0;
  1118. if (this.AfterApplySkin != null)
  1119. {
  1120. this.AfterApplySkin(this, new EventArgs());
  1121. }
  1122. foreach (FormulaArea area in this.chart.Areas)
  1123. {
  1124. area.RemoveAutoMultiplyForStockYAxis();
  1125. }
  1126. }
  1127. }
  1128. private void AreasToDefaultFormulas()
  1129. {
  1130. this.defaultFormulas = string.Join(";", this.chart.AreaToStrings());
  1131. }
  1132. public void AutoAdjustYAxis()
  1133. {
  1134. foreach (FormulaArea area in this.chart.Areas)
  1135. {
  1136. foreach (FormulaAxisY sy in area.AxisYs)
  1137. {
  1138. this.AutoAdjustYAxis(sy);
  1139. }
  1140. }
  1141. }
  1142. public void AutoAdjustYAxis(FormulaAxisY fay)
  1143. {
  1144. this.MinPrice = 0.0;
  1145. fay.AutoScale = true;
  1146. this.NeedRedraw();
  1147. }
  1148. public void AutoScaleAxisY()
  1149. {
  1150. foreach (FormulaArea area in this.chart.Areas)
  1151. {
  1152. foreach (FormulaAxisY sy in area.AxisYs)
  1153. {
  1154. sy.AutoScale = true;
  1155. }
  1156. }
  1157. this.NeedRebind();
  1158. }
  1159. public bool BindData()
  1160. {
  1161. bool flag = true;
  1162. if ((this.HistoryDataManager != null) && (this.IntraDataManager != null))
  1163. {
  1164. CommonDataProvider cdp = null;
  1165. if (this.currentDataCycle.CycleBase >= DataCycleBase.DAY)
  1166. {
  1167. this.CurrentDataManager = this.HistoryDataManager;
  1168. }
  1169. else
  1170. {
  1171. this.CurrentDataManager = this.IntraDataManager;
  1172. this.CurrentDataManager.IsFix = this.fixedTime;
  1173. this.chart.FixedTime = this.fixedTime;
  1174. }
  1175. if (this.CurrentDataManager.VirtualFetch)
  1176. {
  1177. this.CurrentDataManager.StartTime = this.startTime;
  1178. this.CurrentDataManager.EndTime = this.endTime;
  1179. }
  1180. flag = false;
  1181. try
  1182. {
  1183. cdp = (CommonDataProvider)this.CurrentDataManager[this.symbol];
  1184. if (this.AfterBindData != null)
  1185. {
  1186. this.AfterBindData(this, new BindDataEventArgs(cdp, this.CurrentDataManager));
  1187. }
  1188. flag = cdp != null;
  1189. }
  1190. catch
  1191. {
  1192. }
  1193. if (cdp != null)
  1194. {
  1195. this.chart.SetDataProviderNoBind(cdp);
  1196. }
  1197. else
  1198. {
  1199. this.endTime = DateTime.MinValue;
  1200. }
  1201. if (this.fixedTime && (cdp != null))
  1202. {
  1203. cdp.IntradayInfo = this.IntradayInfo;
  1204. }
  1205. if ((this.chart.DataProvider != null) && (this.chart.DataProvider is CommonDataProvider))
  1206. {
  1207. if (this.HasData())
  1208. {
  1209. if (this.chart.DataProvider.DataCycle.ToString() != this.currentDataCycle.ToString())
  1210. {
  1211. this.ColumnWidth = 5.0;
  1212. this.StartBar = 0;
  1213. this.chart.DataProvider.DataCycle = this.currentDataCycle;
  1214. }
  1215. if (this.DataChanged != null)
  1216. {
  1217. this.DataChanged(this, new EventArgs());
  1218. }
  1219. }
  1220. (this.chart.DataProvider as CommonDataProvider).Adjusted = this.adjustData;
  1221. }
  1222. this.chart.SetAreaPercent(this.areaPercent);
  1223. this.chart.Bind();
  1224. this.ApplySkin();
  1225. }
  1226. return flag;
  1227. }
  1228. private void BuildFavoriteMenu()
  1229. {
  1230. this.cmRight.MenuItems.Remove(this.miFavorite);
  1231. this.miFavorite = new MenuItem("&Favorite Indicators");
  1232. this.cmRight.MenuItems.Add(0, this.miFavorite);
  1233. foreach (string str in this.favoriteFormulas)
  1234. {
  1235. this.miFavorite.MenuItems.Add(str, this.ehFavoriteIndicator);
  1236. }
  1237. }
  1238. private void CancelMouseZoom()
  1239. {
  1240. if (this.MouseZoomBmp != null)
  1241. {
  1242. this.DragInfo = null;
  1243. this.MouseZoomBmp = null;
  1244. this.MouseZoomRect = Rectangle.Empty;
  1245. }
  1246. }
  1247. private void ChangeCursorPos()
  1248. {
  1249. if (((this.chart != null) && (this.chart.DataProvider != null)) && ((this.LastCursorPos != this.chart.CursorPos) || (this.LastProvider != this.chart.DataProvider)))
  1250. {
  1251. IDataProvider dataProvider = this.chart.DataProvider;
  1252. if ((this.chart.CursorPos >= 0) && (this.chart.CursorPos < dataProvider.Count))
  1253. {
  1254. this.LastProvider = this.chart.DataProvider;
  1255. this.LastCursorPos = this.chart.CursorPos;
  1256. if (this.CursorPosChanged != null)
  1257. {
  1258. this.CursorPosChanged(this, this.chart, this.LastCursorPos, dataProvider);
  1259. }
  1260. }
  1261. }
  1262. }
  1263. private void Chart_ExtraPaint(object sender, NativePaintArgs e)
  1264. {
  1265. if (this.ExtraPaint != null)
  1266. {
  1267. this.ExtraPaint(this, e);
  1268. }
  1269. }
  1270. private void Chart_NativePaint(object sender, NativePaintArgs e)
  1271. {
  1272. if (this.NativePaint != null)
  1273. {
  1274. this.NativePaint(this, e);
  1275. }
  1276. }
  1277. private void Chart_ViewChanged(object sender, ViewChangedArgs e)
  1278. {
  1279. if (this.ViewChanged != null)
  1280. {
  1281. this.ViewChanged(this, e);
  1282. }
  1283. }
  1284. private void ChartWinControl_AfterApplySkin(object sender, EventArgs e)
  1285. {
  1286. this.chart.ExtendYAxis(TwoYAxisType.AreaSame);
  1287. }
  1288. private void ChartWinControl_DoubleClick(object sender, EventArgs e)
  1289. {
  1290. if (this.MouseDownInfo.HitType == FormulaHitType.htAxisY)
  1291. {
  1292. this.AutoAdjustYAxis(this.MouseDownInfo.AxisY);
  1293. }
  1294. }
  1295. private void ChartWinControl_Enter(object sender, EventArgs e)
  1296. {
  1297. base.Invalidate();
  1298. }
  1299. private void ChartWinControl_KeyDown(object sender, KeyEventArgs e)
  1300. {
  1301. int start;
  1302. int cursorPos;
  1303. if (this.chart != null)
  1304. {
  1305. start = this.chart.Start;
  1306. cursorPos = this.chart.CursorPos;
  1307. int num3 = e.Control ? this.Page : 1;
  1308. switch (e.KeyCode)
  1309. {
  1310. case Keys.End:
  1311. this.chart.AdjustCursorByPos(this.ControlGraphics, 0x7fffffff, this.chart.Start);
  1312. e.Handled = true;
  1313. goto Label_0221;
  1314. case Keys.Home:
  1315. this.chart.AdjustCursorByPos(this.ControlGraphics, 0, this.chart.Start);
  1316. e.Handled = true;
  1317. goto Label_0221;
  1318. case Keys.Left:
  1319. this.chart.AdjustCursorByPos(this.ControlGraphics, this.chart.CursorPos - num3, this.chart.Start + (e.Shift ? num3 : 0));
  1320. e.Handled = true;
  1321. goto Label_0221;
  1322. case Keys.Up:
  1323. case Keys.Add:
  1324. if (e.Control)
  1325. {
  1326. this.NextArea(-1);
  1327. e.Handled = true;
  1328. }
  1329. else
  1330. {
  1331. this.ScaleChart(0.05);
  1332. }
  1333. goto Label_0221;
  1334. case Keys.Right:
  1335. this.chart.AdjustCursorByPos(this.ControlGraphics, this.chart.CursorPos + num3, this.chart.Start - (e.Shift ? num3 : 0));
  1336. e.Handled = true;
  1337. goto Label_0221;
  1338. case Keys.Down:
  1339. case Keys.Subtract:
  1340. if (e.Control)
  1341. {
  1342. this.NextArea(1);
  1343. e.Handled = true;
  1344. }
  1345. else
  1346. {
  1347. this.ScaleChart(-0.05);
  1348. }
  1349. goto Label_0221;
  1350. case Keys.Escape:
  1351. this.CancelMouseZoom();
  1352. base.Invalidate();
  1353. break;
  1354. case Keys.Multiply:
  1355. this.NextFormula(1);
  1356. e.Handled = true;
  1357. goto Label_0221;
  1358. case Keys.Divide:
  1359. this.NextFormula(-1);
  1360. e.Handled = true;
  1361. goto Label_0221;
  1362. case Keys.F7:
  1363. case Keys.F8:
  1364. this.NextCycle(1 - ((e.KeyCode == Keys.F8) ? 0 : 2));
  1365. e.Handled = true;
  1366. goto Label_0221;
  1367. }
  1368. }
  1369. return;
  1370. Label_0221:
  1371. if (e.Handled)
  1372. {
  1373. this.ChangeCursorPos();
  1374. }
  1375. if ((cursorPos != this.chart.CursorPos) && (start != this.chart.Start))
  1376. {
  1377. this.NeedRedraw();
  1378. }
  1379. if (this.needRedraw)
  1380. {
  1381. if (start != this.chart.Start)
  1382. {
  1383. this.MoveChartXBars(3, 1, start - this.chart.Start);
  1384. }
  1385. e.Handled = true;
  1386. this.needDrawCursor = true;
  1387. }
  1388. else
  1389. {
  1390. this.DrawCursorByPos(this.ControlGraphics);
  1391. }
  1392. }
  1393. private void ChartWinControl_MouseDown(object sender, MouseEventArgs e)
  1394. {
  1395. this.MouseDownInfo = this.chart.GetHitInfo((float)e.X, (float)e.Y);
  1396. if (this.MouseDownInfo.Area != null)
  1397. {
  1398. this.chart.SelectedArea = this.MouseDownInfo.Area;
  1399. if ((this.selectFormulaMouseMode == MouseAction.MouseDown) && !this.Designing)
  1400. {
  1401. this.chart.SetSelectedData(this.MouseDownInfo);
  1402. }
  1403. if (((e.Button != MouseButtons.Right) && (this.CrossCursorMouseMode == MouseAction.MouseDown)) && !this.Designing)
  1404. {
  1405. this.MouseCrossCursor(this.ControlGraphics, this.MouseDownInfo);
  1406. }
  1407. this.NeedRedraw();
  1408. }
  1409. if ((e.Button == MouseButtons.Right) && !this.Designing)
  1410. {
  1411. if (this.MouseZoomBmp != null)
  1412. {
  1413. this.CancelMouseZoom();
  1414. }
  1415. else if (base.Visible)
  1416. {
  1417. ContextMenu cmRight = this.cmRight;
  1418. if (!this.nativeContextMenu)
  1419. {
  1420. cmRight = this.ContextMenu;
  1421. }
  1422. if (cmRight != null)
  1423. {
  1424. cmRight.Show(this, new Point(e.X, e.Y));
  1425. }
  1426. }
  1427. }
  1428. else if (!this.Designing)
  1429. {
  1430. this.DragInfo = new ChartDragInfo(this.chart, this.MouseDownInfo);
  1431. if (((this.MouseDownInfo.HitType == FormulaHitType.htArea) && (this.mouseZoomMode != Easychart.Finance.Win.MouseZoomMode.None)) && !this.FixedTime)
  1432. {
  1433. this.LastX = e.X;
  1434. this.LastY = e.Y;
  1435. this.MemBmp = this.GetBitmap(false, true);
  1436. this.MouseZoomBmp = new Bitmap(this.MemBmp.Width, this.MemBmp.Height, PixelFormat.Format32bppPArgb);
  1437. this.MouseZoomBmpG = Graphics.FromImage(this.MouseZoomBmp);
  1438. this.HideCursor();
  1439. }
  1440. }
  1441. }
  1442. private void ChartWinControl_MouseLeave(object sender, EventArgs e)
  1443. {
  1444. if ((this.chart != null) && (this.CrossCursorMouseMode == MouseAction.MouseMove))
  1445. {
  1446. this.HideCursor();
  1447. }
  1448. }
  1449. private void ChartWinControl_MouseMove(object sender, MouseEventArgs e)
  1450. {
  1451. try
  1452. {
  1453. if (this.Designing)
  1454. {
  1455. return;
  1456. }
  1457. int totalPart = 3 - ((this.ChartDragMode == Easychart.Finance.ChartDragMode.Chart) ? 1 : 0);
  1458. if ((this.LastX == e.X) && (this.LastY == e.Y))
  1459. {
  1460. return;
  1461. }
  1462. FormulaHitInfo hitInfo = this.chart.GetHitInfo((float)e.X, (float)e.Y);
  1463. if (this.DragInfo != null)
  1464. {
  1465. float deltaY = this.DragInfo.HitInfo.Y - hitInfo.Y;
  1466. float deltaX = this.DragInfo.HitInfo.X - hitInfo.X;
  1467. FormulaArea fa = this.DragInfo.HitInfo.Area;
  1468. if (this.MouseZoomBmp != null)
  1469. {
  1470. RectangleF fixedZoomRect;
  1471. RectangleF ef2;
  1472. if (this.FixedZoomRect != Rectangle.Empty)
  1473. {
  1474. fixedZoomRect = this.FixedZoomRect;
  1475. fixedZoomRect.Offset((float)e.X, (float)e.Y);
  1476. ef2 = this.FixedZoomRect;
  1477. ef2.Offset((float)this.LastX, (float)this.LastY);
  1478. }
  1479. else
  1480. {
  1481. fixedZoomRect = this.GetRect(this.DragInfo.HitInfo.X, this.DragInfo.HitInfo.Y, (float)e.X, (float)e.Y);
  1482. ef2 = this.GetRect(this.DragInfo.HitInfo.X, this.DragInfo.HitInfo.Y, (float)this.LastX, (float)this.LastY);
  1483. }
  1484. this.MouseZoomRect = RectangleF.Union(fixedZoomRect, ef2);
  1485. this.MouseZoomBmpG.DrawImage(this.MemBmp, this.MouseZoomRect, this.MouseZoomRect, GraphicsUnit.Pixel);
  1486. Rectangle rect = Rectangle.Truncate(fixedZoomRect);
  1487. rect.Width--;
  1488. rect.Height--;
  1489. this.MouseZoomBmpG.DrawRectangle(Pens.Black, rect);
  1490. if (this.mouseZoomBackColor.A != 0)
  1491. {
  1492. this.MouseZoomBmpG.FillRectangle(new SolidBrush(this.mouseZoomBackColor), rect);
  1493. }
  1494. this.ControlGraphics.DrawImage(this.MouseZoomBmp, this.MouseZoomRect, this.MouseZoomRect, GraphicsUnit.Pixel);
  1495. }
  1496. else if (this.EnableResize && (this.DragInfo.HitInfo.HitType == FormulaHitType.htSize))
  1497. {
  1498. for (int i = 0; i < this.chart.Areas.Count; i++)
  1499. {
  1500. this.chart.Areas[i].HeightPercent = this.DragInfo.AreaHeight[i];
  1501. }
  1502. int index = this.chart.Areas.IndexOf(fa);
  1503. if (index < (this.chart.Areas.Count - 1))
  1504. {
  1505. FormulaArea area2 = this.chart.Areas[index + 1];
  1506. double num6 = this.DragInfo.AreaHeight[index] - deltaY;
  1507. double num7 = this.DragInfo.AreaHeight[index + 1] + deltaY;
  1508. if (num6 < 40.0)
  1509. {
  1510. num7 -= 40.0 - num6;
  1511. num6 = 40.0;
  1512. }
  1513. if (num7 < 40.0)
  1514. {
  1515. num6 -= 40.0 - num7;
  1516. num7 = 40.0;
  1517. }
  1518. fa.HeightPercent = num6;
  1519. area2.HeightPercent = num7;
  1520. this.NeedRedraw(fa);
  1521. this.NeedRedraw(area2);
  1522. }
  1523. this.areaPercent = this.chart.GetAreaPercent();
  1524. }
  1525. else if (this.ChartDragMode != Easychart.Finance.ChartDragMode.None)
  1526. {
  1527. if ((this.EnableXScale && !this.chart.FixedTime) && (this.DragInfo.HitInfo.HitType == FormulaHitType.htAxisX))
  1528. {
  1529. this.MoveChartX(fa, totalPart, this.DragInfo.HitInfo.XPart(totalPart), deltaX);
  1530. }
  1531. else if (this.EnableYScale && (this.DragInfo.HitInfo.HitType == FormulaHitType.htAxisY))
  1532. {
  1533. this.MoveChartY(fa, totalPart, this.DragInfo.HitInfo.YPart(totalPart), deltaY);
  1534. }
  1535. else if ((this.ChartDragMode == Easychart.Finance.ChartDragMode.Chart) && (this.DragInfo.HitInfo.HitType == FormulaHitType.htArea))
  1536. {
  1537. if (!this.chart.FixedTime)
  1538. {
  1539. this.MoveChartX(fa, 3, 1, deltaX);
  1540. }
  1541. this.MoveChartY(fa, 3, 1, deltaY);
  1542. }
  1543. }
  1544. }
  1545. else
  1546. {
  1547. if (this.CrossCursorMouseMode == MouseAction.MouseMove)
  1548. {
  1549. this.MouseCrossCursor(this.ControlGraphics, hitInfo);
  1550. }
  1551. if ((this.selectFormulaMouseMode == MouseAction.MouseMove) && !object.Equals(this.chart.GetSelectedData(), hitInfo.Data))
  1552. {
  1553. this.chart.SetSelectedData(hitInfo);
  1554. this.NeedRedraw();
  1555. }
  1556. if (hitInfo.Area != null)
  1557. {
  1558. switch (hitInfo.HitType)
  1559. {
  1560. case FormulaHitType.htSize:
  1561. if (this.EnableResize)
  1562. {
  1563. this.Cursor = Cursors.HSplit;
  1564. }
  1565. goto Label_05D3;
  1566. case FormulaHitType.htAxisX:
  1567. {
  1568. if ((!this.EnableXScale || this.chart.FixedTime) || (this.ChartDragMode == Easychart.Finance.ChartDragMode.None))
  1569. {
  1570. goto Label_0518;
  1571. }
  1572. int num8 = hitInfo.XPart(totalPart);
  1573. if ((num8 != 0) && (num8 != (totalPart - 1)))
  1574. {
  1575. break;
  1576. }
  1577. this.Cursor = Cursors.SizeWE;
  1578. goto Label_05D3;
  1579. }
  1580. case FormulaHitType.htAxisY:
  1581. {
  1582. if (!this.EnableYScale || (this.ChartDragMode == Easychart.Finance.ChartDragMode.None))
  1583. {
  1584. goto Label_0568;
  1585. }
  1586. int num9 = hitInfo.YPart(totalPart);
  1587. if ((num9 != 0) && (num9 != (totalPart - 1)))
  1588. {
  1589. goto Label_055B;
  1590. }
  1591. this.Cursor = Cursors.SizeNS;
  1592. goto Label_05D3;
  1593. }
  1594. case FormulaHitType.htArea:
  1595. if (this.selectFormulaMouseMode == MouseAction.None)
  1596. {
  1597. goto Label_05B7;
  1598. }
  1599. if (hitInfo.Formula == null)
  1600. {
  1601. goto Label_05A9;
  1602. }
  1603. this.Cursor = Cursors.Hand;
  1604. goto Label_05D3;
  1605. default:
  1606. this.Cursor = this.DefaultCursor;
  1607. goto Label_05D3;
  1608. }
  1609. this.Cursor = Cursors.Hand;
  1610. }
  1611. }
  1612. goto Label_05D3;
  1613. Label_0518:
  1614. this.Cursor = this.DefaultCursor;
  1615. goto Label_05D3;
  1616. Label_055B:
  1617. this.Cursor = Cursors.Hand;
  1618. goto Label_05D3;
  1619. Label_0568:
  1620. this.Cursor = this.DefaultCursor;
  1621. goto Label_05D3;
  1622. Label_05A9:
  1623. this.Cursor = this.DefaultCursor;
  1624. goto Label_05D3;
  1625. Label_05B7:
  1626. this.Cursor = this.DefaultCursor;
  1627. Label_05D3:
  1628. this.LastX = e.X;
  1629. this.LastY = e.Y;
  1630. if (this.AfterMouseMove != null)
  1631. {
  1632. this.AfterMouseMove(this, e, hitInfo);
  1633. }
  1634. }
  1635. catch
  1636. {
  1637. }
  1638. }
  1639. private void ChartWinControl_MouseUp(object sender, MouseEventArgs e)
  1640. {
  1641. if (this.DragInfo != null)
  1642. {
  1643. this.DragInfo = null;
  1644. base.Invalidate();
  1645. }
  1646. if (this.MouseZoomBmp != null)
  1647. {
  1648. if (((e.Button == MouseButtons.Left) && !this.MouseZoomRect.IsEmpty) && (this.MouseZoomRect.Width > 100f))
  1649. {
  1650. FormulaHitInfo hitInfo = this.chart.GetHitInfo(this.MouseZoomRect.X, this.MouseZoomRect.Y);
  1651. FormulaHitInfo info2 = this.chart.GetHitInfo(this.MouseZoomRect.Right, this.MouseZoomRect.Bottom);
  1652. int cursorPos = hitInfo.CursorPos;
  1653. int num2 = info2.CursorPos;
  1654. if (this.chart.DataProvider != null)
  1655. {
  1656. double[] numArray = this.chart.DataProvider["DATE"];
  1657. if (cursorPos < numArray.Length)
  1658. {
  1659. this.StartTime = this.chart.IndexToDate(hitInfo.CursorPos);
  1660. this.EndTime = this.chart.IndexToDate(info2.CursorPos);
  1661. }
  1662. }
  1663. }
  1664. this.MouseZoomBmp = null;
  1665. this.MouseZoomRect = Rectangle.Empty;
  1666. }
  1667. }
  1668. private void ChartWinControl_MouseWheel(object sender, MouseEventArgs e)
  1669. {
  1670. if (((this.mouseWheelMode != Easychart.Finance.Win.MouseWheelMode.None) && (this.chart != null)) && !this.FixedTime)
  1671. {
  1672. int moveBars = Math.Sign(e.Delta) * (((Control.ModifierKeys & Keys.Alt) != Keys.None) ? 1 : 12);
  1673. if (this.mouseWheelMode == Easychart.Finance.Win.MouseWheelMode.Scroll)
  1674. {
  1675. this.MoveChartXBars(3, 1, moveBars);
  1676. }
  1677. //删除滑动放大
  1678. //else
  1679. //{
  1680. // this.ScaleChart(((double)moveBars) / 100.0);
  1681. //}
  1682. this.needResetCursorPos = true;
  1683. this.needDrawCursor = false;
  1684. this.LastHitInfo = this.chart.GetHitInfo((float)e.X, (float)e.Y);
  1685. }
  1686. }
  1687. private void ChartWinControl_Paint(object sender, PaintEventArgs e)
  1688. {
  1689. if (this.chart != null)
  1690. {
  1691. this.StatisticWindow.Visible = this.showStatistic && this.StatisticWindow.HasData();
  1692. if (this.needSetDefaultFormulas)
  1693. {
  1694. this.DefaultFormulasToAreas();
  1695. this.needSetDefaultFormulas = false;
  1696. }
  1697. if (this.needRefresh)
  1698. {
  1699. this.RecreateFormula();
  1700. }
  1701. bool flag = true;
  1702. if (this.needRebind)
  1703. {
  1704. flag = this.BindData();
  1705. }
  1706. if (this.needRedraw && flag)
  1707. {
  1708. if (this.chart.FixedTime && (this.CurrentDataManager != null))
  1709. {
  1710. this.chart.StartTime = this.startTime;
  1711. this.chart.EndTime = this.endTime;
  1712. }
  1713. else if (this.chart.DataProvider != null)
  1714. {
  1715. double[] numArray = this.chart.DataProvider["DATE"];
  1716. if (this.endTime == DateTime.MinValue)
  1717. {
  1718. if (numArray.Length > 0)
  1719. {
  1720. this.chart.EndTime = DateTime.FromOADate(numArray[numArray.Length - 1]);
  1721. this.chart.StartTime = DateTime.FromOADate(numArray[Math.Max(0, numArray.Length - this.stockBars)]);
  1722. this.EndTime = this.chart.EndTime;
  1723. this.StartTime = this.chart.StartTime;
  1724. }
  1725. }
  1726. else
  1727. {
  1728. int num2;
  1729. int num = this.chart.DateToIndex(this.endTime);
  1730. if (this.afterBars < 1.0)
  1731. {
  1732. num2 = (int)((numArray.Length - 1) * (1.0 + this.afterBars));
  1733. }
  1734. else
  1735. {
  1736. num2 = (numArray.Length - 1) + ((int)this.afterBars);
  1737. }
  1738. if (num > num2)
  1739. {
  1740. this.endTime = this.chart.IndexToDate(num2);
  1741. }
  1742. this.chart.StartTime = this.startTime;
  1743. this.chart.EndTime = this.endTime;
  1744. }
  1745. }
  1746. FormulaArea mainArea = this.chart.MainArea;
  1747. if (mainArea != null)
  1748. {
  1749. if (this.minPrice > 0.0)
  1750. {
  1751. mainArea.AxisY.MinY = this.minPrice;
  1752. mainArea.AxisY.MaxY = this.maxPrice;
  1753. mainArea.AxisY.AutoScale = false;
  1754. }
  1755. if (this.stockRenderType != Easychart.Finance.StockRenderType.Default)
  1756. {
  1757. mainArea.StockRenderType = this.stockRenderType;
  1758. }
  1759. if (this.HasData() && (this.scaleType != Easychart.Finance.ScaleType.Default))
  1760. {
  1761. mainArea.AxisY.Scale = this.scaleType;
  1762. }
  1763. }
  1764. this.chart.ValueTextMode = this.valueTextMode;
  1765. if (this.stickRenderType != Easychart.Finance.StickRenderType.Default)
  1766. {
  1767. this.chart.StickRenderType = this.stickRenderType;
  1768. }
  1769. this.chart.LatestValueType = this.latestValueType;
  1770. this.chart.ShowCursorLabel = this.showCursorLabel;
  1771. if (this.showVerticalGrid != ShowLineMode.Default)
  1772. {
  1773. if (this.showVerticalGrid == ShowLineMode.HidePrice)
  1774. {
  1775. mainArea.AxisY.MajorTick.ShowLine = false;
  1776. }
  1777. else
  1778. {
  1779. foreach (FormulaArea area2 in this.chart.Areas)
  1780. {
  1781. area2.AxisY.MajorTick.ShowLine = this.showVerticalGrid == ShowLineMode.Show;
  1782. }
  1783. }
  1784. }
  1785. if (this.showHorizontalGrid != ShowLineMode.Default)
  1786. {
  1787. if (this.showHorizontalGrid == ShowLineMode.HidePrice)
  1788. {
  1789. mainArea.AxisX.MajorTick.ShowLine = false;
  1790. }
  1791. else
  1792. {
  1793. foreach (FormulaArea area3 in this.chart.Areas)
  1794. {
  1795. area3.AxisX.MajorTick.ShowLine = this.showHorizontalGrid == ShowLineMode.Show;
  1796. }
  1797. }
  1798. }
  1799. this.chart.NeedRedraw = true;
  1800. this.chart.ExtraNeedRedraw = true;
  1801. }
  1802. if (this.needResetCursorPos)
  1803. {
  1804. this.SetCursorPos();
  1805. this.ChangeCursorPos();
  1806. this.needResetCursorPos = false;
  1807. }
  1808. this.RenderChart(e.Graphics);
  1809. this.needRedraw = false;
  1810. this.needRebind = false;
  1811. this.needRefresh = false;
  1812. e.Graphics.Dispose();
  1813. }
  1814. }
  1815. private void ChartWinControl_SizeChanged(object sender, EventArgs e)
  1816. {
  1817. this.ControlGraphics = base.CreateGraphics();
  1818. if (this.chart != null)
  1819. {
  1820. Rectangle clientRectangle = base.ClientRectangle;
  1821. this.chart.Rect = clientRectangle;
  1822. }
  1823. else
  1824. {
  1825. this.ControlGraphics.Clear(this.BackColor);
  1826. }
  1827. this.NeedRedraw();
  1828. }
  1829. public void CloseArea(FormulaArea fa)
  1830. {
  1831. int index = this.chart.Areas.IndexOf(fa);
  1832. if ((index >= 0) && (this.chart.Areas.Count > 1))
  1833. {
  1834. this.chart.Areas.RemoveAt(index);
  1835. this.areaPercent = this.chart.GetAreaPercent();
  1836. this.SaveChartProperties();
  1837. this.NeedRebind();
  1838. }
  1839. }
  1840. private void cmRight_Popup(object sender, EventArgs e)
  1841. {
  1842. this.miStatisticWindow.Checked = this.ShowStatistic;
  1843. this.miAdjust.Checked = this.AdjustData;
  1844. FormulaArea selectedArea = this.chart.SelectedArea;
  1845. if (selectedArea != null)
  1846. {
  1847. this.miFavorite.Enabled = !selectedArea.IsMain();
  1848. if (selectedArea.Formulas.Count > 0)
  1849. {
  1850. foreach (MenuItem item in this.miFavorite.MenuItems)
  1851. {
  1852. item.Checked = string.Compare(item.Text, selectedArea.Formulas[0].Name, true) == 0;
  1853. }
  1854. }
  1855. }
  1856. }
  1857. public void CopyAreaToClipboard(string Separatar)
  1858. {
  1859. Clipboard.SetDataObject(this.chart.GetAreaTextData(Separatar, true));
  1860. }
  1861. public void CopyToClipboard(string Separatar)
  1862. {
  1863. Clipboard.SetDataObject(this.chart.GetChartTextData(Separatar, true));
  1864. }
  1865. private void CreateCycleMenu()
  1866. {
  1867. if (this.favoriteCycles != null)
  1868. {
  1869. this.miCycle.MenuItems.Clear();
  1870. foreach (string str in this.favoriteCycles.Split(new char[] { ';' }))
  1871. {
  1872. this.miCycle.MenuItems.Add(str, new EventHandler(this.miCycle_SelectedIndexChanged));
  1873. }
  1874. }
  1875. }
  1876. private void DefaultFormulasToAreas()
  1877. {
  1878. if (this.defaultFormulas != null)
  1879. {
  1880. this.chart.Areas.Clear();
  1881. this.chart.StringsToArea(this.defaultFormulas.Split(new char[] { ';' }));
  1882. }
  1883. }
  1884. private static string DefaultSelectFormula(string Default, string[] FilterPrefixes, bool SelectLine)
  1885. {
  1886. return new SelectFormula().Select(Default, FilterPrefixes, SelectLine);
  1887. }
  1888. private static string DefaultSelectMethod(string Default)
  1889. {
  1890. return new SelectMethod().Select(Default);
  1891. }
  1892. protected override void Dispose(bool disposing)
  1893. {
  1894. if (disposing && (this.components != null))
  1895. {
  1896. this.components.Dispose();
  1897. }
  1898. base.Dispose(disposing);
  1899. }
  1900. public static string DoSelectFormula(string Default, string[] FilterPrefixes, bool SelectLine)
  1901. {
  1902. if (OnSelectFormula != null)
  1903. {
  1904. return OnSelectFormula(Default, FilterPrefixes, SelectLine);
  1905. }
  1906. return Default;
  1907. }
  1908. public static string DoSelectSymbol(string Default)
  1909. {
  1910. if (OnSelectSymbol != null)
  1911. {
  1912. return OnSelectSymbol(Default);
  1913. }
  1914. return Default;
  1915. }
  1916. private void DrawCursor(Graphics g)
  1917. {
  1918. this.chart.DrawCursor(g, this.LastHitInfo.X, this.LastHitInfo.Y, false);
  1919. }
  1920. private void DrawCursorByPos(Graphics g)
  1921. {
  1922. this.DrawCursorByPos(g, float.NaN);
  1923. }
  1924. private void DrawCursorByPos(Graphics g, float DefaultY)
  1925. {
  1926. float num;
  1927. float num2;
  1928. this.chart.GetXYFromPos(out num, out num2);
  1929. this.LastHitInfo = this.chart.GetHitInfo(num, num2);
  1930. if (!float.IsNaN(DefaultY))
  1931. {
  1932. this.LastHitInfo.Y = DefaultY;
  1933. }
  1934. if ((this.LastHitInfo.HitType == FormulaHitType.htArea) && (g != null))
  1935. {
  1936. this.DrawCursor(g);
  1937. }
  1938. else
  1939. {
  1940. this.LastHitInfo.X = -1f;
  1941. }
  1942. }
  1943. public void DrawCursorByTime(DateTime t)
  1944. {
  1945. int num = this.chart.DateToIndex(t.ToOADate());
  1946. if (num != this.chart.CursorPos)
  1947. {
  1948. this.chart.CursorPos = num;
  1949. this.DrawCursorByPos(this.ControlGraphics, -1f);
  1950. this.ChangeCursorPos();
  1951. }
  1952. }
  1953. public void EditFormula()
  1954. {
  1955. FormulaArea selectedArea = this.chart.SelectedArea;
  1956. if ((selectedArea != null) && (selectedArea.Formulas.Count > 0))
  1957. {
  1958. FormulaBase fb = null;
  1959. if (selectedArea.SelectedFormula != null)
  1960. {
  1961. fb = selectedArea.SelectedFormula;
  1962. }
  1963. else
  1964. {
  1965. fb = selectedArea.Formulas[0];
  1966. }
  1967. if (EditFormula(fb))
  1968. {
  1969. return;
  1970. }
  1971. }
  1972. MessageBox.Show("Can't edit the source code of this formula");
  1973. }
  1974. public void EditFormula(FormulaArea fa)
  1975. {
  1976. if (fa != null)
  1977. {
  1978. FormulaManager manager = new FormulaManager();
  1979. if (manager.ShowForm(fa, fa.SelectedFormula) == DialogResult.OK)
  1980. {
  1981. this.SetAreaByName(fa, manager.CurrentFormulas);
  1982. }
  1983. }
  1984. else
  1985. {
  1986. this.EditOverlay();
  1987. }
  1988. }
  1989. public static bool EditFormula(FormulaBase fb)
  1990. {
  1991. string formulaFile = PluginManager.GetFormulaFile(fb);
  1992. if (formulaFile != null)
  1993. {
  1994. string directoryName = Path.GetDirectoryName(formulaFile);
  1995. formulaFile = Path.GetFileNameWithoutExtension(formulaFile).Replace('_', '.');
  1996. formulaFile = directoryName + @"\" + formulaFile;
  1997. if (File.Exists(formulaFile))
  1998. {
  1999. OpenFormulaSourceEditor(formulaFile, fb.GetType().ToString());
  2000. return true;
  2001. }
  2002. }
  2003. return false;
  2004. }
  2005. public void EditOverlay()
  2006. {
  2007. }
  2008. private void ExpandDefaultFormulas(int Count)
  2009. {
  2010. double percent = this.chart.Areas[0].HeightPercent / 3.0;
  2011. if (percent < 1.0)
  2012. {
  2013. percent = 1.0;
  2014. }
  2015. while (Count > this.chart.Areas.Count)
  2016. {
  2017. this.chart.AddArea("VOLMA", percent);
  2018. }
  2019. }
  2020. public MenuItem GetAreaMenu(int Count)
  2021. {
  2022. this.miIndicator.MenuItems.Clear();
  2023. for (int i = 0; i < Count; i++)
  2024. {
  2025. this.miIndicator.MenuItems.Add(new MenuItem(string.Concat(new object[] { "&", i + 1, " area", (i > 0) ? "s" : "" }), new EventHandler(this.miIndicator_SelectedIndexChanged), (Shortcut)(0x40031 + i)));
  2026. }
  2027. return this.miIndicator;
  2028. }
  2029. public MenuItem GetAxisMenu()
  2030. {
  2031. return this.miAxisType;
  2032. }
  2033. public Bitmap GetBitmap(bool ShowStatistic, bool ShowExtra)
  2034. {
  2035. this.chart.ExtraNeedRedraw = ShowExtra;
  2036. Bitmap memBitmap = this.chart.GetMemBitmap();
  2037. Bitmap image = new Bitmap(memBitmap);
  2038. Graphics g = Graphics.FromImage(image);
  2039. g.DrawImage(memBitmap, 0, 0);
  2040. g.DrawLine(Pens.Black, 0, 0, image.Width, 0);
  2041. if (ShowStatistic)
  2042. {
  2043. this.StatisticWindow.PaintTo(g);
  2044. }
  2045. return image;
  2046. }
  2047. public MenuItem GetChartMenu()
  2048. {
  2049. return this.GetChartMenu(true, true, true, true);
  2050. }
  2051. public MenuItem GetChartMenu(bool Skin, bool Cycle, bool Area, bool Axis)
  2052. {
  2053. this.miChart.MenuItems.Clear();
  2054. if (Skin)
  2055. {
  2056. this.miChart.MenuItems.Add(this.GetSkinMenu());
  2057. }
  2058. if (Cycle)
  2059. {
  2060. this.miChart.MenuItems.Add(this.miCycle);
  2061. }
  2062. if (Area)
  2063. {
  2064. this.miChart.MenuItems.Add(this.GetAreaMenu(9));
  2065. }
  2066. if (Axis)
  2067. {
  2068. this.miChart.MenuItems.Add(this.GetAxisMenu());
  2069. }
  2070. return this.miChart;
  2071. }
  2072. public DateTime GetCurrentTime()
  2073. {
  2074. return this.chart.IndexToDate();
  2075. }
  2076. public MenuItem GetEditMenu()
  2077. {
  2078. return this.miChartEdit;
  2079. }
  2080. private RectangleF GetRect(float x1, float y1, float x2, float y2)
  2081. {
  2082. return new RectangleF(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs((float)(x2 - x1)), Math.Abs((float)(y2 - y1)));
  2083. }
  2084. public MenuItem GetSkinMenu()
  2085. {
  2086. string[] buildInSkins = FormulaSkin.GetBuildInSkins();
  2087. this.miSkin.MenuItems.Clear();
  2088. foreach (string str in buildInSkins)
  2089. {
  2090. this.miSkin.MenuItems.Add(str, new EventHandler(this.mmSkin_SelectedIndexChanged));
  2091. }
  2092. return this.miSkin;
  2093. }
  2094. public MenuItem GetViewMenu()
  2095. {
  2096. return this.miView;
  2097. }
  2098. public void HandleKeyEvent(object sender, KeyEventArgs e)
  2099. {
  2100. if (base.ContainsFocus)
  2101. {
  2102. this.OnKeyDown(e);
  2103. }
  2104. }
  2105. private bool HasData()
  2106. {
  2107. return ((this.chart != null) && (this.chart.DataProvider != null));
  2108. }
  2109. private void HideCursor()
  2110. {
  2111. this.chart.HideCursor(this.ControlGraphics);
  2112. }
  2113. private void InitializeComponent()
  2114. {
  2115. this.cmRight = new System.Windows.Forms.ContextMenu();
  2116. this.miAddFormula = new System.Windows.Forms.MenuItem();
  2117. this.miCloseFormula = new System.Windows.Forms.MenuItem();
  2118. this.miFormulaManager = new System.Windows.Forms.MenuItem();
  2119. this.miEdit = new System.Windows.Forms.MenuItem();
  2120. this.miFavorite = new System.Windows.Forms.MenuItem();
  2121. this.miSp4 = new System.Windows.Forms.MenuItem();
  2122. this.miStatisticWindow = new System.Windows.Forms.MenuItem();
  2123. this.miAdjust = new System.Windows.Forms.MenuItem();
  2124. this.miSp2 = new System.Windows.Forms.MenuItem();
  2125. this.miCopy = new System.Windows.Forms.MenuItem();
  2126. this.cmMain = new System.Windows.Forms.ContextMenu();
  2127. this.miChart = new System.Windows.Forms.MenuItem();
  2128. this.miSkin = new System.Windows.Forms.MenuItem();
  2129. this.miCycle = new System.Windows.Forms.MenuItem();
  2130. this.miIndicator = new System.Windows.Forms.MenuItem();
  2131. this.miAxisType = new System.Windows.Forms.MenuItem();
  2132. this.miNormal = new System.Windows.Forms.MenuItem();
  2133. this.miLog = new System.Windows.Forms.MenuItem();
  2134. this.miView = new System.Windows.Forms.MenuItem();
  2135. this.miCrossCursor = new System.Windows.Forms.MenuItem();
  2136. this.miStatistic = new System.Windows.Forms.MenuItem();
  2137. this.miSp1 = new System.Windows.Forms.MenuItem();
  2138. this.miCalculator = new System.Windows.Forms.MenuItem();
  2139. this.miChartEdit = new System.Windows.Forms.MenuItem();
  2140. this.miChartCopy = new System.Windows.Forms.MenuItem();
  2141. this.StatisticWindow = new Easychart.Finance.Win.StatisticControl();
  2142. this.SuspendLayout();
  2143. //
  2144. // cmRight
  2145. //
  2146. this.cmRight.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  2147. this.miAddFormula,
  2148. this.miCloseFormula,
  2149. this.miFormulaManager,
  2150. this.miEdit,
  2151. this.miFavorite,
  2152. this.miSp4,
  2153. this.miStatisticWindow,
  2154. this.miAdjust,
  2155. this.miSp2,
  2156. this.miCopy});
  2157. this.cmRight.Popup += new System.EventHandler(this.cmRight_Popup);
  2158. //
  2159. // miAddFormula
  2160. //
  2161. this.miAddFormula.Index = 0;
  2162. this.miAddFormula.Text = "&Add New Formula Area";
  2163. this.miAddFormula.Click += new System.EventHandler(this.miAddFormula_Click);
  2164. //
  2165. // miCloseFormula
  2166. //
  2167. this.miCloseFormula.Index = 1;
  2168. this.miCloseFormula.MergeOrder = 10;
  2169. this.miCloseFormula.Text = "Close Selected Formula";
  2170. this.miCloseFormula.Click += new System.EventHandler(this.miCloseFormula_Click);
  2171. //
  2172. // miFormulaManager
  2173. //
  2174. this.miFormulaManager.Index = 2;
  2175. this.miFormulaManager.MergeOrder = 20;
  2176. this.miFormulaManager.Text = "E&dit Formula";
  2177. this.miFormulaManager.Click += new System.EventHandler(this.miFormulaEditor_Click);
  2178. //
  2179. // miEdit
  2180. //
  2181. this.miEdit.Index = 3;
  2182. this.miEdit.MergeOrder = 30;
  2183. this.miEdit.Shortcut = System.Windows.Forms.Shortcut.CtrlE;
  2184. this.miEdit.Text = "&Edit Formula Source Code";
  2185. this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
  2186. //
  2187. // miFavorite
  2188. //
  2189. this.miFavorite.Index = 4;
  2190. this.miFavorite.MergeOrder = 40;
  2191. this.miFavorite.Text = "&Favorite Indicators";
  2192. //
  2193. // miSp4
  2194. //
  2195. this.miSp4.Index = 5;
  2196. this.miSp4.MergeOrder = 50;
  2197. this.miSp4.Text = "-";
  2198. //
  2199. // miStatisticWindow
  2200. //
  2201. this.miStatisticWindow.Index = 6;
  2202. this.miStatisticWindow.MergeOrder = 80;
  2203. this.miStatisticWindow.Text = "Show &statistic window";
  2204. this.miStatisticWindow.Click += new System.EventHandler(this.miStatisticWindow_Click);
  2205. //
  2206. // miAdjust
  2207. //
  2208. this.miAdjust.Index = 7;
  2209. this.miAdjust.MergeOrder = 90;
  2210. this.miAdjust.Text = "&Adjust Data";
  2211. this.miAdjust.Click += new System.EventHandler(this.miAdjust_Click);
  2212. //
  2213. // miSp2
  2214. //
  2215. this.miSp2.Index = 8;
  2216. this.miSp2.MergeOrder = 100;
  2217. this.miSp2.Text = "-";
  2218. //
  2219. // miCopy
  2220. //
  2221. this.miCopy.Index = 9;
  2222. this.miCopy.MergeOrder = 110;
  2223. this.miCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
  2224. this.miCopy.Text = "&Copy";
  2225. this.miCopy.Click += new System.EventHandler(this.miCopy_Click);
  2226. //
  2227. // cmMain
  2228. //
  2229. this.cmMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  2230. this.miChart,
  2231. this.miView,
  2232. this.miChartEdit});
  2233. //
  2234. // miChart
  2235. //
  2236. this.miChart.Index = 0;
  2237. this.miChart.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  2238. this.miSkin,
  2239. this.miCycle,
  2240. this.miIndicator,
  2241. this.miAxisType});
  2242. this.miChart.Text = "&Chart";
  2243. //
  2244. // miSkin
  2245. //
  2246. this.miSkin.Index = 0;
  2247. this.miSkin.Text = "&Skin";
  2248. //
  2249. // miCycle
  2250. //
  2251. this.miCycle.Index = 1;
  2252. this.miCycle.Text = "&Cycle";
  2253. this.miCycle.Click += new System.EventHandler(this.miCycle_Popup);
  2254. //
  2255. // miIndicator
  2256. //
  2257. this.miIndicator.Index = 2;
  2258. this.miIndicator.Text = "&Indicator Areas";
  2259. //
  2260. // miAxisType
  2261. //
  2262. this.miAxisType.Index = 3;
  2263. this.miAxisType.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  2264. this.miNormal,
  2265. this.miLog});
  2266. this.miAxisType.Text = "&Axis Type";
  2267. //
  2268. // miNormal
  2269. //
  2270. this.miNormal.Index = 0;
  2271. this.miNormal.RadioCheck = true;
  2272. this.miNormal.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
  2273. this.miNormal.Text = "Normal";
  2274. this.miNormal.Click += new System.EventHandler(this.miNormalAxis_Click);
  2275. //
  2276. // miLog
  2277. //
  2278. this.miLog.Index = 1;
  2279. this.miLog.MergeOrder = 1;
  2280. this.miLog.RadioCheck = true;
  2281. this.miLog.Shortcut = System.Windows.Forms.Shortcut.CtrlL;
  2282. this.miLog.Text = "Logarithm";
  2283. this.miLog.Click += new System.EventHandler(this.miNormalAxis_Click);
  2284. //
  2285. // miView
  2286. //
  2287. this.miView.Index = 1;
  2288. this.miView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  2289. this.miCrossCursor,
  2290. this.miStatistic,
  2291. this.miSp1,
  2292. this.miCalculator});
  2293. this.miView.Text = "&View";
  2294. this.miView.Popup += new System.EventHandler(this.miView_Popup);
  2295. //
  2296. // miCrossCursor
  2297. //
  2298. this.miCrossCursor.Checked = true;
  2299. this.miCrossCursor.Index = 0;
  2300. this.miCrossCursor.Text = "Cross Cursor";
  2301. this.miCrossCursor.Click += new System.EventHandler(this.miCrossCursor_Click);
  2302. //
  2303. // miStatistic
  2304. //
  2305. this.miStatistic.Index = 1;
  2306. this.miStatistic.Text = "Statistic Window";
  2307. this.miStatistic.Click += new System.EventHandler(this.miStatistic_Click);
  2308. //
  2309. // miSp1
  2310. //
  2311. this.miSp1.Index = 2;
  2312. this.miSp1.Text = "-";
  2313. //
  2314. // miCalculator
  2315. //
  2316. this.miCalculator.Index = 3;
  2317. this.miCalculator.Shortcut = System.Windows.Forms.Shortcut.CtrlJ;
  2318. this.miCalculator.Text = "&Calculator";
  2319. this.miCalculator.Click += new System.EventHandler(this.miCalculator_Click);
  2320. //
  2321. // miChartEdit
  2322. //
  2323. this.miChartEdit.Index = 2;
  2324. this.miChartEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  2325. this.miChartCopy});
  2326. this.miChartEdit.Text = "&Edit";
  2327. //
  2328. // miChartCopy
  2329. //
  2330. this.miChartCopy.Index = 0;
  2331. this.miChartCopy.Text = "&Copy";
  2332. this.miChartCopy.Click += new System.EventHandler(this.miChartCopy_Click);
  2333. //
  2334. // StatisticWindow
  2335. //
  2336. this.StatisticWindow.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  2337. this.StatisticWindow.BackColor = System.Drawing.SystemColors.Info;
  2338. this.StatisticWindow.Cursor = System.Windows.Forms.Cursors.Arrow;
  2339. this.StatisticWindow.ForeColor = System.Drawing.Color.Black;
  2340. this.StatisticWindow.Location = new System.Drawing.Point(-1000, 35);
  2341. this.StatisticWindow.Name = "StatisticWindow";
  2342. this.StatisticWindow.Size = new System.Drawing.Size(192, 296);
  2343. this.StatisticWindow.TabIndex = 0;
  2344. this.StatisticWindow.Visible = false;
  2345. //
  2346. // ChartWinControl
  2347. //
  2348. this.CausesValidation = false;
  2349. this.Controls.Add(this.StatisticWindow);
  2350. this.Name = "ChartWinControl";
  2351. this.Size = new System.Drawing.Size(584, 427);
  2352. this.SizeChanged += new System.EventHandler(this.ChartWinControl_SizeChanged);
  2353. this.Paint += new System.Windows.Forms.PaintEventHandler(this.ChartWinControl_Paint);
  2354. this.DoubleClick += new System.EventHandler(this.ChartWinControl_DoubleClick);
  2355. this.Enter += new System.EventHandler(this.ChartWinControl_Enter);
  2356. this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ChartWinControl_KeyDown);
  2357. this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ChartWinControl_MouseDown);
  2358. this.MouseLeave += new System.EventHandler(this.ChartWinControl_MouseLeave);
  2359. this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ChartWinControl_MouseMove);
  2360. this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ChartWinControl_MouseUp);
  2361. this.ResumeLayout(false);
  2362. }
  2363. public void InsertNewFormula()
  2364. {
  2365. this.InsertNewFormula("");
  2366. }
  2367. public void InsertNewFormula(string Default)
  2368. {
  2369. FormulaArea fa = new FormulaArea(this.chart);
  2370. FormulaManager manager = new FormulaManager();
  2371. manager.CurrentFormulas = Default;
  2372. if (manager.ShowForm() == DialogResult.OK)
  2373. {
  2374. fa.HeightPercent = this.chart[0].HeightPercent / 3.0;
  2375. this.chart.Areas.Add(fa);
  2376. this.SetAreaByName(fa, manager.CurrentFormulas);
  2377. this.NeedRebind();
  2378. }
  2379. }
  2380. private void InvalidateHitInfo(FormulaHitInfo fhi)
  2381. {
  2382. Region region = new Region(new RectangleF(fhi.X - 1f, 0f, 2f, (float)this.chart.Rect.Height));
  2383. region.Union(new RectangleF(0f, fhi.Y - 1f, (float)this.chart.Rect.Width, 2f));
  2384. foreach (FormulaArea area in this.chart.Areas)
  2385. {
  2386. RectangleF lastCursorRect = area.AxisX.LastCursorRect;
  2387. region.Union(new RectangleF(fhi.X - lastCursorRect.Width, lastCursorRect.Y, lastCursorRect.Width * 2f, lastCursorRect.Height));
  2388. region.Union(new RectangleF((float)area.Rect.X, (float)area.Rect.Y, (float)area.Rect.Width, 20f));
  2389. foreach (FormulaAxisY sy in area.AxisYs)
  2390. {
  2391. lastCursorRect = sy.LastCursorRect;
  2392. if (!lastCursorRect.IsEmpty)
  2393. {
  2394. region.Union(new RectangleF(lastCursorRect.X, fhi.Y, lastCursorRect.Width, lastCursorRect.Height));
  2395. }
  2396. }
  2397. }
  2398. base.Invalidate(region);
  2399. }
  2400. public void MergeRightMenu(ContextMenu cm)
  2401. {
  2402. this.cmRight.MergeMenu(cm);
  2403. }
  2404. /// <summary>
  2405. /// hulu
  2406. /// </summary>
  2407. /// <param name="sender"></param>
  2408. /// <param name="e"></param>
  2409. public void mi_Checked(MenuItem mi)
  2410. {
  2411. foreach (MenuItem item in this.miSkin.MenuItems)
  2412. {
  2413. item.Checked = false;
  2414. }
  2415. //MenuItem item2 = mi;
  2416. mi.Checked = true;
  2417. string text = mi.Text;
  2418. this.Skin = text;
  2419. }
  2420. private void miAddFormula_Click(object sender, EventArgs e)
  2421. {
  2422. this.InsertNewFormula();
  2423. }
  2424. private void miAdjust_Click(object sender, EventArgs e)
  2425. {
  2426. this.AdjustData = !this.AdjustData;
  2427. }
  2428. private void miCalculator_Click(object sender, EventArgs e)
  2429. {
  2430. Process.Start("Calc.exe");
  2431. }
  2432. private void miChartCopy_Click(object sender, EventArgs e)
  2433. {
  2434. this.CopyToClipboard(",");
  2435. }
  2436. private void miCloseFormula_Click(object sender, EventArgs e)
  2437. {
  2438. this.CloseArea(this.chart.SelectedArea);
  2439. }
  2440. private void miCopy_Click(object sender, EventArgs e)
  2441. {
  2442. this.CopyAreaToClipboard(",");
  2443. }
  2444. private void miCrossCursor_Click(object sender, EventArgs e)
  2445. {
  2446. this.ShowCrossCursor = !this.ShowCrossCursor;
  2447. }
  2448. private void miCycle_Popup(object sender, EventArgs e)
  2449. {
  2450. foreach (MenuItem item in this.miCycle.MenuItems)
  2451. {
  2452. item.Checked = item.Text == this.currentDataCycle.ToString();
  2453. }
  2454. }
  2455. private void miCycle_SelectedIndexChanged(object sender, EventArgs e)
  2456. {
  2457. this.EndTime = DateTime.MinValue;
  2458. this.CurrentDataCycle = DataCycle.Parse((sender as MenuItem).Text);
  2459. }
  2460. private void miEdit_Click(object sender, EventArgs e)
  2461. {
  2462. this.EditFormula();
  2463. }
  2464. private void miFormulaEditor_Click(object sender, EventArgs e)
  2465. {
  2466. this.EditFormula(this.chart.SelectedArea);
  2467. }
  2468. private void miIndicator_SelectedIndexChanged(object sender, EventArgs e)
  2469. {
  2470. this.AreaCount = (sender as MenuItem).Index + 1;
  2471. }
  2472. private void miNormalAxis_Click(object sender, EventArgs e)
  2473. {
  2474. foreach (MenuItem item in this.miAxisType.MenuItems)
  2475. {
  2476. item.Checked = false;
  2477. }
  2478. MenuItem item2 = sender as MenuItem;
  2479. item2.Checked = true;
  2480. this.ScaleType = (Easychart.Finance.ScaleType)item2.MergeOrder;
  2481. }
  2482. private void miOverlay_Click(object sender, EventArgs e)
  2483. {
  2484. this.EditOverlay();
  2485. }
  2486. private void miStatistic_Click(object sender, EventArgs e)
  2487. {
  2488. this.ShowStatistic = !this.ShowStatistic;
  2489. }
  2490. private void miStatisticWindow_Click(object sender, EventArgs e)
  2491. {
  2492. this.ShowStatistic = !this.ShowStatistic;
  2493. }
  2494. private void miView_Popup(object sender, EventArgs e)
  2495. {
  2496. this.miStatistic.Checked = this.ShowStatistic;
  2497. }
  2498. private void mmFavorite_SelectedIndexChanged(object sender, EventArgs e)
  2499. {
  2500. FormulaArea selectedArea = this.chart.SelectedArea;
  2501. if ((selectedArea != null) && !selectedArea.IsMain())
  2502. {
  2503. this.SetAreaByName(selectedArea, (sender as MenuItem).Text);
  2504. }
  2505. }
  2506. private void mmSkin_SelectedIndexChanged(object sender, EventArgs e)
  2507. {
  2508. foreach (MenuItem item in this.miSkin.MenuItems)
  2509. {
  2510. item.Checked = false;
  2511. }
  2512. MenuItem item2 = (MenuItem)sender;
  2513. item2.Checked = true;
  2514. string text = item2.Text;
  2515. this.Skin = text;
  2516. }
  2517. private void MouseCrossCursor(Graphics g, FormulaHitInfo HitInfo)
  2518. {
  2519. if (!this.Designing)
  2520. {
  2521. if (HitInfo.HitType == FormulaHitType.htArea)
  2522. {
  2523. this.chart.CursorPos = HitInfo.CursorPos;
  2524. if (this.memoryCrossCursor)
  2525. {
  2526. this.InvalidateHitInfo(this.LastHitInfo);
  2527. this.InvalidateHitInfo(HitInfo);
  2528. }
  2529. else
  2530. {
  2531. this.chart.DrawCursor(g, HitInfo.X, HitInfo.Y, false);
  2532. }
  2533. this.ChangeCursorPos();
  2534. this.LastHitInfo = HitInfo;
  2535. }
  2536. else
  2537. {
  2538. this.HideCursor();
  2539. this.LastHitInfo.X = 0f;
  2540. }
  2541. }
  2542. }
  2543. public void MoveArea(FormulaArea fa, int NewIndex)
  2544. {
  2545. int index = this.chart.Areas.IndexOf(fa);
  2546. if (index >= 0)
  2547. {
  2548. if (NewIndex > index)
  2549. {
  2550. NewIndex--;
  2551. }
  2552. if (NewIndex >= 0)
  2553. {
  2554. this.chart.Areas.RemoveAt(index);
  2555. if (NewIndex > this.chart.Areas.Count)
  2556. {
  2557. NewIndex = this.chart.Areas.Count;
  2558. }
  2559. this.chart.Areas.Insert(NewIndex, fa);
  2560. this.areaPercent = this.chart.GetAreaPercent();
  2561. this.SaveChartProperties();
  2562. this.NeedRebind();
  2563. }
  2564. }
  2565. }
  2566. public void MoveAreaDown(FormulaArea fa)
  2567. {
  2568. int index = this.chart.Areas.IndexOf(fa);
  2569. this.MoveArea(fa, index + 2);
  2570. }
  2571. public void MoveAreaUp(FormulaArea fa)
  2572. {
  2573. int index = this.chart.Areas.IndexOf(fa);
  2574. this.MoveArea(fa, index - 1);
  2575. }
  2576. private void MoveChartX(FormulaArea fa, int TotalPart, int CurrentPart, float DeltaX)
  2577. {
  2578. if (DeltaX != 0f)
  2579. {
  2580. if (this.EndTime == DateTime.MinValue)
  2581. {
  2582. this.EndTime = this.chart.EndTime;
  2583. this.StartTime = this.chart.StartTime;
  2584. }
  2585. int num = this.chart.DateToIndex(this.chart.EndTime, -1);
  2586. int num2 = this.chart.DateToIndex(this.chart.StartTime);
  2587. double num3 = (num - num2) + 1;
  2588. int moveBars = (int)((num3 * DeltaX) / ((double)fa.Rect.Width));
  2589. this.MoveChartXBars(TotalPart, CurrentPart, this.DragInfo.StartTime, this.DragInfo.EndTime, moveBars);
  2590. }
  2591. }
  2592. public void MoveChartXBars(int MoveBars)
  2593. {
  2594. this.MoveChartXBars(3, 1, MoveBars);
  2595. }
  2596. private void MoveChartXBars(int TotalPart, int CurrentPart, int MoveBars)
  2597. {
  2598. this.MoveChartXBars(TotalPart, CurrentPart, this.chart.StartTime, this.chart.EndTime, MoveBars);
  2599. }
  2600. private void MoveChartXBars(int TotalPart, int CurrentPart, DateTime StartTime, DateTime EndTime, int MoveBars)
  2601. {
  2602. if ((this.chart != null) && (this.chart.DataProvider != null))
  2603. {
  2604. double[] numArray = this.chart.DataProvider["DATE"];
  2605. DateTime startTime = this.StartTime;
  2606. DateTime endTime = this.EndTime;
  2607. bool flag = false;
  2608. if (CurrentPart > 0)
  2609. {
  2610. int i = this.chart.DateToIndex(EndTime, -1) + MoveBars;
  2611. if (i < 0)
  2612. {
  2613. i = 0;
  2614. flag = true;
  2615. }
  2616. if (this.chart.CursorPos > i)
  2617. {
  2618. this.chart.CursorPos = i;
  2619. this.ChangeCursorPos();
  2620. }
  2621. this.EndTime = this.chart.IndexToDate(i);
  2622. }
  2623. if (CurrentPart < (TotalPart - 1))
  2624. {
  2625. int num2 = this.chart.DateToIndex(StartTime) + MoveBars;
  2626. if (num2 >= (numArray.Length - 1))
  2627. {
  2628. num2 = numArray.Length - 2;
  2629. flag = true;
  2630. }
  2631. if (num2 < 0)
  2632. {
  2633. num2 = 0;
  2634. }
  2635. if (this.chart.CursorPos < num2)
  2636. {
  2637. this.chart.CursorPos = num2;
  2638. this.ChangeCursorPos();
  2639. }
  2640. this.StartTime = this.chart.IndexToDate(num2);
  2641. }
  2642. if (flag && (CurrentPart == 1))
  2643. {
  2644. this.StartTime = startTime;
  2645. this.EndTime = endTime;
  2646. }
  2647. if (this.resetYAfterXChanged)
  2648. {
  2649. FormulaArea mainArea = this.chart.MainArea;
  2650. if (mainArea != null)
  2651. {
  2652. this.minPrice = 0.0;
  2653. mainArea.AxisY.AutoScale = true;
  2654. }
  2655. }
  2656. if ((this.CurrentDataManager != null) && this.CurrentDataManager.VirtualFetch)
  2657. {
  2658. this.NeedRebind();
  2659. }
  2660. }
  2661. }
  2662. private void MoveChartY(FormulaArea fa, int Part, int CurrentPart, float DeltaY)
  2663. {
  2664. if (DeltaY != 0f)
  2665. {
  2666. FormulaAxisY axisY = this.DragInfo.HitInfo.AxisY;
  2667. if (axisY == null)
  2668. {
  2669. axisY = fa.AxisY;
  2670. }
  2671. axisY.AutoScale = false;
  2672. double num = ((this.DragInfo.AreaMaxY - this.DragInfo.AreaMinY) / ((double)fa.Rect.Height)) * DeltaY;
  2673. if (CurrentPart > 0)
  2674. {
  2675. axisY.MinY = this.DragInfo.AreaMinY - num;
  2676. }
  2677. if (CurrentPart < (Part - 1))
  2678. {
  2679. axisY.MaxY = this.DragInfo.AreaMaxY - num;
  2680. }
  2681. this.minPrice = 0.0;
  2682. this.maxPrice = 0.0;
  2683. this.NeedRedraw(fa);
  2684. }
  2685. }
  2686. public void NeedRebind()
  2687. {
  2688. this.NeedRebind(true);
  2689. }
  2690. public void NeedRebind(bool AutoScaleY)
  2691. {
  2692. this.NeedRebind(AutoScaleY, false);
  2693. }
  2694. private void NeedRebind(bool AutoScaleY, bool DrawLastBarOnly)
  2695. {
  2696. this.needAutoScaleY = AutoScaleY;
  2697. this.needDrawLastBarOnly = DrawLastBarOnly;
  2698. this.needRedraw = true;
  2699. this.needRebind = true;
  2700. base.Invalidate();
  2701. }
  2702. public void NeedRedraw()
  2703. {
  2704. this.NeedRedraw(null);
  2705. }
  2706. public void NeedRedraw(FormulaArea fa)
  2707. {
  2708. this.needRedraw = true;
  2709. if (fa != null)
  2710. {
  2711. Rectangle rect = fa.Rect;
  2712. rect.Inflate(1, 1);
  2713. base.Invalidate(rect);
  2714. }
  2715. else
  2716. {
  2717. base.Invalidate();
  2718. }
  2719. }
  2720. public void NeedRefresh()
  2721. {
  2722. this.needRedraw = true;
  2723. this.needRebind = true;
  2724. this.needRefresh = true;
  2725. base.Invalidate();
  2726. }
  2727. private void NextArea(int Delta)
  2728. {
  2729. int num = ((this.chart.Areas.IndexOf(this.chart.SelectedArea) + Delta) + this.chart.Areas.Count) % this.chart.Areas.Count;
  2730. if (num < this.chart.Areas.Count)
  2731. {
  2732. this.chart.SelectedArea = this.chart[num];
  2733. }
  2734. this.NeedRedraw();
  2735. }
  2736. private void NextCycle(int Delta)
  2737. {
  2738. if ((this.favoriteCycles != null) && (this.favoriteCycles != ""))
  2739. {
  2740. ArrayList list = new ArrayList();
  2741. list.AddRange(this.favoriteCycles.Split(new char[] { ';' }));
  2742. int index = list.IndexOf(this.CurrentDataCycle.ToString());
  2743. if (index < 0)
  2744. {
  2745. index = 0;
  2746. }
  2747. index = ((index + Delta) + list.Count) % list.Count;
  2748. if (!this.fixedTime)
  2749. {
  2750. this.EndTime = DateTime.MinValue;
  2751. }
  2752. this.CurrentDataCycle = DataCycle.Parse(list[index].ToString());
  2753. }
  2754. }
  2755. private void NextFormula(int Delta)
  2756. {
  2757. int index = this.chart.Areas.IndexOf(this.chart.SelectedArea);
  2758. if (index < 0)
  2759. {
  2760. index = this.chart.Areas.Count - 1;
  2761. }
  2762. if (index >= 0)
  2763. {
  2764. FormulaArea area = this.chart[index];
  2765. if (!area.IsMain())
  2766. {
  2767. string str = area.FormulaToString('#');
  2768. int length = str.IndexOf('(');
  2769. if (length >= 0)
  2770. {
  2771. str = str.Substring(0, length);
  2772. }
  2773. int num3 = -1;
  2774. for (int i = 0; i < this.favoriteFormulas.Count; i++)
  2775. {
  2776. if (string.Compare(str, (string)this.favoriteFormulas[i], true) == 0)
  2777. {
  2778. num3 = i;
  2779. }
  2780. }
  2781. if (num3 < 0)
  2782. {
  2783. num3 = 0;
  2784. }
  2785. num3 = ((num3 + Delta) + this.favoriteFormulas.Count) % this.favoriteFormulas.Count;
  2786. this.SetAreaByName(index, (string)this.favoriteFormulas[num3]);
  2787. this.NeedRebind();
  2788. }
  2789. }
  2790. }
  2791. protected override void OnPaintBackground(PaintEventArgs pevent)
  2792. {
  2793. if ((this.chart == null) || (this.chart.DataProvider == null))
  2794. {
  2795. base.OnPaintBackground(pevent);
  2796. }
  2797. }
  2798. public static void OpenFormulaSourceEditor()
  2799. {
  2800. OpenFormulaSourceEditor("", "");
  2801. }
  2802. public static void OpenFormulaSourceEditor(string Filename, string Formula)
  2803. {
  2804. FormulaSourceEditor.Open(Filename, Formula);
  2805. }
  2806. public void Print()
  2807. {
  2808. this.SetupPrinting();
  2809. if (this.printDialog.ShowDialog() == DialogResult.OK)
  2810. {
  2811. this.printDocument.Print();
  2812. }
  2813. }
  2814. private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
  2815. {
  2816. Bitmap image = this.GetBitmap(true, true);
  2817. e.Graphics.DrawImage(image, e.MarginBounds, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
  2818. }
  2819. public void PrintPreview()
  2820. {
  2821. this.SetupPrinting();
  2822. this.previewDialog.ShowDialog();
  2823. }
  2824. public void PrintSetup()
  2825. {
  2826. this.SetupPrinting();
  2827. this.setupDialog.ShowDialog();
  2828. }
  2829. private void RebindLastBar()
  2830. {
  2831. this.needDrawLastBarOnly = true;
  2832. this.BindData();
  2833. this.RenderChart(this.ControlGraphics);
  2834. }
  2835. private void RecreateFormula()
  2836. {
  2837. if (this.chart != null)
  2838. {
  2839. foreach (FormulaArea area in this.chart.Areas)
  2840. {
  2841. this.RecreateFormula(area);
  2842. }
  2843. }
  2844. this.SaveChartProperties();
  2845. }
  2846. private void RecreateFormula(FormulaArea fa)
  2847. {
  2848. string[] ss = fa.FormulaToStrings();
  2849. fa.Formulas.Clear();
  2850. fa.StringsToFormula(ss);
  2851. }
  2852. public void RenderChart(Graphics g)
  2853. {
  2854. Graphics graphics = g;
  2855. if (this.memoryCrossCursor)
  2856. {
  2857. Rectangle rect = this.chart.Rect;
  2858. if (((this.CrossMemBmp == null) || (this.CrossMemBmp.Width != rect.Width)) || (this.CrossMemBmp.Height != rect.Height))
  2859. {
  2860. this.CrossMemBmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppPArgb);
  2861. this.CrossMemBmpG = Graphics.FromImage(this.CrossMemBmp);
  2862. }
  2863. Region r = null;
  2864. if (this.needDrawLastBarOnly && this.needRebind)
  2865. {
  2866. r = new Region();
  2867. r.MakeEmpty();
  2868. }
  2869. g = this.CrossMemBmpG;
  2870. g.SetClip(graphics);
  2871. this.chart.Render(g, r);
  2872. graphics.SetClip(g);
  2873. if (this.LastHitInfo.X != 0f)
  2874. {
  2875. if (this.needRebind)
  2876. {
  2877. this.SetCursorPos();
  2878. }
  2879. if (this.needDrawCursor)
  2880. {
  2881. this.DrawCursorByPos(g);
  2882. this.needDrawCursor = false;
  2883. }
  2884. else
  2885. {
  2886. this.DrawCursor(g);
  2887. }
  2888. }
  2889. }
  2890. else
  2891. {
  2892. this.chart.Render(g);
  2893. if (this.needDrawCursor)
  2894. {
  2895. this.chart.DrawCursor(g);
  2896. this.needDrawCursor = false;
  2897. }
  2898. else if ((this.crossCursorMouseMode == MouseAction.MouseDown) && (this.LastHitInfo.X != 0f))
  2899. {
  2900. this.LastHitInfo = this.chart.GetHitInfo(this.LastHitInfo.X, this.LastHitInfo.Y);
  2901. this.MouseCrossCursor(this.ControlGraphics, this.LastHitInfo);
  2902. }
  2903. }
  2904. if (this.MouseZoomBmp != null)
  2905. {
  2906. g.DrawImage(this.MouseZoomBmp, this.MouseZoomRect, this.MouseZoomRect, GraphicsUnit.Pixel);
  2907. }
  2908. if (this.memoryCrossCursor)
  2909. {
  2910. graphics.DrawImage(this.CrossMemBmp, 0, 0);
  2911. }
  2912. }
  2913. public void Reset(int columnWidth)
  2914. {
  2915. this.EndTime = DateTime.MinValue;
  2916. this.StockBars = base.Width / columnWidth;
  2917. this.AutoScaleAxisY();
  2918. }
  2919. public void SaveChartProperties()
  2920. {
  2921. this.AreasToDefaultFormulas();
  2922. this.areaPercent = this.chart.GetAreaPercent();
  2923. }
  2924. public void ScaleChart(double ScaleFactor)
  2925. {
  2926. if ((this.chart != null) && !this.chart.FixedTime)
  2927. {
  2928. int moveBars = (int)((this.chart.GetTotalBars() * ScaleFactor) + 0.5);
  2929. if (moveBars == 0)
  2930. {
  2931. if (ScaleFactor > 0.0)
  2932. {
  2933. moveBars = 1;
  2934. }
  2935. else
  2936. {
  2937. moveBars = -1;
  2938. }
  2939. }
  2940. int num3 = -moveBars;
  2941. if (this.zoomPosition == ZoomCenterPosition.Left)
  2942. {
  2943. moveBars = 0;
  2944. }
  2945. if (this.zoomPosition == ZoomCenterPosition.Right)
  2946. {
  2947. num3 = 0;
  2948. }
  2949. this.MoveChartXBars(3, 0, moveBars);
  2950. this.MoveChartXBars(3, 2, num3);
  2951. }
  2952. }
  2953. public void SetAreaByName(string FormulaName)
  2954. {
  2955. FormulaArea selectedArea = this.chart.SelectedArea;
  2956. if (selectedArea == null)
  2957. {
  2958. selectedArea = this.chart.Areas[this.chart.Areas.Count - 1];
  2959. }
  2960. this.SetAreaByName(selectedArea, FormulaName);
  2961. }
  2962. public void SetAreaByName(FormulaArea fa, string FormulaName)
  2963. {
  2964. if (fa != null)
  2965. {
  2966. int index = this.chart.Areas.IndexOf(fa);
  2967. if (index >= 0)
  2968. {
  2969. string s = fa.FormulaToString('#');
  2970. try
  2971. {
  2972. this.SetDefaultFormulas(index, FormulaName);
  2973. }
  2974. catch
  2975. {
  2976. this.SetDefaultFormulas(index, s);
  2977. throw;
  2978. }
  2979. this.SaveChartProperties();
  2980. this.NeedRebind();
  2981. //todo:重新赋值行情格式化字符串-Daniel
  2982. //this.chart.MainArea.AxisY.Format = "f" + _quoteDigits;
  2983. //this.NeedRedraw(this.chart.MainArea);
  2984. }
  2985. }
  2986. }
  2987. public void SetAreaByName(int AreaIndex, string FormulaName)
  2988. {
  2989. if ((AreaIndex >= 0) && (AreaIndex < this.chart.Areas.Count))
  2990. {
  2991. this.SetAreaByName(this.chart.Areas[AreaIndex], FormulaName);
  2992. }
  2993. }
  2994. private void SetAreaCount(int Count)
  2995. {
  2996. if (this.chart.Areas.Count != Count)
  2997. {
  2998. while (this.chart.Areas.Count > Count)
  2999. {
  3000. this.chart.Areas.RemoveAt(Count);
  3001. }
  3002. int num = this.chart.Areas.Count;
  3003. this.ExpandDefaultFormulas(Count);
  3004. double num2 = 1.0;
  3005. if (this.chart.Areas.Count > 0)
  3006. {
  3007. num2 = this.chart[0].HeightPercent / 3.0;
  3008. }
  3009. for (int i = num; i < this.chart.Areas.Count; i++)
  3010. {
  3011. this.chart[i].HeightPercent = num2;
  3012. }
  3013. this.areaPercent = this.chart.GetAreaPercent();
  3014. this.NeedRebind();
  3015. }
  3016. this.UseDefaultFormulas(false);
  3017. }
  3018. private void SetCursorPos()
  3019. {
  3020. this.chart.CursorPos = this.LastHitInfo.CursorPos;
  3021. }
  3022. private void SetDefaultFormulas(int Index, string s)
  3023. {
  3024. this.ExpandDefaultFormulas(Index);
  3025. this.chart[Index].Formulas.Clear();
  3026. this.chart[Index].StringToFormula(s, '#');
  3027. }
  3028. private void SetupPrinting()
  3029. {
  3030. if (this.printDialog == null)
  3031. {
  3032. this.printDialog = new PrintDialog();
  3033. this.printDocument = new PrintDocument();
  3034. this.previewDialog = new PrintPreviewDialog();
  3035. this.setupDialog = new PageSetupDialog();
  3036. this.printDocument.DefaultPageSettings.Landscape = true;
  3037. this.printDocument.DefaultPageSettings.Margins = new Margins(30, 30, 30, 30);
  3038. this.printDialog.Document = this.printDocument;
  3039. this.printDocument.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage);
  3040. this.previewDialog.Document = this.printDocument;
  3041. this.setupDialog.Document = this.printDocument;
  3042. }
  3043. }
  3044. public void ShowAllBars()
  3045. {
  3046. if ((this.chart != null) && (this.chart.DataProvider != null))
  3047. {
  3048. double[] numArray = this.chart.DataProvider["DATE"];
  3049. if (numArray.Length > 0)
  3050. {
  3051. this.StartTime = DateTime.FromOADate(numArray[0]);
  3052. this.EndTime = DateTime.FromOADate(numArray[numArray.Length - 1]);
  3053. }
  3054. }
  3055. }
  3056. private void ShowStatisticWindow(object Sender, FormulaChart Chart, int Pos, IDataProvider idp)
  3057. {
  3058. if (this.ShowStatistic)
  3059. {
  3060. if (this.StatisticWindow.Left < 0)
  3061. {
  3062. this.StatisticWindow.Left = 10;
  3063. }
  3064. //使用给定的行情小数位数
  3065. string format = "f" + _quoteDigits;
  3066. //string format = "f2";
  3067. //if ((Chart.MainArea != null) && Chart.MainArea.IsMain())
  3068. //{
  3069. // format = Chart.MainArea.AxisY.Format;
  3070. //}
  3071. double d = idp["DATE"][Chart.CursorPos];
  3072. double num2 = idp["OPEN"][Chart.CursorPos];
  3073. double num3 = idp["HIGH"][Chart.CursorPos];
  3074. double num4 = idp["LOW"][Chart.CursorPos];
  3075. double num5 = idp["CLOSE"][Chart.CursorPos];
  3076. double num6 = idp["VOLUME"][Chart.CursorPos];
  3077. string str2 = "";
  3078. string str3 = "";
  3079. string str4 = "";
  3080. if (Chart.CursorPos > 0)
  3081. {
  3082. double num7 = idp["CLOSE"][Chart.CursorPos - 1];
  3083. if (num7 != double.NaN)
  3084. {
  3085. str2 = FormulaHelper.FormatDouble(num7, format);
  3086. str3 = FormulaHelper.FormatDouble(num5 - num7, format); //(num5 - num7).ToString("f2");
  3087. str4 = ((num5 - num7) / num7).ToString("p2");
  3088. }
  3089. }
  3090. var builder = new StringBuilder();
  3091. //todo:以后可做成多语言资源-Daniel
  3092. builder.Append("商品代码=" + idp.GetStringData("Code") + ";");
  3093. builder.Append("日 期=" + DateTime.FromOADate(d).ToString(Chart.XCursorFormat, DateTimeFormatInfo.CurrentInfo) + ";");
  3094. builder.Append("开盘价=" + FormulaHelper.FormatDouble(num2, format) + ";");
  3095. builder.Append("最高价=" + FormulaHelper.FormatDouble(num3, format) + ";");
  3096. builder.Append("最低价=" + FormulaHelper.FormatDouble(num4, format) + ";");
  3097. builder.Append("收盘价=" + FormulaHelper.FormatDouble(num5, format) + ";");
  3098. builder.Append("涨 幅=" + str3 + ";");
  3099. builder.Append("涨 跌=" + str4 + ";");
  3100. builder.Append("成交量=" + num6.ToString() + ";");
  3101. //builder.Append("Symbol=" + idp.GetStringData("Code") + ";");
  3102. //builder.Append("Date=" + DateTime.FromOADate(d).ToString(Chart.XCursorFormat, DateTimeFormatInfo.InvariantInfo) + ";");
  3103. //builder.Append("Current=" + FormulaHelper.FormatDouble(num5, format) + ";");
  3104. //builder.Append("Last=" + str2 + ";");
  3105. //builder.Append("Open=" + FormulaHelper.FormatDouble(num2, format) + ";");
  3106. //builder.Append("High=" + FormulaHelper.FormatDouble(num3, format) + ";");
  3107. //builder.Append("Low=" + FormulaHelper.FormatDouble(num4, format) + ";");
  3108. //builder.Append("Close=" + FormulaHelper.FormatDouble(num5, format) + ";");
  3109. //builder.Append("Volume=" + num6.ToString() + ";");
  3110. //builder.Append("Change=" + str3 + ";");
  3111. //builder.Append("Percent=" + str4 + ";");
  3112. if (this.ShowIndicatorValues)
  3113. {
  3114. try
  3115. {
  3116. for (int i = this.showOverlayValues ? 0 : 1; i < Chart.Areas.Count; i++)
  3117. {
  3118. int num9 = 0;
  3119. int num10 = 0;
  3120. foreach (FormulaData data in Chart[i].FormulaDataArray)
  3121. {
  3122. string displayName;
  3123. if (num10 == 0)
  3124. {
  3125. displayName = Chart[i].Formulas[num9].DisplayName;
  3126. }
  3127. else
  3128. {
  3129. displayName = string.Empty;
  3130. }
  3131. if (data.ValueTextMode != Easychart.Finance.ValueTextMode.None)
  3132. {
  3133. string str6 = (displayName + data.Name).Trim();
  3134. if (str6 != "")
  3135. {
  3136. builder.Append(str6 + "=" + FormulaHelper.FormatDouble(data[Chart.CursorPos], Chart[i].AxisYs[data.AxisYIndex].Format) + ";");
  3137. }
  3138. }
  3139. num10++;
  3140. if (num10 == Chart[i].Packages[num9].Count)
  3141. {
  3142. num9++;
  3143. num10 = 0;
  3144. }
  3145. }
  3146. }
  3147. }
  3148. catch
  3149. {
  3150. }
  3151. }
  3152. this.StatisticWindow.RefreshData(builder.ToString());
  3153. this.LastProvider = Chart.DataProvider;
  3154. this.LastCursorPos = Chart.CursorPos;
  3155. //固定统计窗口位置-Daniel
  3156. this.StatisticWindow.Top = 20;
  3157. this.StatisticWindow.Left = 60;
  3158. }
  3159. }
  3160. private string[] Split(string s, char separator)
  3161. {
  3162. ArrayList list = new ArrayList();
  3163. int num = 0;
  3164. int startIndex = 0;
  3165. for (int i = 0; i < s.Length; i++)
  3166. {
  3167. if (s[i] == '(')
  3168. {
  3169. num++;
  3170. }
  3171. else if (s[i] == ')')
  3172. {
  3173. num--;
  3174. }
  3175. if ((num == 0) && (s[i] == separator))
  3176. {
  3177. list.Add(s.Substring(startIndex, i - startIndex));
  3178. startIndex = i + 1;
  3179. }
  3180. }
  3181. return (string[])list.ToArray(typeof(string));
  3182. }
  3183. private void StatisticWindow_OnHide(object sender, EventArgs e)
  3184. {
  3185. this.ShowStatistic = this.StatisticWindow.Visible;
  3186. }
  3187. public void UseDefaultFormulas(bool b)
  3188. {
  3189. this.needSetDefaultFormulas = b;
  3190. }
  3191. #endregion Methods of ChartWinControl (126)
  3192. #region Public Methods
  3193. /// <summary>
  3194. /// 插入默认指标
  3195. /// </summary>
  3196. /// <param name="name">The name.</param>
  3197. /// <param name="precent">The precent.</param>
  3198. public void InsertDefaultFormula(string name, double precent = 1.0)
  3199. {
  3200. this.chart.AddArea(name, precent);
  3201. ApplySkin();
  3202. this.NeedRefresh();
  3203. }
  3204. /// <summary>
  3205. /// 添加指标到主图
  3206. /// </summary>
  3207. /// <param name="newFormula"></param>
  3208. public void InsertFormulaToMain(string newFormula)
  3209. {
  3210. InsertFormulaToArea(this.chart.MainArea, newFormula);
  3211. }
  3212. /// <summary>
  3213. /// 添加指标到图表区
  3214. /// </summary>
  3215. /// <param name="area">指定区域</param>
  3216. /// <param name="newFormula">新添加的指标全名(带参数)</param>
  3217. public void InsertFormulaToArea(FormulaArea area, string newFormula)
  3218. {
  3219. if (area == null || string.IsNullOrEmpty(newFormula))
  3220. {
  3221. return;
  3222. }
  3223. var formulaStrings = string.Empty;
  3224. if (area.Formulas == null || area.Formulas.Count == 0)
  3225. {
  3226. formulaStrings = newFormula;
  3227. }
  3228. else
  3229. {
  3230. foreach (var formula in area.Formulas)
  3231. {
  3232. var formulaBase = formula as FormulaBase;
  3233. if (formulaBase == null || string.IsNullOrEmpty(formulaBase.FormulaName) || formulaBase.FormulaName.ToLower() == newFormula.ToLower())
  3234. {
  3235. return;
  3236. }
  3237. formulaStrings += formulaBase.FormulaName + "#";
  3238. }
  3239. formulaStrings += newFormula;
  3240. }
  3241. this.SetAreaByName(area, formulaStrings);
  3242. }
  3243. /// <summary>
  3244. /// 删除图表菜单
  3245. /// </summary>
  3246. public void DeleteChartMenu()
  3247. {
  3248. this.cmRight = null;
  3249. ShowStatistic = false;
  3250. }
  3251. #endregion
  3252. #region Extended Methods
  3253. /// <summary>
  3254. /// 行情小数位数
  3255. /// </summary>
  3256. protected int _quoteDigits;
  3257. /// <summary>
  3258. /// 设置行情小数位数用来格式化价格
  3259. /// 在控件完成加载后调用,否则取的MainArea不一样
  3260. /// </summary>
  3261. /// <param name="quoteDigits">The quote digits.</param>
  3262. public void SetQuoteDigits(int quoteDigits)
  3263. {
  3264. //在控件完成加载后调用,否则取的MainArea不一样-Daniel
  3265. try
  3266. {
  3267. _quoteDigits = quoteDigits;
  3268. this.chart.MainArea.AxisY.Format = "f" + _quoteDigits;
  3269. this.NeedRedraw(this.chart.MainArea);
  3270. }
  3271. catch (Exception e)
  3272. {
  3273. }
  3274. }
  3275. #endregion
  3276. }
  3277. }