DrawString Alignment

  • Thread starter Peter O'Callaghan via .NET 247
  • Start date
P

Peter O'Callaghan via .NET 247

(I tried to post this last week but I can't find it now, so Iappologies if it's on twice)

I am attempting to create a custom control for my CF application.This control should be able to incorporate a muliline headingand should also be able to be aligned either Left, Right orCenter. Now I can think of two ways of doing this. The first isby using a label, but since my application will contain alot ofcontrols, I feel this would give pretty high overheads. Theother way is to use DrawString.

Using DrawString however, there seems to be no options foralignment. I've even attempted to achieve the look by splitingthe string into lines, and calculating the position of each lineusing MeasureString to find its width. Using this method thecenter alignment looks good, but with Right align the edges donow line up as I expect them to. The only reason I can think offor this is somekind of rounding error, involved withMeasureString.

Has anyone got any idea how I can achieve a multiline, alignableheading without using a label?
 
A

Alex Yakhnin [MVP]

Take a look at the ButtonEx code in SDF:

http://www.opennetcf.org/SourceBrow...root/Source/OpenNETCF.Windows.Forms/Button.cs

--
Alex Yakhnin .NET CF MVP
www.intelliprog.com | www.opennetcf.org

(I tried to post this last week but I can't find it now, so I appologies if
it's on twice)

I am attempting to create a custom control for my CF application. This
control should be able to incorporate a muliline heading and should also be
able to be aligned either Left, Right or Center. Now I can think of two ways
of doing this. The first is by using a label, but since my application will
contain alot of controls, I feel this would give pretty high overheads. The
other way is to use DrawString.

Using DrawString however, there seems to be no options for alignment. I've
even attempted to achieve the look by spliting the string into lines, and
calculating the position of each line using MeasureString to find its width.
Using this method the center alignment looks good, but with Right align the
edges do now line up as I expect them to. The only reason I can think of for
this is somekind of rounding error, involved with MeasureString.

Has anyone got any idea how I can achieve a multiline, alignable heading
without using a label?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top