junkbond Posted April 19, 2007 Report Share Posted April 19, 2007 I'm attempting to develop a "bullseye"-type scatter plot that has 3 colored "target" rings beneath the markers. I had previously done something similar in the COM-based version of ChartFX using the PrePaint event and the Windows GDI API. However, I'm having trouble accomplishing the same thing with ChartFX 2005 and the System.Drawing namespace. I'm using this code below, which causes a crash after execution leaves the event. Strangely, if I set the Handled property of the EventArgs to true, the crash does not occur. Is there something I need to be doing to "release" the Graphics object so ChartFX can use it after I'm finished? Thanks! Private Sub Chart1_PrePaint(ByVal sender As Object, ByVal e As ChartFX.WinForms.CustomPaintEventArgs) Handles Chart1.PrePaint Dim xUpLeftOuter As Integer, yUpLeftOuter As Integer Dim xBotRightOuter As Integer, yBotRightOuter As Integer Dim xUpLeftMiddle As Integer, yUpLeftMiddle As Integer Dim xBotRightMiddle As Integer, yBotRightMiddle As Integer Dim xUpLeftInner As Integer, yUpLeftInner As Integer Dim xBotRightInner As Integer, yBotRightInner As Integer Dim USL As Double = Statistics1.Calculators(0).Usl Const pGreen As Single = 0.25 Const pYellow As Single = 0.5 Const pRed As Single = 0.75 If (m_ChartType = OrionChartTypes.TruePosition) Then xUpLeftInner = Chart1.AxisY.ValueToPixel(-(pGreen * USL)) yUpLeftInner = Chart1.AxisY.ValueToPixel((pGreen * USL)) xBotRightInner = Chart1.AxisY.ValueToPixel((pGreen * USL)) yBotRightInner = Chart1.AxisY.ValueToPixel(-(pGreen * USL)) xUpLeftMiddle = Chart1.AxisY.ValueToPixel(-(USL * pYellow)) yUpLeftMiddle = Chart1.AxisY.ValueToPixel((USL * pYellow)) xBotRightMiddle = Chart1.AxisY.ValueToPixel((USL * pYellow)) yBotRightMiddle = Chart1.AxisY.ValueToPixel(-(USL * pYellow)) xUpLeftOuter = Chart1.AxisY.ValueToPixel(-((USL * pRed))) yUpLeftOuter = Chart1.AxisY.ValueToPixel(((USL * pRed))) xBotRightOuter = Chart1.AxisY.ValueToPixel(((USL * pRed))) yBotRightOuter = Chart1.AxisY.ValueToPixel(-((USL * pRed))) Using g As Graphics = e.Graphics Dim p As Pen = New Pen(Color.Black, 2) g.DrawEllipse(p, xUpLeftOuter, yUpLeftOuter, _ xBotRightOuter - xUpLeftOuter, yBotRightOuter - yUpLeftOuter) g.FillEllipse(Brushes.Firebrick, xUpLeftOuter, yUpLeftOuter, _ xBotRightOuter - xUpLeftOuter, yBotRightOuter - yUpLeftOuter) g.DrawEllipse(p, xUpLeftMiddle, yUpLeftMiddle, _ xBotRightMiddle - xUpLeftMiddle, yBotRightMiddle - yUpLeftMiddle) g.FillEllipse(Brushes.LightBlue, xUpLeftMiddle, yUpLeftMiddle, _ xBotRightMiddle - xUpLeftMiddle, yBotRightMiddle - yUpLeftMiddle) g.DrawEllipse(p, xUpLeftInner, yUpLeftInner, _ xBotRightInner - xUpLeftInner, yBotRightInner - yUpLeftInner) g.FillEllipse(Brushes.RoyalBlue, xUpLeftInner, yUpLeftInner, _ xBotRightInner - xUpLeftInner, yBotRightInner - yUpLeftInner) End Using End If End Sub Link to comment Share on other sites More sharing options...
Frank Posted April 20, 2007 Report Share Posted April 20, 2007 The problem: You are disposing e.Graphics ! Instead of: Using g As Graphics = e.Graphics Do: Dim g As Graphics = e.Graphics The Pen p, you need to dispose because you are creating it, the Graphics is ours and you need to leave it alive. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.