473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Polymorphing brushes

I have declared a brush i.e.

Brush FillBrush;

later

FillBrush = new SolidBrush(....

everything is set in the constructor and then I use the brush to paint.

later

FillBrush = new LinearGradientBrush(...

FillBrush.InterpolationColors = ....

this does not work. It says that InterpolationColours is not defined etc...
Intellisense only shows up the methods, none of the properties, and only the
methods derived from brush.

I thought this should work?
TIA
JB
Nov 15 '05 #1
3 1912
John... The compiler is enforcing the type of the reference FillBrush
which is
Brush. The object is of class LinearGradientBrush on the heap, but the
variable FillBrush contains a reference of type Brush.
InterpolationColors is
not a valid method of the type Brush.

http://www.geocities.com/jeff_louie/OOP/oop6.htm

Regards,
Jeff
Brush FillBrush = new LinearGradientBrush(...


FillBrush.InterpolationColors = ....<
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #2
The reason you can't do it has been explained perfectly by Jeff Louie.

What is the value of polymorphism here ? The main idea behind
Polymorphism being the opposite of what you're doing : being able to
consider various objects as being of the same type (while they are not, but
simply have common attributes and behaviors to allow catching their
similarities) ... here you are trying to deal with dissimilarities through
the common interface ...

If you really having some compelling reasons (I wonder what that could
be) that doesn't show here, you can cast to the specific type before
assigning to the properties :
((LinearGradientBrush)FillBrush).InterpolationColo rs = ...

A more normal and meaning use of polymorhism would look more like :

SolidBrush solidBrush1 = new SolidBrush(...
//assign whatever you need
DoSomething(sildBrush1);

LinearGradientBrush linGradBrush = new LinearGradientBrush(...
//addign InterpolationColors and whatever else you need
DoSomething(linGradBrush);

....

void DoSomething(Brush fillBrush)
{
// code that can apply to any Brush ...
}

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:l_******************@news-server.bigpond.net.au...
I have declared a brush i.e.

Brush FillBrush;

later

FillBrush = new SolidBrush(....

everything is set in the constructor and then I use the brush to paint.

later

FillBrush = new LinearGradientBrush(...

FillBrush.InterpolationColors = ....

this does not work. It says that InterpolationColours is not defined etc... Intellisense only shows up the methods, none of the properties, and only the methods derived from brush.

I thought this should work?
TIA
JB

Nov 15 '05 #3
Thanks for the reply both of you.
What I was doing was reusing the same generic brush for painting gradients
and solid colours.
Cheers
John
"Malek" <ke****@arrabeta.com> wrote in message
news:e8****************@TK2MSFTNGP10.phx.gbl...
The reason you can't do it has been explained perfectly by Jeff Louie.

What is the value of polymorphism here ? The main idea behind
Polymorphism being the opposite of what you're doing : being able to
consider various objects as being of the same type (while they are not, but simply have common attributes and behaviors to allow catching their
similarities) ... here you are trying to deal with dissimilarities through
the common interface ...

If you really having some compelling reasons (I wonder what that could
be) that doesn't show here, you can cast to the specific type before
assigning to the properties :
((LinearGradientBrush)FillBrush).InterpolationColo rs = ...

A more normal and meaning use of polymorhism would look more like :

SolidBrush solidBrush1 = new SolidBrush(...
//assign whatever you need
DoSomething(sildBrush1);

LinearGradientBrush linGradBrush = new LinearGradientBrush(...
//addign InterpolationColors and whatever else you need
DoSomething(linGradBrush);

...

void DoSomething(Brush fillBrush)
{
// code that can apply to any Brush ...
}

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:l_******************@news-server.bigpond.net.au...
I have declared a brush i.e.

Brush FillBrush;

later

FillBrush = new SolidBrush(....

everything is set in the constructor and then I use the brush to paint.

later

FillBrush = new LinearGradientBrush(...

FillBrush.InterpolationColors = ....

this does not work. It says that InterpolationColours is not defined

etc...
Intellisense only shows up the methods, none of the properties, and only

the
methods derived from brush.

I thought this should work?
TIA
JB


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mr. B | last post by:
This is driving me NUTZ!!! I've been screwing around on this for a week now. And I have tried to find examples similar to what I have (nada). Got lots of streaming a TXT file... bah! I am...
1
by: Einar Høst | last post by:
Well, subject says it all really... Thanks, Einar -- "If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -- Lewis Carroll
0
by: Richard | last post by:
Rather than all that painting, brush, etc. code to change the styles of a ..NET datagrid to start with and on the fly, I'd rather be able to set a lot of the stuff in the designer properties of the...
5
by: JJ | last post by:
Hi all, I am using the color dialog box to select a colour to print with. However, the e.Graphics.DrawString method uses Brushes.Black, not Color.Black. How do I convert from Brushes to...
0
by: CG3000 | last post by:
I create a .PNG image ( in Macromedia Fireworks ) which has an gif in it in the top left corner and a lot of empty canvas space to the right. I use about 10 text boxes on a form to populate that...
1
by: DeWittds | last post by:
I have been tring to recreate a simple program that I wrote many years ago in quick basic. The program get name and address from a database, then the user will enter in info like order #, po # and...
4
by: marcus hall | last post by:
I am considering a strategy for implementation of a finite state machine. What I would like to do is to use derived classes to represent the state of the machine, so the vtable pointer is the state...
4
by: Peter Webb | last post by:
I am supposed to manually dispose of some instances, such as Brushes, right? I have a couple of questions: 1. I have the following code, and it works just fine: ...
31
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.