private void UpdateDialBitmap() { //Generate new bitmap for dial. Should only be called when some property of the dial is changed. DialBitmap = new Bitmap((int)DialRadius * 2, (int)DialRadius * 2); Graphics g = Graphics.FromImage(DialBitmap); RectangleF rect = new RectangleF(0, 0, DialRadius * 2, DialRadius * 2); Brush myBrush = new SolidBrush(DialColor); g.FillEllipse(myBrush, rect); //Draw Grid if (isGridEnabled) { Pen myPen = new Pen(Color.Black); g.DrawLine(myPen, new Point((int)DialRadius, 0), new PointF((int)DialRadius, DialRadius * 2)); g.DrawLine(myPen, new Point(0, (int)DialRadius), new PointF(DialRadius * 2, (int)DialRadius)); } if (m_numberMarker != null) { // Draw number markers for gauge. m_numberMarker.Offset = new PointF(DialRadius, DialRadius); m_numberMarker.Draw(g, this.m_centerPoint); } if (m_tickMarker != null) { m_tickMarker.Offset = new PointF(DialRadius, DialRadius); m_tickMarker.Draw(g, this.m_centerPoint); } }
private void drawBackGround(Graphics gfx) { gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.FillRectangle(new SolidBrush(BackColor), ClientRectangle); Brush myBrush; Pen myPen; /* TODO : Arc and background Ellipse should be made into gaugeElements. */ /* Draw outer border. */ if (m_isBorderEnabled) { m_Border.Draw(gfx, this.CenterPoint); } /* If enabled, draw background ellipse. */ if (m_isBackGroundEllipseEnabled) { float radius = m_backGroundEllipseRadius; if (m_isBorderEnabled) { radius -= m_Border.BorderWidth; } if (radius > 0) { RectangleF rect = new RectangleF(CenterPoint.X - radius, CenterPoint.Y - radius, 2 * radius, 2 * radius); myBrush = new SolidBrush(m_backGroundEllipseColor); gfx.FillEllipse(myBrush, rect); if (isGridEnabled) { //Draw helper grid. myPen = new Pen(Color.Red); gfx.DrawLine(myPen, new Point((int)CenterPoint.X, 0), new Point((int)CenterPoint.X, Height)); gfx.DrawLine(myPen, new Point(0, (int)CenterPoint.Y), new Point(Width, (int)CenterPoint.Y)); } } } //Draw markers foreach (GaugeMarker m in m_markerList) { m.Draw(gfx, this.CenterPoint); } //Draw tick marker collection. foreach (GaugeTickMarker m in m_TickMarkerCollection) { m.Draw(gfx, this.CenterPoint); } //Draw default number marker. mainNumberMarker.Draw(gfx, this.CenterPoint); /* Draw the arc */ if (m_isArcEnabled) { if (m_arcRadius > 0) { myPen = new Pen(m_arcColor, m_arcWidth); gfx.DrawArc(myPen, new RectangleF(CenterPoint.X - m_arcRadius, CenterPoint.Y - m_arcRadius, 2 * m_arcRadius, 2 * m_arcRadius), m_arcStartAngle, (m_arcEndAngle - m_arcStartAngle)); } } //Draw custom text fields. foreach (GaugeLabel label in m_CustomTextCollection) { label.Draw(gfx, this.CenterPoint); } }