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 上设置背景图像吗?
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
