- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 TRichEdit 来编辑文本。我打开了 WordWrap,它会自动在控件边缘自动换行文本,这样就不会出现滚动条。 RichEdit 宽度设置为适合 80 列。
只要单词之间偶尔有空格,WordWrap 就能很好地模拟这种行为。但是,如果您有一个非常长的单词,RichEdit 换行会自动中断它,而 WordWrap 不会!
如果我现在想访问这些换行,我可以通过 RichEdit.Lines.Text
获取它,它会自动将 CRLF 放在第 80 列。如果我使用 RichEdit.Text,我会得到没有任何内容的原始文本CRLF 适用于 WordWrap。
在自定义函数中完成这项任务并不简单,因为我已经尝试过,而且它不是一个小函数,但是是否有办法使用 TRichEdit 的包装函数?我有一个想法来创建隐藏的 RichEdit,但对于这项任务来说,这似乎很愚蠢,因为我必须计算它的宽度才能进行自动换行 - 我认为毫无意义。
问题 - 有没有办法强制 WordWrap 剪切无法换行的长单词?因此,如果一个单词的长度为 170 个字符,它将被包装成 3 行 80 + 80 + 10,但还要处理之前的单词以填充前后行?
最佳答案
试穿一下尺码:
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
const
MAX_LENGTH = 80;
var
nLineCount: integer;
sCurrentLine: string;
begin
for nLineCount := 0 to RichEdit1.Lines.Count - 1 do
begin
// no space in this line
if (pos(' ',RichEdit1.Lines.Strings[nLineCount]) = 0) then
begin
if (length(RichEdit1.Lines.Strings[nLineCount]) > MAX_LENGTH) then
begin
// hold the whole line
sCurrentLine := RichEdit1.Lines.Strings[nLineCount];
// the current line, make the max value
RichEdit1.Lines.Strings[nLineCount] := copy(sCurrentLine,1,MAX_LENGTH);
// build the next line
RichEdit1.Lines.Add(
copy(sCurrentLine,MAX_LENGTH + 1,1));
end;
end;
end;
end;
关于Delphi - 如何让 WrapText 表现得像 RichEdit.Lines.Text?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8936725/
我有一个包含源代码的 TRichEdit 控件。我想设置单行的背景颜色。 我知道如何设置文本 颜色,但是否也可以设置背景颜色?我不是在谈论整个控件的整个背景颜色,我只是在谈论如何更改一行。 我真的必须
我正在将文本从delphi TRichedit 控件输出到打印机。有一个背景图像,所以我使用具有此逻辑的 EM_FORMATRANGE ... myrichedit.Perform(EM_FORMAT
我创建一个新应用程序,放置 TRichedit 并将 PlainText 属性设置为 true。然后,我运行该应用程序并将一些富格式文本粘贴到 RichEdit 中。 我希望它显示为纯文本,但它会显示
添加一行后,我需要将 RichEdit 滚动到最后。我有一个单独的形式的 RichEdit,我根本不想获得焦点。我尝试了经常建议的解决方案: RichEdit.Lines.Add(someText);
(如果您能更好地理解和定义我的问题,请有人编辑标题。) 我遇到的问题是 RichEdit 的样式格式“恢复”回默认的“无”又名 [],然后返回到我设置的任何内容,粗体或斜体示例。 问题所在 - 我认为
RichEdit 控件在成为其他控件的父控件时停止绘制文本。 这是一个功能还是一个错误?是否可以使 RichEdit 成为其他控件的父控件? 查看下一个应用: -- Form1.dfm --- obj
我希望 RichEdit 处理超链接,因此我按照以下说明进行操作:http://delphi.about.com/od/vclusing/l/aa111803a.htm 以下是我对代码所做的更改: i
当我使用多个 RichEdit 控件时,我的行为非常奇怪: LoadLibrary("Msftedit.dll"); RichEdit = CreateWindow("RICHEDIT50W", ""
我想向 RichEdit 控件添加彩色文本行。但我面临的问题是颜色变化不仅限于我选择的文本。我所做的是: 获取当前光标位置 -> 插入文本 -> 获取光标位置 -> 选择范围 -> 为其着色 -> 取
我需要你的帮助!所以,我正在创建一个带有语法高亮器的 RichEdit,我是这样做的: SendMessage(hWin, WM_SETREDRAW, false, 0);
有人知道是否有类似 Memo/RichEdit 的东西吗?需求:对行进行编号,从流中加载大文件(超过 5 MB)。 最佳答案 Developer Express有一套广泛的 VCL 组件,其中包括一个
如何在 RichEdit 中将某一特定行加粗? 最佳答案 丰富的编辑控件中的格式设置如下: 选择要应用格式的文本。 将该格式应用于所选内容。 事情是这样的: RichEdit1.SelStart :=
我有一个 Richedit,允许我的用户格式化和查看我的应用程序中显示的错误消息。 我现在需要能够仅将文本(无格式)导出到他们的故障单系统使用的另一个数据库。 我已经尝试了所有我能想到的纯文本组合,但
我以前从来不需要使用 TRichEdit,一直使用 TMemo。 当我添加 TMemo 等文本时,我希望 RichEdit 自动滚动到末尾。看看添加一些数据后的样子: 如您所见,滚动条保留在顶部,但我
我在计算 Richedit (Delphi XE) 中的字符数时遇到问题。对于每一个新行,我都会多得到两个字符,但在文本中它们不存在。 示例:这里有 15 个字符,但由于换行,richedit 给出了
我试图在 RichEdit 中保存然后恢复垂直滚动位置。 存储滚动位置的全局变量: SI: TScrollInfo; 此代码保存滚动位置: FillChar( SI, SizeOf(SI), #0 )
Delphi 中的大多数 TWinControl 后代都有一个重写方法 CreateParams 来定义它的子类,例如:'EDIT'、'COMBOBOX'、'BUTTON'、'RICHEDIT' 等。
如果您在 Richedit 中加载一些文本,然后单击鼠标左键 + 移动鼠标滚轮,文本将放大或缩小,而不会丢失文本大小格式。 是否有一种简单的方法可以通过几行代码来实现此功能(放大/缩小)? 谢谢 射线
我试图在 RichEdit 中保存然后恢复垂直滚动位置。 存储滚动位置的全局变量: SI: TScrollInfo; 此代码保存滚动位置: FillChar( SI, SizeOf(SI), #0 )
我有一个 TRichEdit。当我选择一些文本并单击另一个元素时,所选文本的选择消失。有没有办法保持这个选择,当 TRichEdit 失去它的焦点时?谢谢! 最佳答案 TRichEdit 有一个属性H
我是一名优秀的程序员,十分优秀!