Click here to Skip to main content
16,006,766 members
Home / Discussions / C#
   

C#

 
GeneralRe: mfc contron in c# Pin
isamir20-Aug-04 7:30
isamir20-Aug-04 7:30 
GeneralRe: mfc contron in c# Pin
Nick Parker20-Aug-04 7:51
protectorNick Parker20-Aug-04 7:51 
Generalauthoring tool in c# Pin
hudhud20-Aug-04 6:32
hudhud20-Aug-04 6:32 
GeneralRe: authoring tool in c# Pin
Dave Kreskowiak20-Aug-04 9:36
mveDave Kreskowiak20-Aug-04 9:36 
GeneralRotate Text - Find bounding rectangle Pin
Member 64401620-Aug-04 6:03
Member 64401620-Aug-04 6:03 
GeneralRe: Rotate Text - Find bounding rectangle Pin
Heath Stewart20-Aug-04 12:32
protectorHeath Stewart20-Aug-04 12:32 
GeneralRe: Rotate Text - Find bounding rectangle Pin
Werdna20-Aug-04 13:09
Werdna20-Aug-04 13:09 
GeneralRe: Rotate Text - Find bounding rectangle Pin
Member 64401623-Aug-04 6:43
Member 64401623-Aug-04 6:43 
Actually what I needed is a bit more complicated. I first used MeasureString to create a rectangle for the text. Then I want to rotate that rectangle and find the largest "non-rotate" rectangle that rectangle will fit in. I don't care about the location of the largest rectangle, just the width and height. I did figure this out with a bunch of math. here is the routine if anyone is interested.

Note that the rect that is passed into this routine is the rect created using MeasureString.

private RectangleF FindBoundingRect(RectangleF rect, float angle)
{
// Do a quick short cut here if the text is not really rotated
// but is instead horizontal or rotated.
if (angle == 0 || angle == 180 || angle == 360)
{
return new RectangleF(0, 0, rect.Width, rect.Height);
}
else if (angle == 90 || angle == 270)
{
return new RectangleF(0, 0, rect.Height, rect.Width);
}
else if (angle > 360)
{
// Don't handle this case for now.
return new RectangleF(0, 0, 0, 0);
}

// First transform the angle to radians.
float radianAngle = angle * (float)(Math.PI / 180.0F);
float radian90Degrees = 90 * (float)(Math.PI / 180.0F);

// First find the rotated point 1. This is the bottom right point. The radius
// for this point is the width.
float x = (float)(rect.Width * Math.Cos(radianAngle));
float y = (float)(rect.Width * Math.Sin(radianAngle));
PointF p1 = new PointF(x, y);

// Now find point 3 which is also easy. This is the top left point. The
// radius for this point is the height.
x = (float)(rect.Height * Math.Cos(radianAngle + radian90Degrees));
y = (float)(rect.Height * Math.Sin(radianAngle + radian90Degrees));
PointF p3 = new PointF(x, y);

// Point 2, the top right point, is a bit trickier. First find the angle
// from the bottom left up to the top left when the rect is not rotated.
float radianAngleP2 = (float) Math.Atan(rect.Height / rect.Width);

// Now find the length of the diagonal line between these two points.
float radiusP2 = (float) Math.Sqrt((rect.Height * rect.Height) + (rect.Width * rect.Width));

// Now we can find the x,y of point 2 rotated by the specified angle.
x = (float)(radiusP2 * Math.Cos(radianAngle + radianAngleP2));
y = (float)(radiusP2 * Math.Sin(radianAngle + radianAngleP2));

PointF p2 = new PointF(x, y);

// Now based on the original angle we can figure out the width and height
// of our returned rectagle.
float width = 0;
float height = 0;

if (angle < 90)
{
width = p1.X + Math.Abs(p3.X);
height = p2.Y;
}
else if (angle < 180)
{
width = Math.Abs(p2.X);
height = p1.Y + Math.Abs(p3.Y);
}
else if (angle < 270)
{
width = Math.Abs(p1.X) + p3.X;
height = Math.Abs(p2.Y);
}
else
{
width = p2.X;
height = Math.Abs(p1.Y) + p3.Y;
}

return new RectangleF(0, 0, width, height);
}
GeneralRe: Rotate Text - Find bounding rectangle Pin
cnurse20-Aug-04 22:51
cnurse20-Aug-04 22:51 
GeneralRe: Rotate Text - Find bounding rectangle Pin
Member 64401623-Aug-04 6:38
Member 64401623-Aug-04 6:38 
GeneralTrace C# .NET Pin
Md Saleem Navalur20-Aug-04 5:21
Md Saleem Navalur20-Aug-04 5:21 
GeneralRe: Trace C# .NET Pin
Dave Kreskowiak20-Aug-04 9:26
mveDave Kreskowiak20-Aug-04 9:26 
GeneralExposing Application Object Pin
kim3er20-Aug-04 2:29
kim3er20-Aug-04 2:29 
GeneralRe: Exposing Application Object Pin
LongRange.Shooter20-Aug-04 2:47
LongRange.Shooter20-Aug-04 2:47 
GeneralRe: Exposing Application Object Pin
kim3er20-Aug-04 2:53
kim3er20-Aug-04 2:53 
GeneralRe: Exposing Application Object Pin
LongRange.Shooter20-Aug-04 3:11
LongRange.Shooter20-Aug-04 3:11 
GeneralRe: Exposing Application Object Pin
Nick Parker20-Aug-04 6:54
protectorNick Parker20-Aug-04 6:54 
GeneralRe: Exposing Application Object Pin
kim3er23-Aug-04 1:34
kim3er23-Aug-04 1:34 
GeneralRe: Exposing Application Object Pin
Nick Parker23-Aug-04 4:01
protectorNick Parker23-Aug-04 4:01 
GeneralRe: Exposing Application Object Pin
mav.northwind24-Aug-04 1:27
mav.northwind24-Aug-04 1:27 
GeneralMouseWheel events without focus Pin
cnurse20-Aug-04 1:48
cnurse20-Aug-04 1:48 
GeneralRe: MouseWheel events without focus Pin
Dave Kreskowiak20-Aug-04 9:24
mveDave Kreskowiak20-Aug-04 9:24 
GeneralRe: MouseWheel events without focus Pin
Heath Stewart20-Aug-04 12:38
protectorHeath Stewart20-Aug-04 12:38 
GeneralRe: MouseWheel events without focus Pin
cnurse20-Aug-04 22:48
cnurse20-Aug-04 22:48 
GeneralRe: MouseWheel events without focus Pin
Heath Stewart23-Aug-04 7:12
protectorHeath Stewart23-Aug-04 7:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.