protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (ClientManager.Training) { DrawNoData(g, "DISABLED"); DrawBorders(g); return; } // Draw grid float gridCount = (int)((Width - graphMarginX) / gridWidth); float gridSizeX = (Width - graphMarginX) / gridCount; gridCount = (int)(Height / gridHeight); float gridSizeY = Height / gridCount; using (Pen pen = new Pen(Style.Colors.Primary.Dark2)) { for (float posX = graphMarginX; posX < Width; posX += gridSizeX) { g.DrawLine(pen, (int)posX, gridOffset, (int)posX, Height); } for (float posY = gridOffset; posY < Height; posY += gridSizeY) { g.DrawLine(pen, graphMarginX, (int)posY, Width, (int)posY); } } // Find the maximum value double maxValue = 0; if (uploadValues != null) { for (int i = 0; i < uploadValues.Count; i++) { if (uploadValues[i] > maxValue) { maxValue = uploadValues[i]; } } } if (downloadValues != null) { for (int i = 0; i < downloadValues.Count; i++) { if (downloadValues[i] > maxValue) { maxValue = downloadValues[i]; } } } maxValue *= 1.3; string unitPrefix = ""; int divider = 1; int unitDecimals = 0; if (maxValue > 1000000) { unitPrefix = "M"; divider = 1000000; unitDecimals = 2; } else if (maxValue > 1000) { unitPrefix = "K"; divider = 1000; } // Draw Y labels float labelDist = (Height - (2 * graphMarginY)) / 5.8f; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { for (int i = 0; i < 6; i++) { float val = (float)(((5 - i) / 5f) * maxValue); float posY = graphMarginY + (i * labelDist); string text = (val / divider).ToString("F" + unitDecimals); float width = g.MeasureString(text, Style.Fonts.Small).Width; g.DrawString(text, Style.Fonts.Small, brush, new PointF(graphMarginX - width - 5, posY)); } } // Draw min/max lines using (Pen pen = new Pen(Style.Colors.Secondary.Dark2, 3)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.DashPattern = new float[] { 2, 2 }; g.DrawLine(pen, graphMarginX + 5, 8, Width - 5, 8); g.DrawLine(pen, graphMarginX + 5, Height - 8, Width - 5, Height - 8); } // Draw borders DrawBorders(g); // Draw graph values Helper.DrawGraphLine(g, new RectangleF(graphMarginX, graphMarginY, Width - graphMarginX - 2, Height - (2 * graphMarginY)), uploadValues.ToArray(), maxValue, 0, Style.Colors.Terciary.Dark1, Style.Colors.Terciary.Light2, 1.5f); Helper.DrawGraphLine(g, new RectangleF(graphMarginX, graphMarginY, Width - graphMarginX - 2, Height - (2 * graphMarginY)), downloadValues.ToArray(), maxValue, 0, Style.Colors.Secondary.Main, Style.Colors.Secondary.Light2, 1.5f); // Draw title using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { float width = g.MeasureString("Network", Style.Fonts.Title).Width; Helper.DrawTextShadow(g, "Network", new PointF(graphMarginX + 2, 20), Style.Fonts.Title, Color.Black); g.DrawString("Network", Style.Fonts.Title, brush, new PointF(graphMarginX + 2, 20)); string text = "(" + unitPrefix + "B/s)"; Helper.DrawTextShadow(g, text, new PointF(graphMarginX + width + 4, 24), Style.Fonts.Small, Color.Black); g.DrawString(text, Style.Fonts.Small, brush, new PointF(graphMarginX + width + 4, 24)); } // Draw legend using (Brush brush = new SolidBrush(Style.Colors.Terciary.Light1)) { PointF point = new PointF(graphMarginX + 4, Height - graphMarginY - 5 - (Style.Fonts.Small.Height * 2)); Helper.DrawTextShadow(g, "Upload", point, Style.Fonts.Small, Color.Black); g.DrawString("Upload", Style.Fonts.Small, brush, point); } using (Brush brush = new SolidBrush(Style.Colors.Secondary.Main)) { PointF point = new PointF(graphMarginX + 4, Height - graphMarginY - 5 - (Style.Fonts.Small.Height * 1)); Helper.DrawTextShadow(g, "Download", point, Style.Fonts.Small, Color.Black); g.DrawString("Download", Style.Fonts.Small, brush, point); } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (ClientManager.Training) { DrawNoData(g, "DISABLED"); DrawBorders(g); return; } // Draw grid float gridCount = (int)((Width - graphMarginX) / gridWidth); float gridSizeX = (Width - graphMarginX) / gridCount; gridCount = (int)(Height / gridHeight); float gridSizeY = Height / gridCount; using (Pen pen = new Pen(Style.Colors.Primary.Dark2)) { for (float posX = graphMarginX; posX < Width; posX += gridSizeX) { g.DrawLine(pen, (int)posX, gridOffset, (int)posX, Height); } for (float posY = gridOffset; posY < Height; posY += gridSizeY) { g.DrawLine(pen, graphMarginX, (int)posY, Width, (int)posY); } } // Draw Y labels float labelDist = (Height - (graphMarginY * 2)) / 12f; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { for (int i = 0; i < 11; i += 2) { int val = 100 - (i * 10); float width = g.MeasureString(val + "%", Style.Fonts.Small).Width; float posY = graphMarginY + (labelDist * i); g.DrawString(val + "%", Style.Fonts.Small, brush, new PointF(graphMarginX - width - 5, posY)); } } // Draw min/max lines using (Pen pen = new Pen(Style.Colors.Secondary.Dark2, 3)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.DashPattern = new float[] { 2, 2 }; g.DrawLine(pen, graphMarginX + 5, 8, Width - 5, 8); g.DrawLine(pen, graphMarginX + 5, Height - 8, Width - 5, Height - 8); } // Draw label divider using (Pen pen = new Pen(Style.Colors.Primary.Main)) { g.DrawLine(pen, graphMarginX, graphMarginY, graphMarginX, Height - graphMarginY); } // Draw cpu values Helper.DrawGraphLine(g, new RectangleF(graphMarginX, graphMarginY, Width - graphMarginX, Height - (2 * graphMarginY)), cpuValues.ToArray(), 100, 0, Style.Colors.Terciary.Dark2, Style.Colors.Terciary.Main, 1.5f); // Draw title using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { Helper.DrawTextShadow(g, Text, new PointF(graphMarginX + 2, 14), Style.Fonts.Title, Color.Black); g.DrawString(Text, Style.Fonts.Title, brush, new PointF(graphMarginX + 2, 14)); } // Finally, draw the borders of the control DrawBorders(g); }
// -------------------------- protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; float posY = 0; if (ClientManager.Training) { DrawNoData(g, "DISABLED"); DrawBorders(g); return; } try { lock (this) { if (priceData != null) { // Draw grid float rightDivider = Width - gridRightDivider; float gridCount = (int)((rightDivider - graphMarginX) / gridWidth); float gridSizeX = (rightDivider - graphMarginX) / gridCount; gridCount = (int)(Height / gridHeight); float gridSizeY = Height / gridCount; using (Pen pen = new Pen(Style.Colors.Primary.Dark2)) { for (float posX = graphMarginX; posX < rightDivider; posX += gridSizeX) { g.DrawLine(pen, (int)posX, gridOffset, (int)posX, Height); } for (posY = gridOffset; posY < Height; posY += gridSizeY) { g.DrawLine(pen, graphMarginX, (int)posY, rightDivider, (int)posY); } g.DrawLine(pen, rightDivider, gridOffset, rightDivider, Height); } Color pairNameColor; if (Blocked) { pairNameColor = Style.Colors.Secondary.Dark1; } else if (MarkedUser) { pairNameColor = Style.Colors.Terciary.Main; } else { pairNameColor = Style.Colors.Primary.Light1; } // ------------------ // Draw pair name using (Brush brush = new SolidBrush(pairNameColor)) { g.DrawString(pair.BaseCurrency + " / " + pair.QuoteCurrency, Style.Fonts.Medium, brush, new PointF(6, 7)); } posY = Style.Fonts.Medium.Height + 10; // Draw price float width = 0; string[] priceParts = Helper.SplitLeadingZeros(lastPrice.ToString("F8")); using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { width = g.MeasureString("Price: ", Style.Fonts.Tiny).Width; g.DrawString("Price: ", Style.Fonts.Tiny, brush, new PointF(7, posY)); } using (Brush brush = new SolidBrush(Style.Colors.Primary.Dark1)) { g.DrawString(priceParts[0], Style.Fonts.Tiny, brush, new PointF(7 + width, posY)); width += g.MeasureString(priceParts[0], Style.Fonts.Tiny).Width; } using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { g.DrawString(priceParts[1], Style.Fonts.Tiny, brush, new PointF(5 + width, posY)); } posY += Style.Fonts.Tiny.Height + 3; // Draw volume using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { width = g.MeasureString("Volume: ", Style.Fonts.Tiny).Width; g.DrawString("Volume: ", Style.Fonts.Tiny, brush, new PointF(7, posY)); } using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { g.DrawString(volume.ToString("F3"), Style.Fonts.Tiny, brush, new PointF(7 + width, posY)); } posY += Style.Fonts.Tiny.Height + 3; // Draw 24h change using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { width = g.MeasureString("Change: ", Style.Fonts.Tiny).Width; g.DrawString("Change: ", Style.Fonts.Tiny, brush, new PointF(7, posY)); } Color changeColor = Helper.LerpColor((float)change24, -30, 30, Style.Colors.Negative, Style.Colors.Positive); string changeString = ""; if (change24 > 0) { changeString += "+"; } changeString += change24.ToString("F2") + "%"; using (Brush brush = new SolidBrush(changeColor)) { g.DrawString(changeString, Style.Fonts.Tiny, brush, new PointF(5 + width, posY)); } // Draw min/max lines using (Pen pen = new Pen(Style.Colors.Secondary.Dark2, 3)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.DashPattern = new float[] { 2, 2 }; g.DrawLine(pen, graphMarginX + 5, 8, rightDivider - 5, 8); g.DrawLine(pen, graphMarginX + 5, Height - 8, rightDivider - 5, Height - 8); } double maxValue = 0; double minValue = double.MaxValue; // Find the minimum and maximum value for (int i = 0; i < priceData.Length; i++) { if (priceData[i].MarketData.PriceLast > maxValue) { maxValue = priceData[i].MarketData.PriceLast; } if (priceData[i].MarketData.PriceLast < minValue) { minValue = priceData[i].MarketData.PriceLast; } } maxValue *= 1.001; minValue *= 0.999; // Draw graph data Helper.DrawGraphLine(g, new RectangleF(graphMarginX, graphMarginY, rightDivider - graphMarginX, Height - (graphMarginY * 2)), priceData.ToArray(), maxValue, minValue, priceData.Last().Timestamp - (GraphTimeframe * 3600), 38, 1.5f); // Draw spread using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { PointF point = new PointF(graphMarginX + 4, Height - graphMarginY - 5 - Style.Fonts.Small.Height); float graphSpread = (float)((maxValue - minValue) / minValue) * 100; Helper.DrawTextShadow(g, "Spread: " + graphSpread.ToString("F4") + "%", point, Style.Fonts.Small, Color.Black); g.DrawString("Spread: " + graphSpread.ToString("F4") + "%", Style.Fonts.Small, brush, point); } // Draw legend using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { PointF point = new PointF(graphMarginX + 4, Height - graphMarginY - 10 - (Style.Fonts.Small.Height * 2)); string text = "Graph: " + GraphTimeframe + "h"; Helper.DrawTextShadow(g, text, point, Style.Fonts.Small, Color.Black); g.DrawString(text, Style.Fonts.Small, brush, point); } } else { DrawNoData(g); } } DrawBorders(g); } catch (Exception ex) { Console.WriteLine(ex.Message + " - " + ex.StackTrace); } }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (ClientManager.Training) { DrawNoData(g, "DISABLED"); DrawBorders(g); return; } // Draw grid float gridCount = (int)((Width - graphMarginX) / gridWidth); float gridSizeX = (Width - graphMarginX) / gridCount; gridCount = (int)(Height / gridHeight); float gridSizeY = Height / gridCount; using (Pen pen = new Pen(Style.Colors.Primary.Dark2)) { for (float posX = graphMarginX; posX < Width; posX += gridSizeX) { g.DrawLine(pen, (int)posX, gridOffset, (int)posX, Height); } for (float posY = gridOffset; posY < Height; posY += gridSizeY) { g.DrawLine(pen, graphMarginX, (int)posY, Width, (int)posY); } } // Find the maximum value double maxValue = 0; if (pingValues != null) { for (int i = 0; i < pingValues.Count; i++) { if (pingValues[i] > maxValue) { maxValue = pingValues[i]; } } } maxValue *= 1.3; // Draw Y labels float labelDist = (Height - (2 * graphMarginY)) / 5.8f; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { for (int i = 0; i < 6; i++) { int val = (int)(((5 - i) / 5f) * maxValue); float posY = graphMarginY + (i * labelDist); float width = g.MeasureString(val.ToString(), Style.Fonts.Small).Width; g.DrawString(val.ToString(), Style.Fonts.Small, brush, new PointF(graphMarginX - width - 5, posY)); } } // Draw min/max lines using (Pen pen = new Pen(Style.Colors.Secondary.Dark2, 3)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.DashPattern = new float[] { 2, 2 }; g.DrawLine(pen, graphMarginX + 5, 8, Width - 5, 8); g.DrawLine(pen, graphMarginX + 5, Height - 8, Width - 5, Height - 8); } // Draw graph values Helper.DrawGraphLine(g, new RectangleF(graphMarginX, graphMarginY, Width - graphMarginX, Height - (2 * graphMarginY)), pingValues.ToArray(), maxValue, 0, Style.Colors.Terciary.Dark2, Style.Colors.Terciary.Main, 1.5f); // Draw title using (Brush brush = new SolidBrush(Style.Colors.Primary.Light1)) { float width = g.MeasureString("Ping", Style.Fonts.Title).Width; Helper.DrawTextShadow(g, "Ping", new PointF(graphMarginX + 2, 20), Style.Fonts.Title, Color.Black); g.DrawString("Ping", Style.Fonts.Title, brush, new PointF(graphMarginX + 2, 20)); Helper.DrawTextShadow(g, "(ms)", new PointF(graphMarginX + width + 4, 24), Style.Fonts.Small, Color.Black); g.DrawString("(ms)", Style.Fonts.Small, brush, new PointF(graphMarginX + width + 4, 24)); } // Draw borders DrawBorders(g); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.Clear(Style.Colors.Background); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; try { if (tickers != null) { float posY = 0; // Draw grid float gridCount = (int)((Width - graphMarginX - rightDivider) / gridWidth); float gridSizeX = (Width - graphMarginX - rightDivider) / gridCount; gridCount = (int)((Height - bottomDivider) / gridHeight); float gridSizeY = (Height - bottomDivider) / gridCount; using (Pen pen = new Pen(Style.Colors.Primary.Dark2)) { for (float posX = graphMarginX; posX < Width - rightDivider; posX += gridSizeX) { g.DrawLine(pen, (int)posX + 1, gridOffset, (int)posX + 1, Height - bottomDivider); } for (posY = gridOffset; posY < Height - bottomDivider; posY += gridSizeY) { g.DrawLine(pen, graphMarginX, (int)posY, Width - rightDivider, (int)posY); } // Draw dividers g.DrawLine(pen, graphMarginX, Height - bottomDivider, Width, Height - bottomDivider); g.DrawLine(pen, Width - rightDivider, gridOffset, Width - rightDivider, Height); } // Draw min/max lines using (Pen pen = new Pen(Style.Colors.Secondary.Dark2, 3)) { pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; pen.DashPattern = new float[] { 2, 2 }; g.DrawLine(pen, graphMarginX + 2, gridSizeY / 2, Width - rightDivider - 2, gridSizeY / 2); g.DrawLine(pen, graphMarginX + 2, Height - bottomDivider - (gridSizeY / 2), Width - rightDivider - 2, Height - bottomDivider - (gridSizeY / 2)); } // Draw timeframe legend using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { g.DrawString("(-t)", Style.Fonts.Tiny, brush, new PointF(Width - rightDivider + 5, Height - bottomDivider + 5)); } // Find the minimum and maximum value double maxValue = 0; double minValue = double.MaxValue; for (int i = 0; i < tickers.Length; i++) { if (tickers[i].MarketData.OrderTopBuy < minValue) { minValue = tickers[i].MarketData.OrderTopBuy; } if (tickers[i].MarketData.OrderTopSell > maxValue) { maxValue = tickers[i].MarketData.OrderTopSell; } } // Draw price legend int legendCount = (int)gridCount - 1; float legendHeight = (Height - bottomDivider - (2 * gridSizeY)) / legendCount; using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { for (int i = 0; i < legendCount; i++) { double price = ((maxValue - minValue) / (legendCount - 1)) * i + minValue; posY = Height - bottomDivider - gridSizeY - (gridSizeY * i) - 6; g.DrawString(((int)price).ToString(), Style.Fonts.Tiny, brush, Width - rightDivider + 10, posY); } } // Draw timeframe labels using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { int number = 0; for (float x = Width - rightDivider - gridSizeX * 3; x > 0; x -= gridSizeX * 3) { number += 180; int hours = number / 60; int mins = number % 60; string tText = hours.ToString("D2") + ":" + mins.ToString("D2"); tText = tText.Trim(); float width = g.MeasureString(tText, Style.Fonts.Tiny).Width; g.DrawString(tText, Style.Fonts.Tiny, brush, new PointF(x - (width / 2), Height - bottomDivider + 5)); } } // Draw graph Helper.DrawGraphLine(g, new RectangleF(graphMarginX + 2, graphMarginY + gridSizeY, Width - (graphMarginX * 2) - rightDivider, Height - (graphMarginY * 2) - bottomDivider - (gridSizeY * 2)), tickers, maxValue, minValue, tickers.Last().Timestamp - GraphTimeframe, 104, 1.5f); // Draw title using (Brush brush = new SolidBrush(Style.Colors.Primary.Main)) { string text = "USDT / BTC"; float width = g.MeasureString(text, Style.Fonts.Title).Width; Helper.DrawTextShadow(g, text, new PointF(graphMarginX + 6, 30), Style.Fonts.Title, Color.Black); g.DrawString(text, Style.Fonts.Title, brush, new PointF(graphMarginX + 6, 30)); } // Draw current value using (Brush brush = new SolidBrush(Style.Colors.Terciary.Dark1)) { string text = tickers.Last().MarketData.PriceLast.ToString("F2"); float width = g.MeasureString(text, Style.Fonts.Title).Width; Helper.DrawTextShadow(g, text, new PointF(graphMarginX + 6, 57), Style.Fonts.Title, Color.Black); g.DrawString(text, Style.Fonts.Title, brush, graphMarginX + 6, 57); } // Draw Network Down / Restored RectangleF networkMessageRect = new RectangleF(Width * 0.3f, Height * 0.25f, Width * 0.4f, Height * 0.4f); switch (NetworkMessage) { case NetworkMessageState.Hide: // do nothing break; case NetworkMessageState.Down: DrawNetworkDown(g, networkMessageRect); break; case NetworkMessageState.Restored: DrawNetworkRestored(g, networkMessageRect); break; } } else { DrawNoData(g); } // Draw borders DrawBordersCustom(g, (MarkedBorder ? Style.Colors.Terciary.Dark1 : Style.Colors.Primary.Main)); } catch (Exception ex) { Console.WriteLine(ex.Message + " - " + ex.StackTrace); } }