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); 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); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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,...
|
by: Chris |
last post by:
Hi,
Is it possible to rotate a control on a form ? (e.g. Button, customcontrol)
thnx
Christian
|
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
|
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 &...
|
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...
|
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.
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
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...
| |