如何借鉴一个TextBox的顶部 [英] How to draw on top of a TextBox
问题描述
我有一个文本框的winform,我想画在它上面的一些GDI图形。文本框不具有涂料()
事件挂钩,所以我认为这一切已窗体的Paint事件中happeen。作为一个测试,我绘制一条从原点的矩形的位置在文本框中有:
I have winform with a TextBox and I want to draw some GDI graphics on top of it. The text box does not have a Paint()
event to hook to, so I assume it all has to happeen within the form's Paint event. As a test I am drawing a rectangle from the origin to a location within the text box with:
private void FindForm_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = new Pen(Color.Blue))
{
e.Graphics.DrawRectangle(pen, 0, 0, point.X, point.Y);
}
}
问题是,当我运行,绘画是首先进行,然后在文本框中呈现出来,对我行之上。我想文本框被渲染后,绘制线条。
The problem is that when I run, the drawing is done first, and then the text box is rendered, on top of my lines. I want to draw the lines after the text box is rendered.
PS。我没有为与 Form.SetStyle()
函数形式所做的任何设置。
PS. I have not made any settings for the form with the Form.SetStyle()
function.
推荐答案
它可以比较棘手的业主画出文本框
控件,因为它只是周围的本地Win32 文本框的包装
控制。
It can be relatively tricky to owner-draw the TextBox
control because it's simply a wrapper around the native Win32 TextBox
control.
要捕获您需要处理您的自定义的 WM_PAINT
消息的最简单方法绘画例程的工作是从 的NativeWindow
类。
The easiest way to capture the WM_PAINT
messages that you need to handle for your custom painting routines to work is by inheriting from the NativeWindow
class.
下面是一个很好的一步一步的文章,说明如何在上下文中做到这一点显示的红色波浪下划线:所有者绘制一个Windows者,恕不文本框
Here is an excellent step-by-step article that shows how to do this in the context of displaying the red wavy underlines: Owner-drawing a Windows.Forms TextBox
这篇关于如何借鉴一个TextBox的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!