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 还是使 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
