Shift text a number of pixels

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I would like to shift the text of a label a number of pixels to the right.
I really want to draw the textstring on another position in the label (and
not prepend a blank space to the text).

What would be the best approach for this?

TIA,

Michael
 
Just create your own label control. Its just a control that paints text. You
can then add properties to enable you to control offsets etc.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Just create your own label control. Its just a control that paints text.

Hi Bob, I started inheriting from Label because I need most of the
Label-Properties.
Isn't there an easy way to continue using Label as a baseclass and
reposition the string on paint? Or do I really have to "Measure" everything
(string & image)?

Michael
 
After some experimentation I find that you might be able to change the
behaviour. You might have to change the auto-size behaviour to add some
padding, possibly in the OnSizeChanged method.

I did discover however that overriding OnPaint enabled me to modify the
Graphics object of the paint cycle and add a matrix to the graphics
transform. This let me shift the label or scale it or rotate it to an angle.

protected override void OnPaint(PaintEventArgs e)

{

e.Graphics.Transform=new System.Drawing.Drawing2D.Matrix(2,0,0,2,20,0);

base.OnPaint(e);

}

This might lead you in the right direction.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
protected override void OnPaint(PaintEventArgs e)
{

e.Graphics.Transform=new System.Drawing.Drawing2D.Matrix(2,0,0,2,20,0);

base.OnPaint(e);

}

This might lead you in the right direction.

Hi Bob,

Thanks for your time. I'll look at this approach.

Regards,

Michael
 

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

Back
Top