L
Leo
I would like to rotate text and draw it starting from certain
location, say (10, 20). The problem for me is that it does rotate, but
it never draws the text from (10, 20). Will you please tell me where I
am wrong?
double trangent = Math.Atan2(ptTo.Y - ptFrom.Y, ptTo.X - ptFrom.X);
float angle = (float)(trangent * (180/Math.PI));
SizeF stringSize = e.Graphics.MeasureString(Text, this.Font);
float midX = (ptTo.Y + ptFrom.Y) / 2.0F;
float midY = (ptTo.X + ptFrom.X) / 2.0F;
double xOrgText = midX - stringSize.Width * Math.Tan(trangent) /
2.0F;
double yOrgText = midY - stringSize.Width *
Math.Tan(Math.PI/-trangent) / 2.0F;
using (Pen blackPen = new Pen(Color.Black, 2))
{
using (SolidBrush blackBrush = new SolidBrush(Color.Black))
{
e.Graphics.DrawLine(blackPen, ptFrom, ptTo);
e.Graphics.TranslateTransform((float)xOrgText, (float)yOrgText);
e.Graphics.RotateTransform(angle, MatrixOrder.Append);
e.Graphics.DrawString(Text, this.Font, blackBrush, (float)xOrgText, -
(float)yOrgText);
}
}
base.OnPaint(e);
location, say (10, 20). The problem for me is that it does rotate, but
it never draws the text from (10, 20). Will you please tell me where I
am wrong?
double trangent = Math.Atan2(ptTo.Y - ptFrom.Y, ptTo.X - ptFrom.X);
float angle = (float)(trangent * (180/Math.PI));
SizeF stringSize = e.Graphics.MeasureString(Text, this.Font);
float midX = (ptTo.Y + ptFrom.Y) / 2.0F;
float midY = (ptTo.X + ptFrom.X) / 2.0F;
double xOrgText = midX - stringSize.Width * Math.Tan(trangent) /
2.0F;
double yOrgText = midY - stringSize.Width *
Math.Tan(Math.PI/-trangent) / 2.0F;
using (Pen blackPen = new Pen(Color.Black, 2))
{
using (SolidBrush blackBrush = new SolidBrush(Color.Black))
{
e.Graphics.DrawLine(blackPen, ptFrom, ptTo);
e.Graphics.TranslateTransform((float)xOrgText, (float)yOrgText);
e.Graphics.RotateTransform(angle, MatrixOrder.Append);
e.Graphics.DrawString(Text, this.Font, blackBrush, (float)xOrgText, -
(float)yOrgText);
}
}
base.OnPaint(e);