有什么方法可以禁止在备忘录控件中选择文本吗?

发布于 2024-12-11 19:22:50 字数 50 浏览 0 评论 0原文

有什么方法可以禁止在备忘录控件中选择文本,因为这非常烦人。
该备忘录是只读的。

Is there any way to disable selecting of text in a memo control because it's very anoying.
The memo is Read Only.

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

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

发布评论

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

评论(4

饮湿 2024-12-18 19:22:50

我认为你应该重新考虑一下。我意识到您的控件以只读模式使用,但是,如果最终用户希望复制文本的一部分怎么办?然后他需要能够选择有问题的部分。

不过,如果您确定需要禁用每种选择,最简单的方法是使用 TRichEdit 而不是 TMemo,然后简单地执行

procedure TForm1.RichEdit1SelectionChange(Sender: TObject);
begin
  RichEdit1.SelLength := 0;
end;

I think you should rethink. I realise that your control is used in read-only mode, but still, what if the end user wishes to copy a part of the text? Then he needs to be able to select the part in question.

Still, if you are certain that you need to disable every kind of selection, the easiest approach is to use a TRichEdit instead of the TMemo, and do simply

procedure TForm1.RichEdit1SelectionChange(Sender: TObject);
begin
  RichEdit1.SelLength := 0;
end;
倾听心声的旋律 2024-12-18 19:22:50

您还可以使用 onMouseUp 事件

procedure TForm1.Memo1MouseUp(Sender: TObject: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Memo1.SelLength > 0 then
    Memo1.SelLength := 0;
end;

,但是,这不会停止使用键盘进行选择。

或者您也可以使用 onEnter,只需将焦点更改到窗体上的另一个控件。

procedure TForm1.Memo1Enter(Sender: TObject);
begin
  Edit1.SetFocus;
end;

You could also use the onMouseUp event

procedure TForm1.Memo1MouseUp(Sender: TObject: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Memo1.SelLength > 0 then
    Memo1.SelLength := 0;
end;

But, that doesn't stop selecting with the keyboard..

or you could also use the onEnter, and just change the focus to another control on your form.

procedure TForm1.Memo1Enter(Sender: TObject);
begin
  Edit1.SetFocus;
end;
时光磨忆 2024-12-18 19:22:50

我一直在玩 TRichEdit 和 TMemo,直到无聊到流泪。是的,您可以对对象进行一些事件处理技巧,但这仍然不是所需的效果 - 并且光标最终会在某处闪烁。所以我能找到的最好的办法就是使用 TLabel。我正在使用 Borland C++ Builder 6,并且 \n 使用 TLabel 的内联文本字符串正确翻译。所以,

Label1->Caption = "this is a test of the emergency\n"
                  "broadcast station, this is only\n"
                  "a test. If this had been an\n"
                  "actual emergency, blah blah blah...\n";

工作得很好。我没有尝试从文件中读入,但我确信如果流与所看到的完全一样,它也会起作用。由于您必须输入或阅读要显示的文本 - 这应该可以很好地工作,而不是为每行使用一堆 TLabel。如果您担心自动换行,则必须单独处理该部分。如果它是静态的,那么就像我在示例中所做的那样手动完成。我当然希望这会有所帮助或至少给出一个想法......

  • atomkey -

I played around with TRichEdit and TMemo until I was bored to tears. Yes, you can do a few tricks with event handling on the object, but it still is not the desired effect - and the cursor winds up blinking somewhere. So the best thing I could find was to use TLabel. I'm using Borland C++ Builder 6, and the \n is translated correctly with inline text strings for TLabel. So,

Label1->Caption = "this is a test of the emergency\n"
                  "broadcast station, this is only\n"
                  "a test. If this had been an\n"
                  "actual emergency, blah blah blah...\n";

Works just fine. I haven't tried to read in from a file, but I'm certain that if the stream were exactly as seen it would also work. Since you are going to have to enter or read in the text you want displayed anyway - this should work well instead of using a bunch of TLabels for each line. If you have a concern for word wrapping, you will have to process that portion separately. If it static, then just do it by hand like I did in the example. I sure hope this helps or at least gives an idea...

  • atomkey -
憧憬巴黎街头的黎明 2024-12-18 19:22:50

据我了解,您实际上想使用备忘录作为标签(有时它确实有意义)。
当我需要使用 TcxMemo(来自 DeveloperExpress 的备忘录组件)作为标签时,我使用这样简单的过程:

procedure ShowMemoAsLabel(m: TcxMemo);
begin
  m.Enabled := False;
  m.Properties.ReadOnly := True;

  // AH: Unfortunately it doesn't copy some important properties, maybe it will
  // be fixed in future versions of DEX, but at moment we do some job ourselves.
  m.StyleDisabled := m.Style;

  m.StyleDisabled.BorderColor := m.Style.BorderColor;
  m.StyleDisabled.BorderStyle := m.Style.BorderStyle;
  m.StyleDisabled.Color := m.Style.Color;
  m.StyleDisabled.Edges := m.Style.Edges;
  m.StyleDisabled.Shadow := m.Style.Shadow;
  m.StyleDisabled.TextColor := m.Style.TextColor;
  m.StyleDisabled.TextStyle := m.Style.TextStyle;
  m.StyleDisabled.TransparentBorder := m.Style.TransparentBorder;
end;

As i understand you would like to use memo as label actually (and sometimes it really have sense).
When i need to use TcxMemo (memo component from DeveloperExpress) as label i use such simple procedure:

procedure ShowMemoAsLabel(m: TcxMemo);
begin
  m.Enabled := False;
  m.Properties.ReadOnly := True;

  // AH: Unfortunately it doesn't copy some important properties, maybe it will
  // be fixed in future versions of DEX, but at moment we do some job ourselves.
  m.StyleDisabled := m.Style;

  m.StyleDisabled.BorderColor := m.Style.BorderColor;
  m.StyleDisabled.BorderStyle := m.Style.BorderStyle;
  m.StyleDisabled.Color := m.Style.Color;
  m.StyleDisabled.Edges := m.Style.Edges;
  m.StyleDisabled.Shadow := m.Style.Shadow;
  m.StyleDisabled.TextColor := m.Style.TextColor;
  m.StyleDisabled.TextStyle := m.Style.TextStyle;
  m.StyleDisabled.TransparentBorder := m.Style.TransparentBorder;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文