[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

theavey

11/29/2004 10:41:00 PM

In the following code the text will not display if I use the
stringFormat in the Drawstring and will separate the two strings if I
do not use the stringFormat:

graph = e.Graphics;
pen = new Pen(Color.Black,2);

//graph.DrawLine( pen,100,100,200,100);
drawFont = new System.Drawing.Font("Arial", 8, FontStyle.Bold);
drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

String sTest = "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM";
Region[] stringRegions = new Region[1];
StringFormat stringFormat = new StringFormat();
stringFormat = StringFormat.GenericDefault;
stringFormat.Trimming = System.Drawing.StringTrimming.Character;
stringFormat.FormatFlags += 16384;
//graph.TextRenderingHint = TextRenderingHint.AntiAlias;
CharacterRange[] characterRanges = new CharacterRange[1];
characterRanges[0] = new CharacterRange(0,sTest.Length);
stringFormat.SetMeasurableCharacterRanges(characterRanges);
stringRegions = graph.MeasureCharacterRanges( sTest, drawFont,
this.ClientRectangle, stringFormat);
RectangleF rect = stringRegions[0].GetBounds(graph);
//rect.Offset(10,10);
//graph.DrawString(sTest,drawFont,drawBrush,rect);
graph.DrawString(sTest,drawFont,drawBrush,rect,stringFormat);
rect.Offset(rect.Width,0);
//graph.DrawString(sTest,drawFont,drawBrush,rect);
graph.DrawString(sTest,drawFont,drawBrush,rect,stringFormat);

Please help
2 Answers

Tom Heavey

11/29/2004 11:03:00 PM

0

I made a mistake in the previous post. The stringFormat should be initialized
with the GenericTypegraphic instead of the GenericDefault.

Thank you

"THeavey" wrote:

> In the following code the text will not display if I use the
> stringFormat in the Drawstring and will separate the two strings if I
> do not use the stringFormat:
>
> graph = e.Graphics;
> pen = new Pen(Color.Black,2);
>
> //graph.DrawLine( pen,100,100,200,100);
> drawFont = new System.Drawing.Font("Arial", 8, FontStyle.Bold);
> drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
>
> String sTest = "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM";
> Region[] stringRegions = new Region[1];
> StringFormat stringFormat = new StringFormat();
> stringFormat = StringFormat.GenericDefault;
> stringFormat.Trimming = System.Drawing.StringTrimming.Character;
> stringFormat.FormatFlags += 16384;
> //graph.TextRenderingHint = TextRenderingHint.AntiAlias;
> CharacterRange[] characterRanges = new CharacterRange[1];
> characterRanges[0] = new CharacterRange(0,sTest.Length);
> stringFormat.SetMeasurableCharacterRanges(characterRanges);
> stringRegions = graph.MeasureCharacterRanges( sTest, drawFont,
> this.ClientRectangle, stringFormat);
> RectangleF rect = stringRegions[0].GetBounds(graph);
> //rect.Offset(10,10);
> //graph.DrawString(sTest,drawFont,drawBrush,rect);
> graph.DrawString(sTest,drawFont,drawBrush,rect,stringFormat);
> rect.Offset(rect.Width,0);
> //graph.DrawString(sTest,drawFont,drawBrush,rect);
> graph.DrawString(sTest,drawFont,drawBrush,rect,stringFormat);
>
> Please help
>

Tom Heavey

11/29/2004 11:49:00 PM

0

I have found a solution. If I set the FormatFlags to NoClip the code works.
This brings up a couple of questions. Why does this work and is there a more
complete explanation of the FormatFlags especially the top bit (32K bit) that
is not documented? I am also wondering about the property nativeFormat that
is not documented, but is displayed in the debugger. Some internet help
features say this is a private property. How do private properties get
exposed in the debugging environment?

Thank you,

Tom

"THeavey" wrote:

> In the following code the text will not display if I use the
> stringFormat in the Drawstring and will separate the two strings if I
> do not use the stringFormat:
>
> graph = e.Graphics;
> pen = new Pen(Color.Black,2);
>
> //graph.DrawLine( pen,100,100,200,100);
> drawFont = new System.Drawing.Font("Arial", 8, FontStyle.Bold);
> drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
>
> String sTest = "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM";
> Region[] stringRegions = new Region[1];
> StringFormat stringFormat = new StringFormat();
> stringFormat = StringFormat.GenericDefault;
> stringFormat.Trimming = System.Drawing.StringTrimming.Character;
> stringFormat.FormatFlags += 16384;
> //graph.TextRenderingHint = TextRenderingHint.AntiAlias;
> CharacterRange[] characterRanges = new CharacterRange[1];
> characterRanges[0] = new CharacterRange(0,sTest.Length);
> stringFormat.SetMeasurableCharacterRanges(characterRanges);
> stringRegions = graph.MeasureCharacterRanges( sTest, drawFont,
> this.ClientRectangle, stringFormat);
> RectangleF rect = stringRegions[0].GetBounds(graph);
> //rect.Offset(10,10);
> //graph.DrawString(sTest,drawFont,drawBrush,rect);
> graph.DrawString(sTest,drawFont,drawBrush,rect,stringFormat);
> rect.Offset(rect.Width,0);
> //graph.DrawString(sTest,drawFont,drawBrush,rect);
> graph.DrawString(sTest,drawFont,drawBrush,rect,stringFormat);
>
> Please help
>