irvinehing
初階會員
![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:77 回覆:79 積分:31 註冊:2003-11-12
發送簡訊給我
|
如題,小弟希望在Shape元件中變化不同的文字。
請問可以做到嗎?
|
m8815010
版主
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:99 回覆:372 積分:289 註冊:2003-11-13
發送簡訊給我
|
引言:
如題,小弟希望在Shape元件中變化不同的文字。
請問可以做到嗎?
irvinehing你好 : 查了一下 >! <>> 就不解釋了!所以事件就變得可行了! class="code">
Unit1.h
~~
class TForm1 : public TForm
{
__published: // IDE-managed Components
TShape *Shape1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
TWndMethod OldShapeWndProc; //add this line
void __fastcall ShapeWndProc(TMessage& Message); //add this line
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
Unit1.cpp
~~
TForm1 *Form1; AnsiString OutputString="Test"; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
OldShapeWndProc=Shape1->WindowProc;
Shape1->WindowProc=ShapeWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ShapeWndProc(TMessage& Message)
{
OldShapeWndProc(Message); if (Message.Msg==WM_PAINT) {
this->Canvas->Brush->Color=Shape1->Brush->Color;
this->Canvas->TextOutA(Shape1->Left 1,Shape1->Top 1,OutputString);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
this->Canvas->Brush->Color=Shape1->Brush->Color;
this->Canvas->TextOutA(Shape1->Left 50,Shape1->Top 50,OutputString);
}
按下範例中的button1就可以繪上字串了,只是這樣的繪法是沒有自動重繪的能力的,真正要有重繪能力的寫法就是其它的那些程式碼達成的! 沒有圖例,但範例程式是ok,就請自行try一下了 !
|
irvinehing
初階會員
![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:77 回覆:79 積分:31 註冊:2003-11-12
發送簡訊給我
|
m8815010你好。
看了你的恢复觉得这样做好复杂哦。
我还是用最简单的做法,Label+Shape来做。
Label1->Top = 16;
Label1->Left = 16;
Label1->Width = 50;
Label1->Height = 50;
Label1->Alignment = taCenter;
Label1->Layout = tlCenter; Shape1->Top = 16;
Shape1->Left = 16;
Shape1->Width = 50;
Shape1->Height = 50;
总之,谢谢你的指点。
|