TRichEdit在Scrollbars为ssNone时滚轮滚动内容
分类:Components, Delphi
阅读 (2,622)
Add comments
7月 162014
在TRichEdit的Scrollbars属性为ssNone时,RichEdit中的内容超出边框大小时,翻动鼠标上下滚轮时,内容是不会自动滚动的。需要写代码实现此功能,主要是在RichEdit1MouseWheelUp和RichEdit1MouseWheelDown中发送消息实现,具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls; type TForm1 = class(TForm) RichEdit1: TRichEdit; procedure RichEdit1MouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); procedure RichEdit1MouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.RichEdit1MouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin SendMessage(RichEdit1.Handle, WM_VSCROLL, SB_LINEDOWN, 0); Handled := True; end; procedure TForm1.RichEdit1MouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean); begin SendMessage(RichEdit1.Handle, WM_VSCROLL, SB_LINEUP, 0); Handled := True; end; end. |