mooman_fl Posted March 20, 2003 Posted March 20, 2003 In making my usercontrol I have found it necessary to use the System.Drawing class to draw some areas on my control. Up till now this has been going great. I made a new friend class MooGraphics and put in some Enums and Methods to make it easier to use from my program since many of the drawing task are repetitive. Calls to these methods in my class were called once from Initialize (after all other initialization) and once in Paint. Pretty standard. All of my calls have gone as expected until I added this line to the DrawOpen sub: Moo.LeftLines(CollapseLineLeft.Handle, bIsCollapsed, CollapseLineLeft.BackColor, 3, 3) Moo is an instance of my class. CollapseLineLeft is the control I am drawing to, and bIsCollapsed is a boolean to tell if my Control is collapsed or not. The above line calls this sub from my class: Public Sub LeftLines(ByVal CtrlHandle As System.IntPtr, ByVal Collapsed As Boolean, ByVal FillColor As Color, ByVal x As Integer, ByVal y As Integer) Dim myGraphics As Graphics Dim Shadow As New Pen(Color.FromKnownColor(KnownColor.ControlDark)) Dim Highlight As New Pen(Color.FromKnownColor(KnownColor.ControlLightLight)) If Collapsed = True Then myGraphics.DrawLine(Shadow, x, y, x + 5, y) myGraphics.DrawLine(Highlight, x, y + 1, x + 5, y + 1) myGraphics.DrawLine(Shadow, x, y, x, y + 5) myGraphics.DrawLine(Highlight, x + 1, y + 1, x + 1, y + 4) Else myGraphics.DrawLine(Shadow, x, y, x + 5, y) myGraphics.DrawLine(Highlight, x, y + 1, x + 5, y + 1) myGraphics.DrawLine(Shadow, x, y, x, y + 5) myGraphics.DrawLine(Highlight, x + 1, y + 1, x + 1, y + 4) End If myGraphics.Dispose() End Sub What is happening is after I compile (no errors with Option Strict enabled) and try to add the control to the startup project is an error: An exception occurred while trying to create an instance of ToolScroll.ToolPanel. The exception was "Object reference not set to an instance of an object." If I REM out the call to Moo.LeftLines it will add just fine. I am not doing anything different that I can tell in that sub that I am in my other drawing subs... but the others work just fine. What could be causing this? Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
mooman_fl Posted March 20, 2003 Author Posted March 20, 2003 BTW... if you are wondering why some values are not used in the sub it is simply because I hadn't implemented them yet. I was trying to test the line placement before I did rectangle fills to clear areas of the control. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Heiko Posted March 20, 2003 Posted March 20, 2003 I'm no GDI man, but --> is CollapseLineLeft.BackColor definitely instantiated? --> myGraphics appears not to be instantiated at all (where's the New() ? --> You never use the handle that you passed as a parameter. Quote .nerd
*Gurus* divil Posted March 20, 2003 *Gurus* Posted March 20, 2003 It looks to me like you're never instantiating myGraphics. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 20, 2003 Author Posted March 20, 2003 Heiko beat you to it this time divil <g> Thanks for the answer though. You are both right though. Heiko caught both parts of the problem though. (Only the last two. CollapseLineLeft is a simple Panel control so BackColor is definitly instatiated) This is what I get for not sleeping in over 24 hours. I left out this line: myGraphics = Graphics.FromHwnd(CtrlHandle) I think I better head to bed before I try to save my work and accidently reformat my drive instead. LOL Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.