I需要限制TMemo組件中每行的行數和字符數。如何限制TMemo組件中的行和字符的行數
例如我喜歡做這樣的事情:
Memo1.MaxLines:=20;
Memo1.CharsByLine:=80;
我怎麼可以在Delphi中做到這一點?
I需要限制TMemo組件中每行的行數和字符數。如何限制TMemo組件中的行和字符的行數
例如我喜歡做這樣的事情:
Memo1.MaxLines:=20;
Memo1.CharsByLine:=80;
我怎麼可以在Delphi中做到這一點?
有一些令人不快的問題......比如,如果將memo1.lines.text值分配給大塊文本,會發生什麼情況?你想要發生錯誤,數據被迫降低到80個字符/行...
這聽起來像你需要一個文字處理器控制,而不是TMemo。退房http://www.TRichView.com或http://www.wpcubed.com/
我不相信有一個簡單的方法來做到這一點,我已經設置的OnKeyPress事件發生前試圖限制它(我不知道,如果它處理文本粘貼)
procedure AddressMemoOnKeyPressEvent(Sender: TObject; var Key: Char);
var
i, lineCount: Integer;
begin
with Sender as TMemo do
begin
if (Key <> #13) and (Key <> #8) and (Length(Lines[CaretPos.Y]) >= MAX_CHARS_PER_LINE_IN_MEMO) then
Key := #0;
lineCount := 0;
for i := 1 to Length(TMemo(Sender).Lines.Text) do
begin
if (TMemo(Sender).Lines.Text[i] = #13) then
Inc(lineCount);
end;
if (Key = #13) AND (Key <> #8) AND (lineCount >= MAX_LINES_PER_MEMO - 1) then
Key := #0;
// if we got past the last line, no key can be entered...
if (CaretPos.Y >= MAX_LINES_PER_MEMO) then
Key := #0;
end;
end;