Graphics.DrawString() drawing text with multiple colors
-
Hi everyone. I am working on a project where I am scrolling text across the screen that identifies an image, along with the time. "New York, NY - 5:00AM". I have the drawing and scrolling down pat. I am using a graphics object and using drawstring in my custom OnPaint() event. The problem is that I need to have the time in a different color. ("New York, NY -" will be in black, where "5:00AM" will be in yellow). I am not sure how to go about doing this. I was not sure if one DrawString() could have multiple colors embedded in it, or if I need to have two DrawStrings with the X offset just right. If I do have to do the latter method, can you point me in the direction of figuring out where that X Start Position should be based on a given string (ie, if I start drawing the text "New York, NY" at x position 600, how do I know what X position I should begin to start drawing the 05:00AM text? This is where I am at a loss and any help would be appreciated big time. Thanks!
-
Hi everyone. I am working on a project where I am scrolling text across the screen that identifies an image, along with the time. "New York, NY - 5:00AM". I have the drawing and scrolling down pat. I am using a graphics object and using drawstring in my custom OnPaint() event. The problem is that I need to have the time in a different color. ("New York, NY -" will be in black, where "5:00AM" will be in yellow). I am not sure how to go about doing this. I was not sure if one DrawString() could have multiple colors embedded in it, or if I need to have two DrawStrings with the X offset just right. If I do have to do the latter method, can you point me in the direction of figuring out where that X Start Position should be based on a given string (ie, if I start drawing the text "New York, NY" at x position 600, how do I know what X position I should begin to start drawing the 05:00AM text? This is where I am at a loss and any help would be appreciated big time. Thanks!
Hi, each DrawString takes one Pen, each Pen has one Color, so yes you would need to call DrawString twice. There also is MeasureString which predicts how much space a DrawString (with almost the same parameters) will require. That should solve your positioning problem. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|