J'essaie de faire pivoter une étiquette de 90 degrés. Pour le moment, je peux prendre le texte de l'étiquette et le faire pivoter, mais ce que je veux faire, c'est tourner une étiquette de mon choix, ou si je devais être vraiment flashy, disons un contrôle de bouton. Donc, en utilisant le code ci-dessous, comment puis-je le modifier afin que je puisse lui donner un contrôle et l'amener à le faire pivoter?Rotation du texte et des boutons de l'étiquette sur 90 degrés
protected override void OnPaint(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
string text = label4.Text;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.Trimming = StringTrimming.None;
Brush textBrush = new SolidBrush(this.ForeColor);
//Getting the width and height of the text, which we are going to write
float width = graphics.MeasureString(text, this.Font).Width;
float height = graphics.MeasureString(text, this.Font).Height;
//The radius is set to 0.9 of the width or height, b'cos not to
//hide and part of the text at any stage
float radius = 0f;
if (ClientRectangle.Width < ClientRectangle.Height)
{
radius = ClientRectangle.Width * 0.9f/2;
}
else
{
radius = ClientRectangle.Height * 0.9f/2;
}
int rotationAngle = 90;
double angle = (rotationAngle/180) * Math.PI;
graphics.TranslateTransform(
(ClientRectangle.Width + (float)(height * Math.Sin(angle)) - (float)(width * Math.Cos(angle)))/2,
(ClientRectangle.Height - (float)(height * Math.Cos(angle)) - (float)(width * Math.Sin(angle)))/2);
graphics.RotateTransform((float)rotationAngle);
graphics.DrawString(text, this.Font, textBrush, 0, 0);
graphics.ResetTransform();
}
Je l'ai fait, mais cela a ouvert une toute nouvelle boîte de Pandore ... – flavour404