在某些表单上,我有dbEdits,有时不够宽,无法显示其字段可能包含的所有文本.对于他们我有以下代码:
procedure Tgm12edLots.dbeLotNameMouseEnter(Sender: TObject); begin with dbeLotName do begin ShowHint := True; Hint := Text; end; end;
我想避免显示所有文本是否可见的提示,但我不知道如何测试该条件.
感谢您的任何提示/建议!
解决方法
我觉得这应该有用……
function CanShowAllText(Edit: TDBEdit):Boolean; var TextWidth:Integer; VisibleWidth: Integer; Bitmap: TBitmap; const //This could be worked out but without delphi I can't remember all that goes into it. BordersAndMarginsWidthEtc = 4; begin Bitmap := TBitmap.Create; try Bitmap.Canvas.Font.Assign(Edit.Font); TextWidth := Bitmap.Canvas.TextWidth(Edit.Text); VisibleWidth := Edit.Width - BordersAndMarginsWidthEtc; Result := TextWidth < VisibleWidth; finally Bitmap.Free; end; end;