Can a background image be set on a Winforms TextBox?(可以在 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 上设置背景图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:可以在 Winforms TextBox 上设置背景图像吗?


- 在 LINQ to SQL 中使用 contains() 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01