如何为 TabPage 控件分配自定义背景色或背景图像?
如何在 Visual Studio C# 2010 中为选项卡页控件分配背景图像?我可以分别为每个选项卡提供背景图像,但我不能为整个选项卡页控件提供背景图像,因为选项卡页控件的一部分保留不同的背景,并且每个选项卡页都有良好且精细的背景。
这是我的表单的图片:
查看 '选项卡行中的灰色区域。如何用一个背景覆盖整个标签页控件?
How can I assign a background image to tabpage control in Visual Studio C# 2010? I am able to provide background image to each of the tab separately, but I cannot do it so for the whole tabpage control, due to which a portion of tabpage control remain with different background and each of the tab pages has ok and fine background.
Here is the picture of my form:
See the 'grey-colored' region in the tabs line. How can I cover the whole tabpage control with one single background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
包含选项卡的标题区域不是选项卡页的一部分。它是父
TabControl
的一部分,由 Windows 自动为您绘制。如果你想改变它的外观,你就必须自己画它。这就是所谓的所有者绘图,这并不是一项简单的任务,尤其是对于像这样的复杂控件。对于初学者来说,您不能只使用
OwnerDrawFixed
,因为它只允许您自定义绘制选项卡的内容(例如,更改字体)。您需要绘制整个选项卡控件。我无法想象您想要这样做的充分理由,但您会在网上找到一些可能帮助您入门的示例。例如:
The header area that contains the tabs is not part of your tab page. It's part of the parent
TabControl
, which is automatically drawn for you by Windows.If you want to change how it looks, you'll have to draw it yourself. That's called owner-drawing, and it's not exactly a trivial undertaking, especially for a complicated control like this one. For starters, you can't just use
OwnerDrawFixed
, because that just allows you to custom draw the contents of the tabs (for example, to change the font). You will need to owner draw the entire tab control.I can't imagine a good reason that you would ever want do this, but you'll find a few samples online that might help get you started. For example: