ChartWinControl.cs 128 KB

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