有没有可以对一选定的控件(比如一Label)进行任意角度旋转的控件。(100分)

  • 主题发起人 主题发起人 jialiang
  • 开始时间 开始时间
J

jialiang

Unregistered / Unconfirmed
GUEST, unregistred user!
100分如果不够,我可以把我其它几个问题的分一起加上来,几个问题都是相关的,如下
http://www.delphibbs.com/delphibbs/dispq.asp?lid=613448 (50分)
http://www.delphibbs.com/delphibbs/dispq.asp?lid=600324 (200分)
http://www.delphibbs.com/delphibbs/dispq.asp?lid=593908 (200分)
过了很久了,也没人给个圆満的答案。
想来,要是有一个通用的旋转控件,像TStretchHandle一样对于任意控件可以随意拖动,
那对于任意控件进行任意角度旋转也一定有。最好能搭配TStretchHandle一起使用。
哪位大位助我?

 
用组件图象代替覆盖实际组件(实际组件不可见),然后对起编程,图象的旋转是容易实现的,
而对于用户这是没有区别的
——————可以在VCL类的基础上利用这种方法创建自己的类
 
深度历险:
JLLABEL.ZIPTRotateLabel 构件是一个能够旋转任意角度、立体显示文字的加强版TLabel
构件 ( 1.0 版,附源码 ),作者 : Joerg LingnerLB3D10.ZIP立体外观的 TLabel构件,
能够显示多种立体效果 (1.0 版,附源码 ),作者:InforTech, Inc。
 
TO VGA:
JlLabel等多只是实现文件旋转,而不是整个控件旋转
TO jasper:
你的意思我还不明白,能否说详细点,再举个例子,帖个源码。
 
http://ms2.deanshoes.com/~cloud下好像有。
 
难道没有这类控件吗?
 
M$ OFFICE的那些不知道是怎么做出来的
 
http://www.51delphi.com
expack控件包中有
 
1stClass 可以啊
 
http://go1.163.com/delphigirl/VCL/41.htm
 
关于“图像旋转”,有专家如下说法:
*************************************
如果有人试着通先选择新的中心点再旋转图片这个方法来得到新的图片的话,会发觉图片
上有许多“洞”,这是因为不连续的空间和整数的数学运算造成的。为了解决这个问题,
我们可以使用一个“相反”的方法。仔细考虑新图像中的每个像素,查找它在原图像中的
位置。这样的技术就会解决任何在图像中的“洞”。
*************************************
我个人观点:
通用的算法原理都一样,及选择旋转后的图像的点,通过算法查找气再原图中对应的香素点!
我觉得旋转后的图像有效区域的象素点数和原图片的象素点数一样多,怎么会出现“洞”呢?
我不理解上面这段话的含义,哪位仁兄理解了帮忙解释一下
 
我碰巧看见你的帖子,又碰巧看见网上的这篇文章,给你考了过来


一个旋转label组件

Unit ALabel;

Interface

Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TALabel = class(TLabel)

Private
{ Private declarations }
FAngle : Integer; {Add to the OjectInspector!}
FLayout : TTextLayout; {Remove from ObjectInspector!}
FAlignment : TAlignment; {Remove from ObjectInspector!}
FWordWrap : Boolean; {Remove from ObjectInspector!}

{Strange effects occures when AutoSize = TRUE and
Align = alClient! So I removed the Align property}
FAlign : Integer; {Remove from ObjectInspector!}

{Internal procedures}
Procedure DrawLabelText(Flags : Word); {Label text}
Procedure SetAngle(Value : Integer); {Rotation of label}

Protected
{ Protected declarations }
Procedure Paint; override; {Drawing of the label}

Public
{ Public declarations }
constructor Create(AOwner : TComponent); override;

Published
{ Published declarations }

{Inherited anyway
Property Color;
Property Font;
Property Color;
Property Cursor;
Property DragCursor;
Property DragMode;
Property Enabled;
Property Hint;
Property ParentColor;
Property ParentFont;
Property Font;
Property ShowHint; }

{Skip Layout, WordWrap, Align and Alignment from
the ObjectInspector by making them read-only}
Property Align : Integer read FAlign;
Property WordWrap : Boolean read FWordWrap;
Property Layout : TTextLayout read FLayout;
Property Alignment : TAlignment read FAlignment;

{The new propertie for ALabel!}
Property Angle : Integer read FAngle write SetAngle
default 0;
{Setting the default for Angle doesn't work here...}
End;

Procedure Register; {Hello!}

Implementation

{----------------------------------------------------------------------}
Procedure TALabel.SetAngle(Value : Integer);

Begin
If Value <> FAngle then
Begin
{Set angle between 0 and 3599}
If Value < 0 then
Repeat
Value := Value + 3600;
Until Value >= 0;
If Value >= 3600 then
Repeat
Value := Value - 3600;
Until Value < 3600;
FAngle := Value; {Update the angle in the ObjectInspector}
Invalidate; {Update label}
End;
End;
{----------------------------------------------------------------------}
Procedure TALabel.DrawLabelText(Flags : Word);

Var
Text : Array[0..255] of Char;
LogFont,NewLogFont : TLogFont;
NewFont,OldFont : HFont;
L : Byte;
MRect : TRect;
TextX,TextY : Integer;
Phi : Real;

Begin
{Delphi automatically fills the text: 'ALabel#' in here.
# is a number starting from '1'}
GetTextBuf(Text,SizeOf(Text));

If (Flags and DT_CALCRECT <> 0) and
((Text[0] = #0) or ShowAccelChar and
(Text[0] = '&amp;') and (Text[1] = #0)) then
StrCopy(Text,' ');
{I assume that this statement corrects the length of
the string if an accelerator character is used, but
I don't ask me how it works}

If not ShowAccelChar then
Flags := Flags or DT_NOPREFIX;
{Don't ask me what DT_NOPREFIX means}

L := StrLen(Text);

{Create the rotated font}
Canvas.Font := Font;
GetObject(Font.Handle,SizeOf(TLogFont),@LogFont);
NewLogFont := LogFont;

MRect := ClientRect;
NewLogFont.lfEscapement := FAngle; {Set rotation}
NewFont := CreateFontIndirect(NewLogFont);
OldFont := SelectObject(Canvas.Font.Handle,NewFont);
DeleteObject(OldFont);
Canvas.Font.Handle := NewFont; {The new font is ready!}

Phi := FAngle * Pi / 1800; {DegToRad for Pascal}

{If AutoSize = FALSE then calculate where the text
should begin in the label}
If AutoSize = False then
Begin
TextX := Trunc(0.5 * ClientWidth -
0.5 * Canvas.TextWidth(Text) * cos(Phi) -
0.5 * Canvas.TextHeight(Text) * sin(Phi));
TextY := Trunc(0.5 * ClientHeight -
0.5 * Canvas.TextHeight(Text) * cos(Phi) +
0.5 * Canvas.TextWidth(Text) * sin(Phi));
End;

{If AutoSize = TRUE then calculate the labelsize and
were the text should begin in the label}
If AutoSize = True then
Begin
{Calculate optimum labelsize first}
ClientWidth := 4 + Trunc(Canvas.TextWidth(Text) * Abs(cos(Phi)) +
Canvas.TextHeight(Text)*Abs(sin(Phi)));
ClientHeight := 4 + Trunc(Canvas.TextHeight(Text) * Abs(cos(Phi)) +
Canvas.TextWidth(Text) * Abs(sin(Phi)));

{Calculate X offset of text}
TextX := 2;
If (FAngle > 900) and (FAngle < 2700) then
TextX := TextX + Trunc( Canvas.TextWidth(Text) * Abs(cos(Phi)) );
If (FAngle > 1800) then
TextX := TextX + Trunc(Canvas.TextHeight(Text) * Abs(sin(Phi)) );

{Calculate Y offset of text}
TextY := 2;

 
多谢free_knight,
不过这是个旋转的Label,我需要的是一个能旋转图形控件的通用旋转控件。
这是很少见。
 
太麻烦,就用LMD组件包中的吧,里面不但有这个东西,而且还有显示时间、系统信息的
Lable,实在很全面,也非常容易使用。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部