仿360工具栏

来源:互联网 发布:福州理工学院知乎 编辑:程序博客网 时间:2024/05/22 03:52
继承TWinControl类,用GDI+画背景和图标。为什么要用的GDI+,而不用GDI或TCanvs呢?因为当鼠标在工具栏上滑动时,如果经过某图标,需要产生一个动态焦点。如果要画出这种效果的话,我的设想是:先在图标上铺上一个浅透明层,再在图标两侧分别画上深色的渐变阴影。这样,立体的感觉就有了。GDI+有相应的绘图函数,相对方便。



在窗口中响应点击事件如下:

#define STRICT#include <vcl.h>#pragma hdrstop#include "Unit1.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma link "GraphicButtonControl1"#pragma resource "*.dfm"TForm1 *Form1;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)        : TForm(Owner){    AnsiString uiPath = ExtractFilePath(Application->ExeName)+"UI1\\";//获取当前路径    GraphicButtonControl11->UIPicturePath->UIPath = uiPath;}//---------------------------------------------------------------------------void __fastcall TForm1::GraphicButtonControl11Click(TObject *Sender){   if(GraphicButtonControl11->picNo <= GraphicButtonControl11->PicCount)   Label1->Caption = "您点击了"+GraphicButtonControl11->FStrList->Strings[GraphicButtonControl11->picNo];}//---------------------------------------------------------------------------


0 0