Главная страница
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.044 c
1-1157272016
atruhin
2006-09-03 12:26
2006.10.15
Ипользование объекта вместо записи


15-1158684060
GanibalLector
2006-09-19 20:41
2006.10.15
Джеф Раскин "Интерфейс"


3-1155824707
incm
2006-08-17 18:25
2006.10.15
Как используя BDE и MS SQL Server получать RAISEROR( Err ,10)


15-1158837623
iamdanil
2006-09-21 15:20
2006.10.15
(с)


2-1159565942
-Gruo-
2006-09-30 01:39
2006.10.15
Удаление всех пробелов из строки?