CMFCPropertyGridProperty 和 CEdit 文本自动选择

发布于 2024-12-27 02:30:20 字数 801 浏览 1 评论 0原文

我在此处读到的内容(当用户选择一个编辑控件,...并通过使用反向视频突出显示其文本),如果我理解正确,当我单击它时,CEdit 应该突出显示(我希望它与选择相同)文本。

我将 CMFCPropertyGridCtrl 与 CMFCPropertyGridProperty 一起使用。但是,当我单击网格(一个属性值)时,它不会选择任何内容。

我发现:属性在内部创建CEdit,用于手动编辑属性值。它已创建,其字体已设置等。然后调用 SetFocus,然后调用 UpdateWindow - 这将重绘编辑框并将光标设置在第一个字符之前。此后,再次单击鼠标以单击编辑框 - 这似乎是正确的。但没有选择任何文本。

我还尝试创建自己的属性类,它派生自 CMFCPropertyGridProperty。在这一切之后我已经调用了SetSel。它确实选择了我的文本,但随后它只是取消选择它(在下一个重画中)。我还取得的成果是,在重绘之后,仅选择从开始到鼠标单击的文本(当我在第 4 个字符后单击时,仅选择前 4 个字符)。

我的问题:

CEdit 真的应该在第一次单击鼠标后自动选择文本吗? (你有一些资源吗?)

你不知道为什么这在 CMFCPropertyGridProperty 中不起作用吗?

CMFCPropertyGridCtrl和CMFCPropertyGridProperty可以在mfc源代码目录下的afxpropertygridctrl.h/.cpp中找到。

What I have read here (When the user selects an edit control, .... and highlights its text by using reverse video) and if I understand it right, CEdit should highlight (I hope it's the same as select) text when I click on it.

I'm using CMFCPropertyGridCtrl with CMFCPropertyGridProperty. But when I click on grid (one property value), it doesn't select anything.

What I have found out: Property creates internally CEdit, which is for manually editing property value. It's created, its font is set etc. Then SetFocus is called and after that UpdateWindow - this redraws edit box and sets cursor before first character. After this, mouse click is evoked again to click on edit box - this seems correct. But no text is selected.

I have also tried to create my own property class, which derives from CMFCPropertyGridProperty. I have called SetSel after all this. It really selects my text, but then it just deselects it (in next Redraw). What I have also achieved was that after Redraw only text from begining to mouse click was selected (when I clicked after 4th character, only first 4 characters were selected).

My questions:

Should CEdit really select automaticaly text after first mouse click? (do you have some resources?)

Don't you know, why this is not working in CMFCPropertyGridProperty?

CMFCPropertyGridCtrl and CMFCPropertyGridProperty can be found in afxpropertygridctrl.h/.cpp in mfc source code directory.

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

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

发布评论

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

评论(1

许久 2025-01-03 02:30:20

所以我最终发现:

CEdit 在单击文本后可能不会选择文本。这必须通过例如 SetSel 函数手动完成。

但在 CMFCPropertyGridCtrl 中,如果单击,它会传递到 CMFCPropertyGridProperty 并且会重复单击。因此,如果我使用 SetSel,它会取消选择文本。所以我必须编写自己的类,它继承CMFCPropertyGridProperty并跳过这一步(再次单击)。 SetFocus 和 SetSel 就足够了(这也将光标设置到 CEdit 窗口)。

So what I have finally found out:

CEdit probably doesn't select text after clicking on it. This has to be done manually by for example SetSel function.

But in CMFCPropertyGridCtrl, if you click, it's passed to CMFCPropertyGridProperty and there is click repeated. So if I used SetSel, it deselects text. So I had to write my own class which inherits CMFCPropertyGridProperty and skips this step (clicking again). It's enough to SetFocus and SetSel (which also sets cursor to CEdit window).

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