2
Answers

Changing Colors

huddo23

huddo23

19y
2.6k
1
Hey Guys.....Im only new to C# and im designing a program which requires the use of the gdi+. My problem is that i can draw lines on the screen and set their color but i dont know how to change the color of a line at runtime....eg, when an event happens line1 turns from black to red. Any Help would be greatly apreciated. Thanx Huddo
Answers (2)
0
huddo23

huddo23

NA 3 0 19y
Thanks alot for that your reply made more sense than most books ive read...lol Thanks Huddo
0
spgilmore

spgilmore

NA 591 0 19y
This is very simple. Just draw a line in the new color between the same two points and it will be overdrawn. GDI+ is not a collection of primitives objects. It is a Graphics object (like a canvas) which has pixels of various colors. Nothing more. If you want to change those colors, you use the various GDI+ methods to draw primitives and images in various ways. Once that operation is finished, the line, the blit, the circle etc. is not really there anymore, only the changed pixels on the Graphics canvas remain. So when you draw a line on the canvas in red, there is no line whose color can be changed. There is only a canvas whose pixels can be overdrawn. Note that this does not preclude your ability to devise a system that works that way. You can define objects that represent these primitives and keep references to them, then render them on the Graphics object on demand. You could then modify the color property or the dimensions of these primitives at any time and re-render them to display the result. This is how many programs work, but you have to implement all that yourself.