Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

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 on Monday, September 11, 2006 1:09 PM | Back to top


Comments on this post: Interesting limitation to NETCF

# re: Interesting limitation to NETCF
Requesting Gravatar...
You might want to read up on class inheritance and virtual methods
Left by Alex Feinman on Oct 05, 2006 3:27 PM

# re: Interesting limitation to NETCF
Requesting 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
Left by Theo Moore on Oct 06, 2006 5:01 AM

Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: GeeksWithBlogs.net