Click here to Skip to main content
15,905,967 members
Home / Discussions / C#
   

C#

 
GeneralDownload files ListBox and Thread Pin
fredza2-Dec-04 8:28
fredza2-Dec-04 8:28 
GeneralRe: Download files ListBox and Thread Pin
Nick Parker2-Dec-04 9:31
protectorNick Parker2-Dec-04 9:31 
GeneralRe: Download files ListBox and Thread Pin
fredza2-Dec-04 10:04
fredza2-Dec-04 10:04 
GeneralRe: Download files ListBox and Thread Pin
Heath Stewart2-Dec-04 11:08
protectorHeath Stewart2-Dec-04 11:08 
GeneralClose Windows Form automatically Pin
realmontanakid2-Dec-04 6:27
realmontanakid2-Dec-04 6:27 
GeneralRe: Close Windows Form automatically Pin
Judah Gabriel Himango2-Dec-04 7:34
sponsorJudah Gabriel Himango2-Dec-04 7:34 
GeneralRe: Close Windows Form automatically Pin
Heath Stewart2-Dec-04 7:40
protectorHeath Stewart2-Dec-04 7:40 
GeneralChange text color on a single line Pin
Gywox2-Dec-04 5:45
Gywox2-Dec-04 5:45 
I want to change text color on a single line of text with DrawString().
Ex. <red>The <blue>qui<red>ck, b<blue>rown f<red>ox easily jumps over the lazy dog.
I'm trying to use Graphics.MeasureCharacterRanges(), this method gets the ranges
of a number of characters. All fine. Then I can use a TextureBrush with a colored
image to change the text color. The problem is that I can't use this method when rendering
Italic style text. The color rectangles don't compensate for italics text.
If anyone have any tips or a better method to do this, I will be very grathful.
Many thanks, Gywox

<br />
public void DrawTextColor(PaintEventArgs e)<br />
{<br />
	Graphics graphics = e.Graphics;<br />
	Rectangle layoutRect = new Rectangle(20, 20, 400, 100);<br />
	Font tnrFont = new Font("Times New Roman", 24, FontStyle.Italic);<br />
	StringFormat strFormat = new StringFormat();<br />
	CharacterRange[] charRanges = {<br />
			new CharacterRange(3, 4), <br />
			new CharacterRange(12, 6) };<br />
	Region[] charRegions = new Region[charRanges.Length];<br />
	string str = "The quick, brown fox easily jumps over the lazy dog.";<br />
	strFormat.SetMeasurableCharacterRanges(charRanges);<br />
<br />
	Image image = new Bitmap(layoutRect.Width, layoutRect.Height);<br />
	Graphics graphicsImage = Graphics.FromImage(image);<br />
	graphicsImage.FillRectangle(Brushes.Red, 0, 0, image.Width, image.Height);<br />
<br />
	charRegions = graphics.MeasureCharacterRanges(str, tnrFont, layoutRect, strFormat);<br />
	for (int index = 0; index < charRegions.Length; index++)<br />
	{<br />
		RectangleF boundsRect = charRegions[index].GetBounds(graphics);<br />
		graphicsImage.FillRectangle(Brushes.Blue, boundsRect);<br />
	}<br />
	TextureBrush textureBrush = new TextureBrush(image);<br />
	graphics.DrawString(str, tnrFont, textureBrush, layoutRect, strFormat);<br />
}<br />


Gywox
GeneralTest for file lock Pin
Marc Clifton2-Dec-04 5:16
mvaMarc Clifton2-Dec-04 5:16 
GeneralRe: Test for file lock Pin
Heath Stewart2-Dec-04 5:31
protectorHeath Stewart2-Dec-04 5:31 
GeneralRe: Test for file lock Pin
Marc Clifton2-Dec-04 6:04
mvaMarc Clifton2-Dec-04 6:04 
GeneralRe: Test for file lock Pin
Heath Stewart2-Dec-04 7:34
protectorHeath Stewart2-Dec-04 7:34 
GeneralRe: Test for file lock Pin
Willie Lassiter5-Dec-04 17:55
Willie Lassiter5-Dec-04 17:55 
GeneralConverting string to bitmap Pin
jawbrey2-Dec-04 5:15
jawbrey2-Dec-04 5:15 
GeneralRe: Converting string to bitmap Pin
Heath Stewart2-Dec-04 7:17
protectorHeath Stewart2-Dec-04 7:17 
GeneralBrowse all controls Pin
bouli2-Dec-04 4:34
bouli2-Dec-04 4:34 
GeneralRe: Browse all controls Pin
Judah Gabriel Himango2-Dec-04 4:58
sponsorJudah Gabriel Himango2-Dec-04 4:58 
GeneralRe: Browse all controls Pin
bouli2-Dec-04 5:02
bouli2-Dec-04 5:02 
GeneralRe: Browse all controls Pin
Heath Stewart2-Dec-04 5:20
protectorHeath Stewart2-Dec-04 5:20 
GeneralRe: Browse all controls Pin
bouli2-Dec-04 5:30
bouli2-Dec-04 5:30 
GeneralRe: Browse all controls Pin
Heath Stewart2-Dec-04 5:35
protectorHeath Stewart2-Dec-04 5:35 
GeneralRe: Browse all controls Pin
Judah Gabriel Himango2-Dec-04 5:37
sponsorJudah Gabriel Himango2-Dec-04 5:37 
GeneralRe: Browse all controls Pin
Heath Stewart2-Dec-04 7:30
protectorHeath Stewart2-Dec-04 7:30 
GeneralRe: Browse all controls Pin
turbochimp2-Dec-04 5:08
turbochimp2-Dec-04 5:08 
GeneralProblem with string literals Pin
pchak2-Dec-04 4:18
pchak2-Dec-04 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.