StringGrid 列的显示位置要求文字靠左 数字靠右(50)

  • 主题发起人 主题发起人 fanwendou
  • 开始时间 开始时间
F

fanwendou

Unregistered / Unconfirmed
GUEST, unregistred user!
如题:StringGrid 列的显示位置要求文字靠左数字靠右怎么实现??
 
自己画,OnCellDraw中写,使用TextOut显示位置
 
smlabc贴一下你的代码
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var nLeft,nTop : Integer;begin if gdFocused in state then begin Rect := StringGrid1.CellRect(ACol, ARow); nLeft := stringGrid1.Left; nTop := stringGrid1.top; Rect.Top := Rect.Top+ nTop; Rect.Left := Rect.Left + nLeft; // InflateRect(Rect, nLeft, nTop); ComboBox1.SetBounds(Rect.Left+stringGrid1.Left+2,Rect.Top+StringGrid1.Top+2, StringGrid1.ColWidths[ACol] , StringGrid1.RowHeights[ARow]) ; ComboBox1.Visible:=true; end;end;
 
ComboBox1 从何说起?
 
procedure TCDMAOptParamView.SgSystemDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var X, Y: Integer; s: string;begin with TStringGrid(Sender) do begin s := Cells[ACol, ARow]; if TryStrToInt(s, X) then begin // 右 if (Rect.Right - Rect.Left) + 2 > Canvas.TextWidth(s) + 2 then X := Rect.Left + ((Rect.Right - Rect.Left) - Canvas.TextWidth(s)) + 2 else X := Rect.Left + 2; Y := (Rect.Bottom + Rect.Top - Canvas.TextHeight(s)) div 2; Canvas.TextRect(Rect, X, Y, s); // 或者用 // DrawText(Canvas.Handle, PChar(s), Length(s), Rect, DT_CENTER or DT_SINGLELINE or DT_VCENTER); //文字居中 end else begin // 左 X := Rect.Left + 2; Y := (Rect.Bottom + Rect.Top - Canvas.TextHeight(s)) div 2; Canvas.TextRect(Rect, X, Y, s); end; end;end;
 
多人接受答案了。
 
后退
顶部