小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

delphi stringgrid單列和所有列自動列寬

 ZLM_圖書館 2014-02-28

function GetColMaxDataLength(ASGrid: TStringGrid; ACol, AStartRow: Integer): Integer;
 //三個自定義函數(shù)和過程放在implementation 后面
 //----------------------------------------------------------------------------//
//取得某一列數(shù)據(jù)的最大長度
//----------------------------------------------------------------------------//
var
   ColIndex, RowIndex: Integer;
   MaxColLength: Integer; //列數(shù)據(jù)的最大長度
begin
   MaxColLength := 0;
   with ASGrid do
   begin
     //取得列數(shù)據(jù)的最大長度
     for RowIndex := AStartRow to RowCount - 1 do
     begin
       if length(Cells[ACol, RowIndex]) > MaxColLength then
       begin
         MaxColLength:= length(Cells[ACol, RowIndex]);
       end;
     end;
   end;
   result := MaxColLength;
end;
//----------------------------------------------------------------------------//
//根據(jù)數(shù)據(jù)長度自動設(shè)置指定列的列寬
//----------------------------------------------------------------------------//
procedure SetOneColWidth(ASGrid: TStringGrid; ACol: Integer);
var
   OneCharPixel: Integer; //一個字符所占的像素數(shù)
   RightSpaceWidth: Integer; //右邊距空隙
begin
   RightSpaceWidth := 3; //設(shè)置為3達(dá)到和左邊距一致的效果
   OneCharPixel := 6; //6對應(yīng)9號字[*此處最好寫成一個根據(jù)字號獲得像素值的函數(shù)*]
   ASGrid.ColWidths[ACol] := GetColMaxDataLength(ASGrid, ACol, 0) * OneCharPixel
   + RightSpaceWidth;
end;

//----------------------------------------------------------------------------//
//根據(jù)數(shù)據(jù)長度自動設(shè)置全部列的列寬
//----------------------------------------------------------------------------//
procedure SetAllColWidth(ASGrid: TStringGrid);
var
   ColIndex: Integer; //需要設(shè)置的列
begin
   for ColIndex := 0 to ASGrid.ColCount - 1 do
   begin
     SetOneColWidth(ASGrid, ColIndex);
   end;
end;

procedure TForm1.BitBtn10Click(Sender: TObject);
var i:Integer;
begin      //stringgrid設(shè)置單獨列自動列寬
 i:=StrToInt(Trim(Edit1.Text));
//ShowMessage(IntToStr(GetColMaxDataLength(StringGrid1,i,0)));  //調(diào)用implementation下面定義的函數(shù)
 SetOneColWidth(StringGrid1,i)
end;

procedure TForm1.BitBtn11Click(Sender: TObject);
begin   //stringgrid全部自動列寬
SetAllColWidth(StringGrid1);
end;

------------------------------------------------------------

procedure TForm1.BitBtn10Click(Sender: TObject);
var i:Integer;
begin      //stringgrid設(shè)置單獨列自動列寬
 i:=StrToInt(Trim(Edit1.Text));
//ShowMessage(IntToStr(GetColMaxDataLength(StringGrid1,i,0)));  //調(diào)用implementation下面定義的函數(shù)
 SetOneColWidth(StringGrid1,i)
end;

procedure TForm1.BitBtn11Click(Sender: TObject);
begin   //stringgrid全部自動列寬
SetAllColWidth(StringGrid1);
end;

end.

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多