/// <summary> /// Draw date label at X /// </summary> /// <param name="g"></param> /// <param name="fc"></param> /// <param name="Area"></param> /// <param name="X"></param> public void DrawCursor(Graphics g, FormulaChart fc, FormulaArea Area, float X) { if (!LastCursorRect.IsEmpty) { fc.RestoreMemBmp(g, LastCursorRect); } FormulaLabel fl = Area.Labels[2]; int i = fc.CursorPos; if ((object)fdDate != null) { if (i >= 0) { DateTime D = fc.IndexToDate(i); string s = D.ToString(CursorFormat); //,DateTimeFormatInfo.InvariantInfo SizeF sf = g.MeasureString(s, LabelFont); RectangleF R = new RectangleF(X - fc.Rect.X, Rect.Y, sf.Width, Rect.Height - 1); if (R.Right > Rect.Right) { R.Offset(-R.Width - 1, 0); } LastCursorRect = R; LastCursorRect.Inflate(2, 1); R.Offset(fc.Rect.Location); fl.DrawString(g, s, LabelFont, fl.TextBrush, VerticalAlign.Bottom, FormulaAlign.Left, R, false); } } }
private string ReplaceText(FormulaChart fc, string s, out int ColorIndex) { ColorIndex = 0; while (true) { int i1 = s.IndexOf('{'); int i2 = s.IndexOf('}'); if (i2 > i1) { string s1 = s.Substring(i1 + 1, i2 - i1 - 1); int i = s1.IndexOf(':'); string s3 = ""; string s2 = s1; if (i > 0) { s2 = s1.Substring(0, i); s3 = s1.Substring(i + 1); } if (s2 == "Company") { s2 = CompanyName; } else if (s2 == "URL") { s2 = URL; } else if (s2 == "Time") { s2 = ((DateTime.Now.Ticks - StartTick) / 10000).ToString() + "ms"; } else { IDataProvider idp = fc.DataProvider; FormulaArea Area = fc.MainArea; //if (DATE==null) //{ DATE = idp["DATE"]; CLOSE = idp["CLOSE"]; if (CLOSE == null || CLOSE.Length == 0) { return(s); } if (Bar < 0) { for (int j = CLOSE.Length - 1; j >= 0; j--) { if (!double.IsNaN(CLOSE[j])) { Bar = j; break; } } } if (Bar < 0) { Bar = 0; } //} if (string.Compare(s2, "D") == 0) { if (s3 == "") { s3 = "dd-MMM-yyyy dddd"; } string LastTradeTime = idp.GetStringData("LastTradeTime"); DateTime dtLastTrade = fc.IndexToDate(Bar); if (LastTradeTime != null && LastTradeTime != "") { dtLastTrade = FormulaHelper.ToDateDef(LastTradeTime, dtLastTrade); } s2 = dtLastTrade.ToString(s3); //,DateTimeFormatInfo.InvariantInfo } else { string s4 = idp.GetStringData(s2); if (s4 != null) { s2 = s4; } else { try { double Last = 0; //if (s3=="") s3 = "f2"; s3 = Area.AxisY.Format; if (string.Compare(s2, "Change", true) == 0) { Last = GetLast(); if (Bar < CLOSE.Length) { double n = CLOSE[Bar]; ColorIndex = GetColorIndex(Last, n); string Percent = ((n - Last) / Last).ToString("p2"); //,NumberFormatInfo.InvariantInfo if (!Percent.StartsWith("-")) { Percent = "+" + Percent; } if (s3 == "") { s3 = "f" + FormulaHelper.TestBestFormat(n, 2); } s2 = (n - Last).ToString(s3) + "(" + Percent + ")"; //,NumberFormatInfo.InvariantInfo } } else { double d = 0; if (s2 == "LC") { d = GetLast(); } else { FormulaData fd = idp[s2]; double[] dd = null; if (!object.Equals(fd, null)) { dd = fd.Data; } if (dd != null && Bar < dd.Length) { Last = GetLast(); d = dd[Bar]; if (s2 == "VOLUME") { s3 = "f0"; ColorIndex = GetColorIndex(Last, CLOSE[Bar]); } else { ColorIndex = GetColorIndex(Last, d); } } else { d = double.NaN; } } if (s3 == "") { s3 = "f" + FormulaHelper.TestBestFormat(d, 2); } s2 = FormulaHelper.FormatDouble(d, s3); } } catch { s2 = ""; } } } } s = s.Substring(0, i1) + s2 + s.Substring(i2 + 1); } else { break; } } return(s); }