stringformat

  • Thread starter Thread starter Joshua T. Moore
  • Start date Start date
J

Joshua T. Moore

Is there any way to get StringFormat in the compact framework? All I need
are the pieces below. This would save hours if not days of manual
adjustment. This would be used in user-created class.

Thanks,
Joshua Moore

StringFormat format = new StringFormat(StringFormatFlags.NoWrap);

format.LineAlignment = StringAlignment.Center;

format.Alignment = StringAlignment.Center;
 
Having the StringFormat class would be nice. But we don't have it yet. So
you'll need to handle the calculations yourself. The ButtonEx class, source
linked below, contains a private method named
"GetLocationFromContentAlignment" that should help in doing these sorts of
calculations. You might want to start by looking there.
http://www.opennetcf.org/SourceBrow...root/Source/OpenNETCF.Windows.Forms/Button.cs

--
Tim Wilson
..Net Compact Framework MVP

<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
 
Is contentAlignment avaiable? Does that allow middle center alignment in
compact framework?
 
You'll need to fully define the ContentAlignment enum as well, I forgot that
not all the enum values are in the CF. Check this out.
http://www.opennetcf.org/SourceBrow.../Source/OpenNETCF.Drawing/ContentAlignment.cs
Does that allow middle center alignment in
compact framework?
Yes, the method that I mentioned in the previous post will return a Point
that represents the point at which the string should be drawn.

--
Tim Wilson
..Net Compact Framework MVP

<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
 
I really appreciate your help. Last question: I don't believe DrawString
allows a contentAlignment. Is there an easy way to draw strings (GDI) with
content alignment (user-class)?
 
You can use the "GetLocationFromContentAlignment" to return a Point struct
from which you can use the X and Y properties with the DrawString method. If
you walk through the OnPaint method of the ButtonEx
class(http://www.opennetcf.org/SourceBrowse/view.aspx?f=d:/sites/OpenNETCF/I
netPub/wwwroot/Source/OpenNETCF.Windows.Forms/Button.cs) you can see how
this all works.

--
Tim Wilson
..Net Compact Framework MVP

<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
 
This seems like a lot of work, and on a CE device might slow things down.
If you know the font size and the destination rectangle, can you measure the
string and get a clientRect?
 
You can measure the string to know the approximate width and height required
but you still need to determine the positioning within the rectangle in
order to draw the text. In the case of the "GetLocationFromContentAlignment"
method, only simple mathematical calculations and bit shifting is being done
to determine the location at which to render the text. So this should not
slow the painting down to an unreasonable speed.

--
Tim Wilson
..Net Compact Framework MVP

<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
 
Thank you so much...it's very fast.

Tim Wilson said:
You can measure the string to know the approximate width and height
required
but you still need to determine the positioning within the rectangle in
order to draw the text. In the case of the
"GetLocationFromContentAlignment"
method, only simple mathematical calculations and bit shifting is being
done
to determine the location at which to render the text. So this should not
slow the painting down to an unreasonable speed.

--
Tim Wilson
.Net Compact Framework MVP

<Feedback>
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
</Feedback>
 
Back
Top