1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WinCloningDGV
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
//Par defaut l'origine des coord (0,0 ) est
//le coin sup haut-gauche du form(topleft)
// la rotation se fait par rapport à cette origine
// si tu fais une rotation >=90 ou <=-90 tu ne vois plus le texte
//tout cela est decevant et ridicule ...
string str1 =string.Empty ;
private void button1_Click(object sender, EventArgs e)
{
str1 = "texte obeissant";
this.Invalidate();
}
private void Form3_Paint(object sender, PaintEventArgs e)
{
//Pour remedier on utilise un matrix qui permet de
//specifier la position de l'axe de rotation
//du "TEXTE OBEISSANT"
Font myFont = new Font("Arial", 16, FontStyle.Bold);
PointF position = new PointF(300, 300);
//1-position initiale san rotation
e.Graphics.DrawString(str1, myFont, Brushes.DarkBlue , position);
//2-rotation par rapport au point 300,300 de 90
Matrix myMat = new Matrix();
myMat.RotateAt(90, position);
e.Graphics.Transform = myMat;
e.Graphics.DrawString(str1, myFont, Brushes.Red, position);
//3-tourne par rapport au centre de son rectangle englobant
myMat.RotateAt(-90, position);
e.Graphics.Transform = myMat;
//string format mesure taille de son rectangle englobant
SizeF strSize = e.Graphics.MeasureString(str1, myFont);
PointF center = new PointF(position.X + strSize.Width / 2, position.Y + strSize.Height);
myMat.RotateAt(45, center);
e.Graphics.Transform = myMat;
//dessine son rect
e.Graphics.FillRectangle(Brushes.Yellow, position.X,position.Y,strSize.Width,strSize.Height);
e.Graphics.DrawString(str1, myFont, Brushes.Red , position);
}
}
} |
Partager