可以在 Winforms TextBox 上设置背景图像吗? [英] Can a background image be set on a Winforms TextBox?

查看:18
本文介绍了可以在 Winforms TextBox 上设置背景图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 C# 中更改 Windows 窗体 TextBox 的背景图像?没有 BackgroundImage 属性.我应该以某种方式覆盖 Paint 方法吗?

Is it possible to change the background image of a Windows Forms TextBox in C#? There is no BackgroundImage property. Should I override the Paint method somehow?

推荐答案

这是不可能的.如果您尝试通过覆盖 TextBox 并在构造函数中调用 SetStyle(ControlStyles.UserPaint, true) 来覆盖 OnPaintBackground 并绘制图像,那么您会遇到一些粗鲁的惊喜.回退到旧版渲染模式只是其中之一.

It isn't possible. If you try by overriding TextBox and calling SetStyle(ControlStyles.UserPaint, true) in the constructor so you can override OnPaintBackground and draw the image, you'll be in for several rude surprises. Falling back to legacy rendering mode is just one of them.

TextBox 可以追溯到 Windows 的早期,那时它还必须在 386SUX 硬件上运行.它在这种有限的硬件上合理工作所犯的一项特殊罪行是在不使用 WM_PAINT 事件的情况下绘制自身.这会破坏背景图像.

TextBox dates from the very early days of Windows, back when it still had to run on 386SUX hardware. One particular crime it commits to work reasonably on such limited hardware was to draw itself without using the WM_PAINT event. This destroys the background image.

CodeProject.com 上有一个项目提供了一个.我不能推荐它.

There's a project at CodeProject.com that provides one. I cannot recommend it.

这篇关于可以在 Winforms TextBox 上设置背景图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆