画控件的几个函数

画控件的几个函数。主要使它们好看一点儿。 

代码: 
#ifndef DRAWCONTROLS_H 
#define DRAWCONTROLS_H 

#include <math.h> 
#include <Classes.hpp> 
#include <Controls.hpp> 
#include <StdCtrls.hpp> 
#include <Forms.hpp> 
#include <ComCtrls.hpp> 
#include <ExtCtrls.hpp> 
#include <Grids.hpp> 
#include <ImgList.hpp> 
#include <ToolWin.hpp> 
#include <DBGrids.hpp> 
#include <jpeg.hpp> 
#include <ADODB.hpp> 
#include <DB.hpp> 
#include <Buttons.hpp> 
#include <Graphics.hpp> 
#include <StdIO.h> 
#include <CheckLst.hpp> 
//--------------------------------------------------------------------------- 
void DrawComboBox(TWinControl *Control,int Index, TRect &Rect, TOwnerDrawState State) 

    if(!(Index%2)) 
        ((TComboBox*)Control)->Canvas->Brush->Color = clWhite; 
    else 
        ((TComboBox*)Control)->Canvas->Brush->Color = TColor(RGB(240,240,240)); 

    ((TComboBox*)Control)->Canvas->FillRect(Rect); 

    if(State.Contains(odSelected)) 
    { 
        ((TComboBox*)Control)->Canvas->Font->Color = clBlue; 
    } 
    else 
    { 
        ((TComboBox*)Control)->Canvas->Pen->Color = clWindowText; 
    } 
    DrawText(((TComboBox*)Control)->Canvas->Handle, 
             ((TComboBox*)Control)->Items->Strings[Index].c_str(), 
             -1, 
             (RECT*)&(TRect(Rect.left+2,Rect.top,Rect.right-2,Rect.bottom)), 
             DT_SINGLELINE | DT_VCENTER |DT_LEFT | DT_WORDBREAK); 

//--------------------------------------------------------------------------- 
void DrawStringGrid(TObject *Sender, int ACol,int ARow, TRect &Rect, TGridDrawState State) 

    String strText = ((TStringGrid*)Sender)->Cells[ACol][ARow]; 
    int x=0,y=0; 
    x=Rect.left + (Rect.Width() - ((TStringGrid*)Sender)->Canvas->TextWidth(strText))/2; //水平居中 
    y=Rect.top + (Rect.Height() - ((TStringGrid*)Sender)->Canvas->TextHeight(strText))/2;//水平居中 
    if(ARow%2) 
        if(State.Contains(gdFixed)) 
            ((TStringGrid*)Sender)->Canvas->Brush->Color = TColor(RGB(245,245,245)); 
        else 
            ((TStringGrid*)Sender)->Canvas->Brush->Color = TColor(RGB(255,255,255)); 
    else 
        if(State.Contains(gdFixed)) 
            ((TStringGrid*)Sender)->Canvas->Brush->Color = TColor(RGB(235,235,235)); 
        else 
            ((TStringGrid*)Sender)->Canvas->Brush->Color = TColor(RGB(245,245,245)); 
    if(State.Contains(gdFixed)) 
    { 
        //((TStringGrid*)Sender)->Canvas->Brush->Color = TColor(RGB(220,220,220)); 
        ((TStringGrid*)Sender)->Canvas->Font->Color = clNavy; 
    } 
    else 
    { 
        ((TStringGrid*)Sender)->Canvas->Font->Color = clBlack; 
    } 

    ((TStringGrid*)Sender)->Canvas->FillRect(Rect); 

    if(State.Contains(gdFocused)) 
    { 
        ((TStringGrid*)Sender)->Canvas->Font->Color = clBlue; 
    } 
    
    DrawText(((TStringGrid*)Sender)->Canvas->Handle, 
             strText.c_str(), 
             -1, 
             (RECT*)&(TRect(Rect.left+2,Rect.top,Rect.right-2,Rect.bottom)), 
             DT_SINGLELINE | DT_VCENTER |DT_LEFT | DT_WORDBREAK); 

//--------------------------------------------------------------------------- 
void DrawCustomListBox(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) 

    if(State.Contains(odFocused) || State.Contains(odSelected)) //选中行 
    { 
        dynamic_cast<TCustomListBox*>(Control)->Canvas->Brush->Color = clSkyBlue; 
    } 
    else 
    { 
        if(Index%2) //偶数行 
            dynamic_cast<TCustomListBox*>(Control)->Canvas->Brush->Color = (TColor)(RGB(240,240,240)); 
        else 
            dynamic_cast<TCustomListBox*>(Control)->Canvas->Brush->Color = (TColor)(RGB(255,255,255)); 
    } 
    dynamic_cast<TCustomListBox*>(Control)->Canvas->FillRect(Rect); 
    
    dynamic_cast<TCustomListBox*>(Control)->Canvas->Font->Color = clBlack; 

    String strText = dynamic_cast<TCustomListBox*>(Control)->Items->Strings[Index]; 
    DrawText(dynamic_cast<TCustomListBox*>(Control)->Canvas->Handle, 
             strText.c_str(), 
             -1, 
             (RECT*)&(TRect(Rect.left+2,Rect.top,Rect.right-2,Rect.bottom)), 
             DT_SINGLELINE | DT_VCENTER |DT_LEFT | DT_WORDBREAK); 

//--------------------------------------------------------------------------- 
#endif  
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值