设置 tMemo 顶部项目

发布于 2025-01-15 16:23:30 字数 164 浏览 4 评论 0原文

请问如何让 tMemo 从顶部项目开始显示? 我还没有找到类似“TopItem”的东西,想知道是否必须这样做 通过某种方式发送消息(keydown control、keydown home、keyup home、keyup control) 但尽管阅读了大量的 Delphi 帮助,我还是没有弄清楚如何做到这一点。

How can I make a tMemo display starting at the top item please?
I have not found anything like a "TopItem", and wonder if it has to be done
by somehow sending messages (keydown control, keydown home, keyup home, keyup control)
but despite reading large tracts of the Delphi Help I haven't worked out how to do this either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月野兔 2025-01-22 16:23:30

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

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

Just select any character depending on what you want visible in Lines.

Memo.Lines.SelStart:=0; 
Memo.Lines.SelLength:=1;
蝶舞 2025-01-22 16:23:30

Steve88,感谢您的尝试,但没有成功。
从 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;

Steve88, thanks for trying, but that did not work.
Got some ideas from a post from Peter Below, which led me to the following, which actually works!

There are some funnies as to whether to use MemoPopup.Perform or PostMessage, and I hope someone can shed light on the workings of these.

// 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;
心不设防 2025-01-22 16:23:30

是不是只是:

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

当然,在您将 Tmemo 的内容填满之后添加此代码......
(这对我有用)

Isn't it just:

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

Add this code of course after you have filled your Tmemo with its contents ...
(This works for me)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文