国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

ListBox自畫的另一種效果

2019-11-17 05:24:48
字體:
供稿:網(wǎng)友

  本文代碼簡單實現(xiàn)了類似CnPack中的一個界面效果,利用TListBox的自畫。
演示圖片:
/Article/UploadFiles/200601/20060103023924211.gif
//---------------------------------------------------------------------------
// ListBox自畫的另一種效果
// by ccrun(老妖)
// info ccrun.com
//---------------------------------------------------------------------------
#include <vcl.h>
#PRagma hdrstop

#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
    // ListBox的風(fēng)格,要自畫必須選lbOwnerDrawFixed和lbOwnerDrawVariable
    lbxMain->Style = lbOwnerDrawFixed;
    // 去掉ListBox的邊框,可有可無
    lbxMain->Ctl3D = false;
    // ListBox的每一項的高度
    lbxMain->ItemHeight = 50;
    pStrList = new TStringList;
    // 往ListBox中添加些數(shù)據(jù)
    for(int i=0; i<10; i++)
    {
        lbxMain->Items->Add("ListBox Items of " + String(i));
        pStrList->Add("Second of " + String(i) + String((char)0x03) + "Third of " + String(i));
    }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::lbxMainDrawItem(TWinControl *Control, int Index,
      TRect &Rect, TOwnerDrawState State)
{
    // 填充的背景顏色
    lbxMain->Canvas->Brush->Color = clWhite;
    // 文字顏色
    lbxMain->Canvas->Font->Color = clBlack;
    // 填充背景
    lbxMain->Canvas->FillRect (Rect) ;
    // 圓角矩形的背景顏色
    lbxMain->Canvas->Brush->Color = TColor(0x00FFF7F7);
    // 圓角矩形的邊框顏色
    lbxMain->Canvas->Pen->Color = TColor(0x00131315);
    // 畫出圓角矩形
    lbxMain->Canvas->RoundRect(Rect.Left + 3, Rect.Top + 3,
            Rect.Right - 2, Rect.Bottom - 2, 8, 8);
    // 以不同的寬度和高度再畫一次,實現(xiàn)立體效果
    lbxMain->Canvas->RoundRect(Rect.Left + 3, Rect.Top + 3,
            Rect.Right - 3, Rect.Bottom - 3, 5, 5);
    // 假如是當前選中項
    if(State.Contains(odSelected))
    {
        // 選中項的背景顏色
        lbxMain->Canvas->Brush->Color = TColor(0x00FFB2B5);
        // 以不同的背景色畫出選中項的圓角矩形
        lbxMain->Canvas->RoundRect(Rect.Left + 3, Rect.Top + 3,
                Rect.Right - 3, Rect.Bottom - 3, 5, 5);
        // 選中項的文字顏色
        lbxMain->Canvas->Font->Color = clBlue;
        // 假如當前項擁有焦點
        if(State.Contains(odFocused))
            // 重畫焦點虛框,實際上就是擦除了原先的焦點虛框
            // 我看到CnPack的設(shè)置中好象沒有去除那個框. ccrun注
            ::DrawFocusRect(lbxMain->Canvas->Handle, &Rect);
    }
    // 畫出圖標
    ImageList1->Draw(lbxMain->Canvas, Rect.Left + 7,
            Rect.top + (lbxMain->ItemHeight - ImageList1->Height)/2, Index, true);
    // Item的第一行文字
    lbxMain->Canvas->TextOutA(Rect.Left + 32 + 10, Rect.Top + 4,
            lbxMain->Items->Strings[Index]);
    String strTemp = pStrList->Strings[Index];
    // Item的第二行文字
    lbxMain->Canvas->TextOutA(Rect.Left + 32 + 10, Rect.Top + 18,
            strTemp.SubString(1, strTemp.Pos((char)0x03) - 1).c_str());
    // Item的第三行文字
    lbxMain->Canvas->TextOutA(Rect.Left + 32 + 10, Rect.Top + 32,
            strTemp.SubString(strTemp.Pos((char)0x03) + 1, strTemp.Length()).c_str());
}
//---------------------------------------------------------------------------
// 點擊ListBox以后顯示點擊的項目
void __fastcall TMainForm::lbxMainClick(TObject *Sender)
{
    pnlStatusBar->Caption = " " + lbxMain->Items->Strings[lbxMain->ItemIndex];
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormShow(TObject *Sender)
{
    lbxMain->ItemIndex = 0;
    lbxMain->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
    delete pStrList;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::lbxMainDblClick(TObject *Sender)
{
    TEditForm *p = new TEditForm(MainForm);
    p->edtFirst->Text = lbxMain->Items->Strings[lbxMain->ItemIndex];
    String strTemp = pStrList->Strings[lbxMain->ItemIndex];
    p->edtSecond->Text = strTemp.SubString(1, strTemp.Pos((char)0x03) - 1);
    p->edtThird->Text = strTemp.SubString(strTemp.Pos((char)0x03) + 1, strTemp.Length());
    p->pnlTitle->Caption = " 當前ListBox選中項:" + String(lbxMain->ItemIndex);
    p->pnlTitle->Tag = lbxMain->ItemIndex;
    p->Left = Left + (Width - p->Width) / 2;
    p->Top = Top + (Height - p->Height) / 2;
    p->ShowModal();
    delete p;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::pnlTitleMouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    // 移動沒有標題欄的窗體
    Refresh();
    if(Button == mbLeft)
    {
        ReleaseCapture();
        Perform(WM_SYSCOMMAND, 0xF017, 0);
    }    
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BTnMenUCloseClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btnMenuUpDownClick(TObject *Sender)
{
    if(btnMenuUpDown->Caption == "6")
    {
        // 還原窗體
        btnMenuUpDown->Caption = "5";
        Height = 310;
    }
    else
    {
        // 上卷窗體
        btnMenuUpDown->Caption = "6";
        Height = 25;
    }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::imgLogoClick(TObject *Sender)
{
    // 打開 C++Builder研究 網(wǎng)站
    ShellExecute(Handle, NULL, "http://www.ccrun.com",
            NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 达拉特旗| 长兴县| 都匀市| 德令哈市| 河池市| 额尔古纳市| 灵丘县| 六枝特区| 双江| 饶阳县| 阆中市| 东源县| 韶山市| 莱州市| 永清县| 沅江市| 福安市| 布尔津县| 南江县| 昌乐县| 孝感市| 赫章县| 崇礼县| 分宜县| 英德市| 封开县| 资中县| 汽车| 松桃| 通州区| 禄丰县| 全椒县| 新巴尔虎右旗| 五大连池市| 西盟| 石嘴山市| 莱芜市| 垫江县| 民权县| 莱芜市| 三穗县|