新鲜、有趣,互联生活。令狐葱。

2006/11/06

BCB中使用EhLib控件的几个技巧

说明:最近在使用BCB做项目,所以适当的学习了一些其上的控件,在找一些资料的时候感觉困难不小,所以好不容易找出来的东西也希望能解某些人的燃眉之急。
 
//**********************************
//* 点击columns 的title 实现自动排序
//* 针对EhLib 的DbGridEh
//**********************************
void __fastcall TForm_LineInfo::DBGridEh1TitleClick(TColumnEh *Column)
{
    
//TADOQuery * query =  DBGridEh1->DataSource->DataSet;

    if(!query ->IsEmpty()){
        TBookmark SavePlace;
        SavePlace = query-> GetBookmark();
        if (query->Sort != Column->FieldName ){
            query->Sort = Column->FieldName;
        } else {
             query->Sort = Column->FieldName + "   DESC  ";
        }
        query->GotoBookmark( SavePlace);
        query->FreeBookmark(SavePlace);
   }
}
//**********************************
//* 让DBGrid自适应列宽
//* 针对EhLib 的DbGridEh
//**********************************
void AdjustDBGrid(TDBGridEh *DBGrid )
{
      for( int i = 0; i <= DBGrid->Columns->Count - 1; i++){
           DBGrid->Columns->Items[i]->Title->Alignment   =   taCenter;
          DBGrid ->Columns->Items[i]->Title->Font->Name   =   "宋体";
          DBGrid->Columns->Items[i]->Title->Font-> Size     =   10 ;
          DBGrid->Columns->Items[i]->Width = this->Canvas ->TextWidth(DBGrid->Columns->Items[i]->Title->Caption )   +   30 ;
      }
//for的结束
}
//**********************************
//* 随窗口变化调整控件位置
//* 当然也可以直接设置控件为Align属性为alClient
//**********************************
void __fastcall TForm_LineInfo::FormResize(TObject *Sender)
{
    int midLoc = Width / 2;
    TControl * ChildControl;
     for (int i = 0; i < this->ControlCount; i++) {
        
//遍历Controls数组,ControlCount是数组元素个数
        ChildControl = Controls[i];
        
//ChildControl->Left = midLoc-ChildControl->Width / 2;

        if (ChildControl == GroupBox1) {
            
//若控件是GroupBox,对其子控件进行操作
            int SubMidLoc = GroupBox1->Width / 2;
             for(int j = 0;j < GroupBox1->ControlCount; j++) {

            
//遍历GroupBox1的Controls数组。ControlCount是数组元素个数
            ChildControl = GroupBox1->Controls[j];
            ChildContro1->Left = SubMidLoc-ChildControl->Width / 2;
            }
        }
    }
}

没有评论: