如何为 TabPage 控件分配自定义背景色或背景图像?

发布于 2024-10-14 23:19:04 字数 306 浏览 10 评论 0原文

如何在 Visual Studio C# 2010 中为选项卡页控件分配背景图像?我可以分别为每个选项卡提供背景图像,但我不能为整个选项卡页控件提供背景图像,因为选项卡页控件的一部分保留不同的背景,并且每个选项卡页都有良好且精细的背景。

这是我的表单的图片:

C:\Documents and Settings\AWaheed3\Desktop\Stack Overflow.JPG

查看 '选项卡行中的灰色区域。如何用一个背景覆盖整个标签页控件?

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:

C:\Documents and Settings\AWaheed3\Desktop\Stack Overflow.JPG

See the 'grey-colored' region in the tabs line. How can I cover the whole tabpage control with one single background?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦萦几度 2024-10-21 23:19:04

包含选项卡的标题区域不是选项卡页的一部分。它是父 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文