public void Action(ChartParameter parameter) { ZChart cChart = parameter.Chart; InputDeviceStatus cStatus = parameter.Status; MouseEventArgs e = cStatus.GetCurrentMouseArgs(); if (cStatus.Event == EInputDeviceEvent.MouseUp) { if (__cStart == Point.Empty) { List <Layer> cLayers = cChart.Layers; int iCount = cLayers.Count; for (int i = 0; i < iCount; i++) { Layer cLayer = cLayers[i]; if (cLayer.IsLayerScope(e.X, e.Y)) { __cLayer = cLayer; break; } } __cStart = e.Location; } else { Point cEnd = e.Location; Boundary.BoundFix(ref __cStart, ref cEnd, new Rectangle4(__cLayer.LayerRectangleWithoutAxisY)); //保存至使用者繪製容器內 parameter.Behavior.DrawContainer.AddDrawObject(__sName, __cLayer, new Point[] { __cStart, cEnd }, new PowerLanguage.PenStyle[] { parameter.CustomPen }); __cStart = Point.Empty; parameter.CustomPainter = null; //繪圖完畢需要設定為 null __cGDI.ClearRops(__cLineInfos, null, false); cChart.Refresh(); } } else if (__cStart != Point.Empty && cStatus.Event == EInputDeviceEvent.MouseMove) { __cGDI.SaveDC(); __cGDI.ClipRectangle(__cLayer.LayerRectangleWithoutAxisY); __cGDI.ClearRops(__cLineInfos, null, !parameter.Updated); ChartProperty cProperty = cChart.ChartProperty; IntPtr cPen = Gdi.CreatePen(new PowerLanguage.PenStyle(cProperty.DrawAideLineColor, 1)); __cLineInfos.Add(__cGDI.DrawRopLine(cPen, __cStart.X, __cStart.Y, e.X, e.Y)); __cGDI.RestoreDC(); } }
public void Action(ChartParameter parameter) { __cGDI.ClearRops(true); __cGDI.ClearRops(__cLineInfos, __cTextInfos, !parameter.Updated); InputDeviceStatus cStatus = parameter.Status; if (cStatus.Event == EInputDeviceEvent.MouseMove) { ZChart cChart = parameter.Chart; AxisX cAxisX = cChart.AxisX; ChartProperty cProperty = cChart.ChartProperty; MouseEventArgs e = cStatus.GetCurrentMouseArgs(); int iOldBKColor = __cGDI.SelectBackground(cProperty.BackgroundColor); IntPtr cOldFont = __cGDI.SelectFont(cProperty.AxisFont); IntPtr cPen = Gdi.CreatePen(new PowerLanguage.PenStyle(cProperty.ForeColor, 1)); int iBarNumber = cAxisX.ConvertBarNumberFromX(e.X); if (iBarNumber > cAxisX.DataCount) { return; } else { Rectangle cAxisXRect = cAxisX.AxisRectangle; AxisXUnit cUnit = cAxisX.ConvertBarNumberToWidth(iBarNumber); cAxisXRect.X = cUnit.CenterPoint; cAxisXRect.Width = cAxisX.FontMetrics.Width * 12; DateTime cDateTime = cAxisX.ConvertBarNumberToTime(iBarNumber); __cLineInfos.Add(__cGDI.DrawRopLine(cPen, cUnit.CenterPoint, 0, cUnit.CenterPoint, cAxisXRect.Y)); __cTextInfos.Add(__cGDI.DrawRopString(cDateTime.ToString("MM/dd HH:mm"), cProperty.BackgroundColor, cProperty.ForeColor, 2, 5, cAxisXRect)); } List <Layer> cLayers = cChart.Layers; int iCount = cLayers.Count; for (int i = 0; i < iCount; i++) { Layer cLayer = cLayers[i]; if (__cLineInfos.Count == 1 && cLayer.IsLayerScope(e.X, e.Y)) { AxisY cAxisY = cLayer.AxisY; Rectangle cAxisYRect = cAxisY.AxisRectangle; cAxisYRect.Y = e.Y; cAxisYRect.Height = cAxisY.FontMetrics.Height; __cLineInfos.Add(__cGDI.DrawRopLine(cPen, 0, e.Y, cAxisYRect.X, e.Y)); __cTextInfos.Add(__cGDI.DrawRopString(Math.Round(cAxisY.ConvertValueFromY(e.Y), cAxisY.Decimals).ToString(), cProperty.BackgroundColor, cProperty.ForeColor, 5, 0, cAxisYRect)); } cLayer.LegendIndex = iBarNumber; __cEngine.DrawLegend(cLayer, cProperty); } __cGDI.RemoveObject(__cGDI.SelectFont(cOldFont)); __cGDI.SelectBackground(iOldBKColor); } //如果使用者使用十字線功能, 如果有在選擇繪圖功能會在 CustomPainter 屬性儲存繪圖功能的類別名稱 //如果有繪圖類別名稱就取出使用 string sName = parameter.CustomPainter; if (__cCustomPainter == null && sName != null) { __cCustomPainter = parameter.Behavior.GetCustomAction(sName); if (__cCustomPainter == null || !(__cCustomPainter is IDrawable)) { parameter.CustomPainter = null; } } if (__cCustomPainter != null) { __cCustomPainter.Action(parameter); //如果繪圖類別名稱 == null 表示繪圖已經完畢 if (parameter.CustomPainter == null) { __cCustomPainter = null; } } }
protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam) { switch (message) { case MessageType.Create: window.SetWindowLong(0, IntPtr.Zero); // on/off flag return(0); case MessageType.KeyDown: // Send most key presses to the parent window if ((VirtualKey)wParam != VirtualKey.Return && (VirtualKey)wParam != VirtualKey.Space) { window.GetParent().SendMessage(message, wParam, lParam); return(0); } // For Return and Space, fall through to toggle the square goto case MessageType.LeftButtonDown; case MessageType.LeftButtonDown: window.SetWindowLong(0, (IntPtr)(1 ^ (int)window.GetWindowLong(0))); window.SetFocus(); window.Invalidate(false); return(0); // For focus messages, invalidate the window for repaint case MessageType.SetFocus: Checker4.idFocus = (int)window.GetWindowLong(WindowLong.Id); // Fall through goto case MessageType.KillFocus; case MessageType.KillFocus: window.Invalidate(); return(0); case MessageType.Paint: using (DeviceContext dc = window.BeginPaint()) { Rectangle rect = window.GetClientRectangle(); dc.Rectangle(rect); if (window.GetWindowLong(0) != IntPtr.Zero) { dc.MoveTo(new Point(0, 0)); dc.LineTo(new Point(rect.Right, rect.Bottom)); dc.MoveTo(new Point(0, rect.Bottom)); dc.LineTo(new Point(rect.Right, 0)); } // Draw the "focus" rectangle if (window == Windows.GetFocus()) { rect.Inflate(rect.Width / -10, rect.Height / -10); dc.SelectObject(StockBrush.Null); using PenHandle pen = Gdi.CreatePen(PenStyle.Dash, 0, default); dc.SelectObject(pen); dc.Rectangle(rect); dc.SelectObject(StockPen.Black); } } return(0); } return(base.WindowProcedure(window, message, wParam, lParam)); }