模仿 Tcl/Tk 的字体“OnMouseEnter” C# 应用程序中的行为
我正在查看朋友发给我的一个用 Tcl/Tk 编写的程序。它有一个格式丰富的多行文本框,具有不同的颜色和字体,对于某些文本块,应用程序窗口会对用户将鼠标悬停在不同的文本元素上做出反应。他说这是通过在创建新字体时指定“OnMouseEnter”回调事件来实现的。这似乎是一种很酷且优雅的方法,我想在我编写的 C# 应用程序中做类似的事情。目前,我可以想到的三种方法是:(a)计算出从 XY 鼠标坐标到文本的映射(也许有一个简单的函数可以实现这一点?)(b)使每个不同的文本块成为一个子控件它自己的回调函数(这非常丑陋,需要我自己进行文本换行)或(c)使其成为网页控件并通过 WebBrowser.Navigating 让 javascript“调用”C#。任何有关实现此类功能的最佳方法的建议都将受到欢迎。
I was looking at a program my friend sent me that was written in Tcl/Tk. It has a rich-formatting multi-line text box with different colors and fonts, and for certain blocks of text the application window reacts to users hovering over different text elements. He says this is implemented by specifying a "OnMouseEnter" callback event when creating a new font. This seems like a cool and elegant approach, and I wanted to do something similar in a C# app I wrote. At the moment the three ways I can think to do this are: (a) work out the mapping from X-Y mouse coords to text (maybe there is an easy function for this?) (b) make each distinct text block a child control with its own callback functions (which is very ugly and would require me to do my own text wrapping) or (c) make it a webpage control and have javascript "call" C# via WebBrowser.Navigating. Any suggestions as to the best way to implement this kind of functionality would be welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数文本框控件都具有 XY 坐标到文本块转换功能的调用。您可以挂钩文本框的整个鼠标移动事件并查看鼠标下方的内容。
这可能是丑陋的代码,但至少它可以工作。
Most textbox control have X-Y coord to text block translation function calls. You can hook the entire mouse move event for the textbox and see what's beneath the mouse.
This might be ugly code but at least it would work.