![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Как узнать 1 и последнюю видимую строку в Memo? [D7, XP]
Alex_C © (2006-09-27 16:53:00)В RichEdit - есть в факах, а вот для мемо - нет.
Gydvin (2006-09-27 19:03:00) [1]Чуть хромает подправишь
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
RichEdit1: TRichEdit;
function LinesVisible(Memo: tmemo): integer;
procedure Button1Click(Sender: TObject);
procedure Memo1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.LinesVisible(Memo: tmemo): integer;
var
OldFont: HFont;
Hand: THandle;
TM: TTextMetric;
Rect: TRect;
tempint: integer;
begin
Hand := GetDC(Memo.Handle);
try
OldFont := SelectObject(Hand, Memo.Font.Handle);
try
GetTextMetrics(Hand, TM);
memo.Perform(EM_GETRECT, 0, longint(@Rect));
tempint := (Rect.Bottom - Rect.Top) div
(TM.tmHeight + TM.tmExternalLeading);
finally
SelectObject(Hand, OldFont);
end;
finally
ReleaseDC(Memo.handle, Hand);
end;
Result := tempint;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x, y, a: integer;
begin
x := LinesVisible(memo1);
a := memo1.Lines.Count;
if x > a then x := a;
if x <> 0 then x := x - 1;
y := SendMessage(memo1.handle, EM_GETFIRSTVISIBLELINE, 0, 0);
caption := 'Up ' + inttostr(y) + ' - Down ' + inttostr(y + x) + ' - count ' + inttostr(a);
end;
procedure TForm1.Memo1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
Button1.Click;
end;
end.
clickmaker (2006-09-27 17:05:00) [2]
> [3] Alex_C © (27.09.06 17:02)
работает
ShowMessage(IntToStr(Memo1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0)));
только щас проверил )
Alex_C (2006-09-27 17:02:00) [3]To clickmaker: работает только для RichEdit'а. Это в факах есть. Для мемо это не работает, только сейчас проверил.
clickmaker (2006-09-27 16:58:00) [4]EM_GETFIRSTVISIBLELINE
последнюю можно узнать, разделив высоту клиентской области на высоту текста
zdm (2006-09-27 16:56:00) [5]ну может не очень красивый вариант, пробегись циклом по всем первая-это первая а последняя соответсвенно