是否可以确定dbEdit中的文本是否长于可见的文本? [英] Is it possible to determine if the text in a dbEdit is longer than what is visible?

查看:152
本文介绍了是否可以确定dbEdit中的文本是否长于可见的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些表单上,我有dbEdits有时不够宽,不能显示其字段可能包含的所有文本。对于他们,我有以下代码:

On some forms I have dbEdits that sometimes aren't wide enough to show all the text their fields may contain. For them I have the following code:

procedure Tgm12edLots.dbeLotNameMouseEnter(Sender: TObject);
begin
  with dbeLotName do begin
    ShowHint := True;
    Hint := Text;
  end;
end;

我想避免提示如果所有的文字都可见,但我不

I'd like to avoid the hint showing if all the text is visible, but I don't how to test for that condition.

感谢任何提示/建议!

推荐答案

我认为这应该工作...

I think this should work...

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;

这篇关于是否可以确定dbEdit中的文本是否长于可见的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆