如何使tMemo显示器从最上面的项目开始?我没有发现任何类似于"TopItem“的东西,我想知道是否必须通过发送消息来完成(按键控制、按键主页、keyup home、keyup控件),但是尽管我阅读了大量的Delphi帮助,但我也没有想出如何做到这一点。
发布于 2022-03-21 18:37:52
只需选择任何字符,取决于您希望在行中可见的内容。
Memo.Lines.SelStart:=0;
Memo.Lines.SelLength:=1;发布于 2022-03-22 10:48:43
Steve88,谢谢你的努力,但这不管用。从彼得下面的一篇文章中得到了一些想法,这让我想到了以下几点,这实际上是可行的!
对于是使用MemoPopup.Perform还是PostMessage,有一些有趣的地方,我希望有人能了解这些工具的工作原理。
// Trying to get a tMemo to display its contents, starting at the first line.
// Various ideas from assorted net sites, and Peter Below's reply to someone
// with a similar problem - thanks, Peter!
// A couple of bits left in for people to puzzle over as to why they do or don't work!!
uses Winapi.Windows, Winapi.Messages;
var
KeyStateBefore, KeyStateUse : tKeyboardState;
begin
PostMessage(MemoPopup.Handle, WM_KeyDown, ord('A'), 0); //'a' gets through
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, ord('K'), 0); //This does not
Application.ProcessMessages;
GetKeyboardState(KeyStateBefore);
KeyStateUse := KeyStateBefore;
KeyStateUse[vk_Control] := $81;
SetKeyBoardState(KeyStateUse); //Now turn on the control key.
//These do appear to work as expected.
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, vk_Home, 0);
MemoPopup.Perform(WinApi.Messages.WM_KEYUP, vk_Home, 0);
Application.ProcessMessages;
SetKeyboardState(KeyStateBefore); //Remove the control key.
PostMessage(MemoPopup.Handle, WM_KeyDown, ord('B'), 0); //Got through, lower case
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, ord('E'), 0); //Nope
Application.ProcessMessages;
KeyStateUse := KeyStateBefore;
KeyStateUse[vk_Shift] := $80;
SetKeyboardState(KeyStateUse);
PostMessage(MemoPopup.Handle, WM_KeyDown, ord('C'), 0); //Got through in upper case
MemoPopup.Perform(WinApi.Messages.WM_KEYDOWN, ord('Q'), 0); //Not this though
Application.ProcessMessages;
SetKeyBoardState(KeyStateBefore);
Application.ProcessMessages;
end;https://stackoverflow.com/questions/71553752
复制相似问题