Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.10.15;
Скачать: CL | DM;

Вниз

Как узнать 1 и последнюю видимую строку в Memo?   Найти похожие ветки 

 
Alex_C ©   (2006-09-27 16:53) [0]

В RichEdit - есть в факах, а вот для мемо - нет.


 
zdm ©   (2006-09-27 16:56) [1]

ну может не очень красивый вариант, пробегись циклом по всем первая-это первая а последняя соответсвенно


 
clickmaker ©   (2006-09-27 16:58) [2]

EM_GETFIRSTVISIBLELINE
последнюю можно узнать, разделив высоту клиентской области на высоту текста


 
Alex_C ©   (2006-09-27 17:02) [3]

To clickmaker: работает только для RichEdit"а. Это в факах есть. Для мемо это не работает, только сейчас проверил.


 
clickmaker ©   (2006-09-27 17:05) [4]


> [3] Alex_C ©   (27.09.06 17:02)

работает
ShowMessage(IntToStr(Memo1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0)));

только щас проверил )


 
Gydvin ©   (2006-09-27 19:03) [5]

Чуть хромает подправишь

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.



Страницы: 1 вся ветка

Текущий архив: 2006.10.15;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.046 c
15-1158931308
Megabyte
2006-09-22 17:21
2006.10.15
Firebird 2.0 и IB_Expert 2.5.0.22


15-1158672046
Оксана
2006-09-19 17:20
2006.10.15
Работа


2-1159158945
Gool
2006-09-25 08:35
2006.10.15
Панель в IE


15-1159014680
PHPDeveloper
2006-09-23 16:31
2006.10.15
Регистратор в ShareWare каталогах


2-1159215032
Glomen
2006-09-26 00:10
2006.10.15
Связать listbox и textbox