tags:

views:

135

answers:

4

Some advice, please. I'm just starting out in C#. I've managed to get some shapes created on a Windows form, and now I'd like to fill them with color. In the old C++ I studied years ago, there was a floodfill function that was really easy. It has been an unpleasant realization to find there's not a similar method available in regular old C#. Does anyone have advice for me, or some code, so I can implement filling without understanding GDI+, DirectX, or rest of the avalanche of acronyms that I've run into by researching this on the web? I need to fill irregular shapes, bounded by a certain color. Gradient and transparency control would be nice, but I'd settle for plain old solid fill right now, just to get a modicom of control over this. Any help, code or advice would be really appreciated.

A: 

i used:

To get HDC http://msdn.microsoft.com/en-us/library/9z5820hw(VS.90).aspx

and to FloodFill http://www.pinvoke.net/default.aspx/gdi32/FloodFill.html

it worked

Andrey
Thank you, Audrey. I'm looking over these sites. I self-taught,still a rank novice, groping my way through this stuff. Is this easy enough that an unskilled an uneducated newbie such as myself can grasp, in your opinion? Thanks, Jimmy
Jimmy
@Jimmy yes, you can. just go step by step. Read article about P/Invoke, then read first link and take code from there. Then take second, to get HDC for Graphics you are painting on.
Andrey
+2  A: 

Take a look at the Graphics.FillXxxx() methods. The most flexible one is FillPath, it takes a GraphicsPath which in turn lets you define an arbitrary shape and fill it.

Hans Passant
Thank you, Hans. I'll look into it.
Jimmy
+1  A: 

See this site for a lot of help with using GDI in .Net:

http://www.bobpowell.net

Chris Dunaway
Thank you, Chris. This site looks really, really promising. I'll keep at it.
Jimmy
A: 

There is an article on how to flood fill in .Net at Code Project.

Dour High Arch