mooman_fl
Well-known member
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 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:
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?
All of my calls have gone as expected until I added this line to the DrawOpen sub:
Code:
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:
Code:
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?