设置tMemo顶部项目



如何从顶部项目开始显示tMemo?我还没有发现任何类似于;TopItem";,想知道是否必须这样做通过以某种方式发送消息(keydown control、keydown home、keyup home、key up control(但是,尽管阅读了大量的Delphi帮助,我也没有想出如何做到这一点。

只需根据您希望在Lines中显示的内容选择任何字符。

Memo.Lines.SelStart:=0; 
Memo.Lines.SelLength:=1;

Steven88,感谢您的尝试,但没有成功。从Peter Below的一篇帖子中得到了一些想法,这让我想到了以下内容,它确实有效!

关于是使用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;

最新更新