F farmer Unregistered / Unconfirmed GUEST, unregistred user! 2001-08-15 #1 把Memo的WordWrap属性设为False,不让它自动换行。如何控制当输入的字符串长度达 到显示宽度时禁止继续输入,必须输入回车后另起一行?
W wang4762 Unregistered / Unconfirmed GUEST, unregistred user! 2001-08-15 #4 通过调用API确定MEMO控件中的当前行和列。 你可以调用WINDOWSAPI中的EM—LINEFROM?CHAR和EM—LINEINDEX函数来确定MEMO控件中的当前行和列,具体调用的过程见下面的过程。 varLineNum:longint; CharsBeforeLine:longint; begin LineNumΚSendMessage(Memo1.Handle,EM—LINEFROMCHAR,Memo1.SelStart,0); CharsBeforeLine:=SendMessage(Memo1.Handle,EM—LINEINDEX,LineNum,0); Label1.Caption:=′Line′+IntToStr(LineNum+1) Lab el2.Caption:=′Position′+IntToStr((Memo1.SelStart-CharsBeforeLine)+1); end;
通过调用API确定MEMO控件中的当前行和列。 你可以调用WINDOWSAPI中的EM—LINEFROM?CHAR和EM—LINEINDEX函数来确定MEMO控件中的当前行和列,具体调用的过程见下面的过程。 varLineNum:longint; CharsBeforeLine:longint; begin LineNumΚSendMessage(Memo1.Handle,EM—LINEFROMCHAR,Memo1.SelStart,0); CharsBeforeLine:=SendMessage(Memo1.Handle,EM—LINEINDEX,LineNum,0); Label1.Caption:=′Line′+IntToStr(LineNum+1) Lab el2.Caption:=′Position′+IntToStr((Memo1.SelStart-CharsBeforeLine)+1); end;
C caidaoli Unregistered / Unconfirmed GUEST, unregistred user! 2001-08-15 #5 procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char); var OldFont : TFont; LineNum:longint; begin LineNum := SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0); OldFont := Canvas.Font; try Canvas.Font := Memo1.Font; if Canvas.TextWidth(Memo1.Lines[LineNum])>= Memo1.Width then if Key <>#13 then Key :=#0; finally Canvas.Font := OldFont; end; end;
procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char); var OldFont : TFont; LineNum:longint; begin LineNum := SendMessage(Memo1.Handle,EM_LINEFROMCHAR,Memo1.SelStart,0); OldFont := Canvas.Font; try Canvas.Font := Memo1.Font; if Canvas.TextWidth(Memo1.Lines[LineNum])>= Memo1.Width then if Key <>#13 then Key :=#0; finally Canvas.Font := OldFont; end; end;