I realized something interesting about the NETCF this weekend: The only classes that support the CreateGraphics() function are Forms and the base class control. I like to use Panel controls to split up my graphics needs; I can have a simple message area, drawing area, whatever. Just makes it simple. However, I need to get a graphics object. I can Invalidate the panel and write code in the Paint event (I get a Graphics object from the arguments), but that isn't always practical. As a matter of fact, this is most useful when updating a message or something similar.
So, I tried to get at the base Control class of the Panel class using the following:
So, here I am trying to do just that.
Imagine I have a Panel control called Panel1, and here is what I am doing:
Dim oControl as Control
Dim G as Graphics
oControl = CType(Panel1, Control) 'Note that I get no error here...but it isn't converted either
G = Control.CreateGraphics() 'Errors out here...the oControl is considered a panel by the compiler.
So, I tried this method:
Dim oControl as Control = New Panel
oControl = Panel1 'Should get at the base class....or so I thought.
Same error.
Seems like this should be *way* easier than it is. Again, I can code around it using the Paint event, but I shouldn't have to do so. This was so much easier in VB6.......oy.
EDIT: BTW, the compiler won't argue at all if you type Panel1.CreateGraphics() as you would with regular framework...until you actually compile and deploy. This does work fine in the regular framework, too.