代码之家  ›  专栏  ›  技术社区  ›  relayman357

在运行时更改TBitBtn标志符号

  •  1
  • relayman357  · 技术社区  · 6 年前

    我有一个VCL表单,上面有一个TBitBtn和一个包含两个位图的TImageList。在运行时,我运行以下代码行,将其中一个位图放到我的TBitBtn上:

    ImageList1->GetBitmap(1, BitBtn1->Glyph);
    

    这成功地将位图放到TBitBtn上。然后,我运行以下代码行来更改位图,但什么也没有发生:

    ImageList1->GetBitmap(0, BitBtn1->Glyph);
    

    两个位图都出现在imagelist(0和1)中。我可以交换代码行并证明imagelist没有任何错误。 Here is 一个老帖子,一个家伙似乎在德尔菲解决了这个问题。我想我必须先把字形清除一下,但我不知道C++中的用法。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Ken White    6 年前

    下面是一个使用它的方法的例子,使用 TBitmap TImageList 并在运行时将其放入glyph中。在这个例子中 TBitBtn->OnClick 事件处理程序。

    void __fastcall TForm1::btn1Click(TObject *Sender)
    {
        // FOdd is a bool variable defined in the form's private section.
        // It's just being used here as a toggle to flip between the images
        this->FOdd = !this->FOdd;
    
        TBitmap *bmp = new Graphics::TBitmap();
        try {
            bmp->SetSize(this->ImageList1->Width, this->ImageList1->Height);
            this->ImageList1->GetBitmap(int(FOdd), bmp);
            this->BitBtn1->Glyph->Assign(bmp);
        }
        __finally
        {
            delete bmp;
        }    
    }
    

    推荐文章