如何改变memo控件的行间距?
解决方案 »
- SQL语句问题
- 关于数据库访问,很急,请帮忙.
- 急,第3次发贴,请大家帮忙,关于数据库程序设计填空题
- 初学者:组件TStringGrid和TQuery在哪里啊,找都找不到!谢谢!
- 在Form里如何重新定义一个mousedown事件覆盖TControl的Mousedown
- 程序打包问题:连接远程mysql的odbc已通,为什么程序中连不上呢
- 用delphi调用sql存储过程出现服务器内存过大而无法运行
- DBGrid在显示较少记录时,在右边总是出现垂直滚动条,求助怎么把它去掉????????
- 问一个弱智的问题:什么是POS?
- 用delphi怎么实现呢?
- 绝对经典的愚人话题(转载)
- 在DBGRID中如何控制只让某一列可修改,其它列的不可修改?
关注。
unit Unit1;interfaceuses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
StdCtrls, ExtCtrls, Forms;type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Memo1KeyPress(Sender: TObject; var Key: Char);
public
MaxCharsPerLine, MaxLines: Integer;
function MemoLine: Integer;
function LineLen(r: Integer): Integer;
function NRows: Integer;
end;var
Form1: TForm1;implementation{$R *.DFM}function TForm1.NRows: Integer;
begin
with Memo1 do
Result := 1 + SendMessage(Handle, EM_LINEFROMCHAR, GetTextLen-1, 0);
end;function TForm1.LineLen(r: Integer): Integer;
var r1, r2: Integer;
begin
with Memo1 do begin
r1 := SendMessage(Handle, EM_LINEINDEX, r, 0);
if (r < NRows-1) then
r2 := SendMessage(Handle, EM_LINEINDEX, r+1, 0)-2 {-CR/LF}
else
r2 := GetTextLen;
end;
Result := r2-r1;
end;function TForm1.MemoLine: Integer;
begin
with Memo1 do
Result := SendMessage(Handle, EM_LINEFROMCHAR, SelStart, 0);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
MaxCharsPerLine := 8;
MaxLines := 4;
end;procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
with Memo1 do begin
case Key of
' '..#255: if (LineLen(MemoLine) >= MaxCharsPerLine) then
Key := #0;
#10, #13: if (NRows >= MaxLines) then
Key := #0;
#8: if (SelStart = SendMessage(Handle, EM_LINEINDEX, MemoLine, 0)) then
Key := #0;
end;
end;
end;end.
var
ACanvas: TCanvas;
ARect : TRect;
str: string;begin
str := 'hello the world'; ARect := Rect(0,0,memo1.Width,50);
ACanvas := TCanvas.Create;
ACanvas.Handle := GetDC(Memo1.Handle);
ACanvas.TextRect(ARect,0,0,str);
end;
其实memo没有办法改变行间距,据说rxlib里面的rxrichedit有这个功能
不过我没有用过
这样也行?呵呵,服了。
不过这样的字是画上去的,还得考虑重绘,而且人家要是想从中粘一段儿出来...
但是不知道怎么样接收键盘的输入,有办法让它接收到键盘的输入的字符吗?