Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Diagonal Labels
 

Diagonal Labels

Hi

It is possible to make diagonal label or something similar with the same properties.


Thanks

Luis

elvinny  Thursday, April 16, 2009 10:27 AM
Hi Luis,

It's not possible to rotate controls in WinForm applications. It can be done easily in WPF applications.

Since a label's main usage is to show text, you can custom draw the text in the label using the method I provided in my previous reply. It looks like the label is rotated. Alternatively, draw the text directly on the form.

Ifyou have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Linda Liu  Thursday, April 23, 2009 8:01 AM
Hi Luis,

By "diagonal label", do you mean a label with diagonal on it? If so, you can draw the diagonal on the label by yourself.
In detail, handle the Paint event of the label to draw lines on it. The following is a sample:


void label1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(Pens.Red, new Point(0,0), new Point(this.label1.Width, this.label1.Height));
e.Graphics.DrawLine(Pens.Green, new Point(0, this.label1.Height), new Point(this.label1.Width, 0));
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Linda Liu  Tuesday, April 21, 2009 3:46 AM

Hello Linda,

Thanks for the reply

The doubt i have is if is possible to turn a label in diagonal. I have some labels in horizontal and i would like to turn or rotate a label in diagonal. There is some text info in middle center.

Regards

Luis

elvinny  Tuesday, April 21, 2009 11:28 AM

Hi Luis,

Yes, it's possible to rotate the text in a Label. To do this, you need to apply a rotate transform on the graphics object of the Label control. The following is a sample:

void label1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.RotateTransform(30);
e.Graphics.DrawString("hello",this.label1.Font,new SolidBrush(this.label1.ForeColor),new PointF(5,0));
}

Hope this helps.
If you have any questions, please feel free to let me know.

Sincerely,
Linda Liu

Linda Liu  Wednesday, April 22, 2009 4:24 AM
Hi Linda,


The last reply was helpfull, but it's not the text i want to rotate,i want is the label. i would like to control the label rotation to 80º, 45º or another degreeor angle.

Thanks for reply


Regards,

Luis
elvinny  Wednesday, April 22, 2009 10:52 AM
Hi Luis,

It's not possible to rotate controls in WinForm applications. It can be done easily in WPF applications.

Since a label's main usage is to show text, you can custom draw the text in the label using the method I provided in my previous reply. It looks like the label is rotated. Alternatively, draw the text directly on the form.

Ifyou have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Linda Liu  Thursday, April 23, 2009 8:01 AM

You can use google to search for other answers

Custom Search

More Threads

• Display Smart tag at runtime
• Custom Controls with Visual C++ .NET
• OverDrawing Custom Inherited Controls
• refresh properties window for dynamic properties
• EnableDesignMode with collections (Troubles with serialization)
• Custom DataGridView Columns
• Interfaces and User Controls with Designer
• UserControl, Inherited Control, Abstract class, (C#)
• Make a Form Fill the Window at Run Time
• Adding icon inside TextBox