473,382 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to rotate text?

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);
Nov 16 '05 #1
1 9762
After you apply the rotation transform you will have to get the bounds of
the rotated text and move it back to your starting point of 10, 20.

You might need to do this with a path.

HTH
JB
"Leo" <pk*******@yahoo.com> wrote in message
news:81**************************@posting.google.c om...
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);

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: googlemike | last post by:
Is it possible to use a new CSS tag that permits one to rotate text (such as on top of column headers), and have it work in Firefox AND IE ? Or is that on the verge of coming out but isn't here...
2
by: Fabri | last post by:
I wonder if it is possible to rotate these images in this way: <img name="one" src="one.gif"> <img name="two" src="two.gif"> <img name="three" src="three.gif"> I would like every 3 (or 4,...
3
by: Chris | last post by:
Hi, Is it possible to rotate a control on a form ? (e.g. Button, customcontrol) thnx Christian
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
6
by: sales | last post by:
Hello, I am trying to get my website checkout page to rotate / take turns displaying shopping comparison engine surveys rather than display them all 4 at the same time, thus overwhelming &...
1
by: RC | last post by:
First, this is a SVG issue, not 100% of XML issue. But I can't find SVG group to post this. Since SVG is XML file, I post here hopefully someone know both SVG and XML can help. Here is my SVG...
3
by: Diego F. | last post by:
Hi all. I have a listview with images and my application must be able to rotate one image. I need a method to rotate 90 degrees rigth (i.e.). Is that possible? -- Regards, Diego F.
10
by: Joey_Stacks | last post by:
Does anyone know of a scipt that will rotate random div layers on page refresh? I have a primary content area front and center on my site homepage, and I'd like to rotate various chunks of html...
17
by: handique | last post by:
Hi, I have javascript code for rotating images, but the rotation starts only when mouse is placed over the image. But i want to rotate images automatically when the page loads. Can any guide me in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.