簡體   English   中英

如何使 TImage 移動(如 DVD 徽標)

[英]How do I make a TImage move (like a DVD logo)

我試圖讓 TImage 像 DVD 徽標一樣移動,但 TImage 沒有移動。

這是我使用的代碼:

void __fastcall TForm1::DVDLogoTimer(TObject *Sender)
{
    image->Left+=xPos; image->Top+=yPos;

    if (image->Left <= invisibleHelperObject->Left) xPos=-xPos;
    if (image->Top <= invisibleHelperObject->Top) yPos=-yPos;
    if (image->Left+image->Width >= invisibleHelperObject->Width) xPos=-xPos;
    if (image->Top+image->Height >= invisibleHelperObject->Height) yPos=-yPos;

    Label1->Caption = IntToStr(xPos) + " | " + IntToStr(yPos);
}

(X 和 Y 變量甚至沒有變化(保持在 0))

在 C++Builder 6(以及現代版本中的“經典”Borland 編譯器)中,您不能將+=之類的復合運算符與屬性一起使用。 這樣做會將屬性值入臨時值,然后修改臨時值,但不會臨時值分配回屬性。 在屬性上使用復合運算符需要現代的基於 Clang 的編譯器:

Clang 增強型 C++ 編譯器與上一代 C++ 編譯器之間的差異,__property:復合和鏈式賦值

Clang 增強型 C++ 編譯器支持 __property 的復合賦值,而__property支持。

關鍵字__property的對象不像字段或成員。 它們應該用於簡單的作業

盡管 BCC32 和 RAD Studio Clang 增強型 C++ 編譯器都允許在復合賦值中使用__property ,例如:

Form1->Caption += DateToStr(Now());

BCC32 只調用 getter,而不是 setter。 因此,我們建議您在針對多個平台時避免此類構造。

這些編譯器都不支持在鏈式賦值中使用__property ,如下所示:

Button2->Caption = Button1->Caption = DateToStr(Now()); // Error

因此,在您的情況下,當您調用image->Left += xPos; 例如,它的行為就好像你已經寫了這個:

//image->Left += xPos;
int temp = image->Left;
temp += xPos;

因此,您需要分別使用+=運算符,例如:

void __fastcall TForm1::DVDLogoTimer(TObject *Sender)
{
    image->Left = image->Left + xPos;
    image->Top = image->Top + yPos;
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM