鼠标单击图片框时弹出文本框,以便为图片添加自定义注释
在我的 C# winforms 应用程序中,我有一个图片框,可以将一些位图图像加载到其中。我想要做的是,如果用户单击图片框中的某个位置,在鼠标位置会出现一个小文本框,用户可以向图片添加自定义文本(注释)。
我知道如何将字符串写入位图文件,但我找不到一种方法在鼠标位置弹出文本框,并在用户写入内容并按 Enter 键时自动将文本添加到图像中。这个文本框及其属性应该如何定义?
谢谢。
In my C# winforms application, I have a picturebox which some bitmap images can be loaded into it. What I want to do is if user clicks somewhere within picturebox, at the mouse location a small textbox will be appeared and user can add a custom text (note) to the picture.
I know how to write a string into a bitmap file, but I couldnt find a way to POP UP a textbox at mouse location, and automaticly add the text to the image when user wrote something and hit enter key. How this textbox and its properties should be defined?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在自定义弹出窗体中嵌入控件,如下所示。
PopupForm 构造函数中的最后一个参数指定当用户按 Enter 时要执行的操作。在此示例中,指定了一个匿名方法,设置表单的标题。
用法
PopupForm 类
You could embed a control in a custom popup form, as shown below.
The last argument in the PopupForm constructor specifies the action to take, when the user presses Enter. In this example an anonymous method is specified, setting the title of the form.
Usage
PopupForm Class
我想,您可以在鼠标单击时动态创建文本框,并使用它的 BringToFront() 方法,以防它不会出现在图片框上方。当用户按 Enter 时,处理此事件,从文本框中获取文本,并根据需要删除文本。
I suppose, you could create Textbox dynamically on mouse click and use it's BringToFront() method in case is will not appear above the picture box. When the user presses Enter, handle this event, get text from Textbox and remove if if needed.