text超出了长度,如何在末尾加上省略号?(100分)

  • 主题发起人 主题发起人 lijun4183
  • 开始时间 开始时间
L

lijun4183

Unregistered / Unconfirmed
GUEST, unregistred user!
给定一段长度,当字符串的显示长度超过这段长度时,自动加上...,正好符合这段长度。<br>请问如何实现?
 
MAX_LEN:=20;<br>s:='123456789012345678901234567890';<br><br>if Length(s)&gt;MAX_LEN then<br>begin<br>&nbsp; s:=Copy(s,1,MAX_LEN-3);<br>&nbsp; s:=s+'...';<br>end;
 
用ehlib自动会加的
 
同意楼上的
 
用ehlib自动会加的????<br>请问什么是ehlib?<br><br>
 
ehlib是一个控件包,有许多网站都提供下载,听说很好用我下了还没用过
 
对,用ehlib吧,省劲儿!嘿嘿!
 
用DrawText API函数就可以了,加上 DT_END_ELLIPSIS 参数,具体看下面的函数说明:<br><br>The DrawText function draws formatted text in the specified rectangle. It formats the text according to the specified method (expanding tabs, justifying characters, breaking lines, and so forth). <br><br>int DrawText(<br><br>&nbsp; &nbsp; HDC hDC, // handle to device context <br>&nbsp; &nbsp; LPCTSTR lpString, // pointer to string to draw <br>&nbsp; &nbsp; int nCount, // string length, in characters <br>&nbsp; &nbsp; LPRECT lpRect, // pointer to structure with formatting dimensions &nbsp;<br>&nbsp; &nbsp; UINT uFormat // text-drawing flags <br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>hDC<br><br>Identifies the device context. <br><br>lpString<br><br>Points to the string to be drawn. If the nCount parameter is -1, the string must be null-terminated. <br><br>nCount<br><br>Specifies the number of characters in the string. If nCount is -1, then the lpString parameter is assumed to be a pointer to a null-terminated string and DrawText computes the character count automatically. <br><br>lpRect<br><br>Points to a RECT structure that contains the rectangle (in logical coordinates) in which the text is to be formatted.<br><br>uFormat<br><br>Specifies the method of formatting the text. It can be any combination of the following values: <br><br>Value Description<br>DT_BOTTOM Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.<br>DT_CALCRECT Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the lpRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.<br>DT_CENTER Centers text horizontally in the rectangle.<br>DT_EDITCONTROL Duplicates the text-displaying characteristics of a multiline edit control. Specifically, the average character width is calculated in the same manner as for an edit control, and the function does not display a partially visible last line.<br>DT_END_ELLIPSIS or DT_PATH_ELLIPSIS Replaces part of the given string with ellipses, if necessary, so that the result fits in the specified &nbsp;rectangle. The given string is not modified unless the DT_MODIFYSTRING flag is specified.You can specify DT_END_ELLIPSIS to replace characters at the end of the string, or DT_PATH_ELLIPSIS to replace characters in the middle of the string. If the string contains backslash (/) characters, DT_PATH_ELLIPSIS preserves as much as possible of the text after the last backslash.<br>DT_EXPANDTABS Expands tab characters. The default number of characters per tab is eight.<br>DT_EXTERNALLEADING Includes the font external leading in line height. Normally, external leading is not included in the height of a line of text.<br>DT_LEFT Aligns text to the left.<br>DT_MODIFYSTRING Modifies the given string to match the displayed text. This flag has no effect unless the DT_END_ELLIPSIS or DT_PATH_ELLIPSIS flag is specified.<br>DT_NOCLIP Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.<br>DT_NOPREFIX Turns off processing of prefix characters. Normally, DrawText interprets the mnemonic-prefix character &amp; as a directive to underscore the character that follows, and the mnemonic-prefix characters &amp;&amp; as a directive to print a single &amp;. By specifying DT_NOPREFIX, this processing is turned off.<br>DT_RIGHT Aligns text to the right.<br>DT_RTLREADING Layout in right to left reading order for bi-directional text when the font selected into the hdc is a Hebrew or Arabic font. The default reading order for all text is left to right.<br>DT_SINGLELINE Displays text on a single line only. Carriage returns and linefeeds do not break the line.<br>DT_TABSTOP Sets tab stops. Bits 15-8 (high-order byte of the low-order word) of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight.<br>DT_TOP Top-justifies text (single line only).<br>DT_VCENTER Centers text vertically (single line only).<br>DT_WORDBREAK Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the lpRect parameter. A carriage return-linefeed sequence also breaks the line.<br>&nbsp;<br><br>Note that the DT_CALCRECT, DT_EXTERNALLEADING, DT_INTERNAL, DT_NOCLIP, and DT_NOPREFIX values cannot be used with the DT_TABSTOP value. <br><br>&nbsp;<br><br>Return Values<br><br>If the function succeeds, the return value is the height of the text. <br><br>Remarks<br><br>The DrawText function uses the device context's selected font, text color, and background color to draw the text. Unless the DT_NOCLIP format is used, DrawText clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified. <br>If the selected font is too large for the specified rectangle, the DrawText function does not attempt to substitute a smaller font. <br>
 
多人接受答案了。
 
后退
顶部