Interesting limitation to NETCF

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.

posted @ Monday, September 11, 2006 1:09 PM

Print

Comments on this entry:

# re: Interesting limitation to NETCF

Left by Alex Feinman at 10/5/2006 3:27 PM
Gravatar
You might want to read up on class inheritance and virtual methods

# re: Interesting limitation to NETCF

Left by Theo Moore at 10/6/2006 5:01 AM
Gravatar
Thank you for your input! Yes, I understand the concepts of inheritance and polymorphism. I believe that I should able to get at the CreateGraphics() method for a Panel control (or other control) from its base Control class, and was trying to do so. The issue I am having is how to get at the base class and utilize it. I appreciate your input, but it's a bit broad; Is there a specific resource you would recommend that describes this?

Theo
Comments have been closed on this topic.
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910