画控件的几个函数

106 阅读1分钟

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

代码: 
#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