Transperent tabcontrol .... [英] Transperent tabcontrol ....

查看:94
本文介绍了Transperent tabcontrol ....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将TabControl的背景颜色设置为Transperent?

解决方案

默认情况下,选项卡控件的背景是透明的,您无法更改它。

查看选项卡本身右侧的位,然后更改表单背景颜色。您将看到它通过空白区域显示。


Windows窗体TabControl没有BackColor,ForeColor或BackgroundImage属性:它的每个TabPages ...您可以将其视为单独的Windows包含在TabControl中,每个都与一个TabHeader关联...具有所有这些属性。



TabHeader出现的TabControl区域直接接近你;你将不得不使用API​​调用和/或WndProc来访问它...做一些事情,比如设置它的Tabs的颜色等等。那个没有被Tabs占用的区域占据了它的背景。 ContainerControl /形成它。如果它的ContainerControl有一个BackgroundImage,BackGroundImage将显示出来。



你可以,亲切的,模拟使TabPages的背景透明,但不能控制Opacity,就像使用Forms一样。而且,如果TabPages位于表格上的任何其他控件之上,他们将不会透露。



这是一个例子:



假设你有一个坚实的背景图像,或者有一个足够模式的图案,如果显示多个未对齐的副本,它将显得无缝。



1.创建一个WinForm:分配它的BackgroundImage。



2.向WinForm添加一个TabControl;将一些TabPages添加到TabControl。在每个TabPage上放置各种WinForm控件。



3.假设TabControl的名称为'tabControl1:将以下内容添加到WinForm的Load EventHandler中:

  foreach (TabPage theTab  in  tabControl1.TabPages)
{
theTab.BackgroundImage = this .BackgroundImage;
}

现在运行项目,观察视觉上发生的事情。



我想如果你真的想要花哨, 你可以在Form上使用复杂(不是实体,没有细微图案)的BackgroundImage,并在运行时通过分析TabPages的内容区域,并将其DisplayRectangles中Form的BackgroundImage部分提取为单独的位图,然后将其分配给每个TabPages作为BackgroundImage。



如果你真的需要更复杂的透明功能,我建议你考虑使用WPF而不是的WinForms。


How to set background color of TabControl to Transperent?

解决方案

The background of a tab control is transparent by default, and you cannot change it.
Look at the bit to the right of the tabs themselves, and change your form background colour. You will see it show through the empty area.


The Windows Forms TabControl has no BackColor, ForeColor, or BackgroundImage Properties: each of its TabPages ... which you can think of as separate Windows contained in the TabControl, each associated with a TabHeader ... has all those Properties.

The area of the TabControl where the TabHeaders appear is not accessible to you directly; you would have to use API calls an/or WndProc to get access to it ... to do things like set the colors of its Tabs, etc. That area, where it is not occupied by the Tabs, takes on the background of the ContainerControl/Form it's in. If its ContainerControl has a BackgroundImage, the BackGroundImage will show through.

You can, kind-of, simulate making the background of the TabPages transparent, although with no control over Opacity as you can do with Forms. And, if the TabPages are on top of any other Control on the Form they will not "show through."

Here's an example:

Assume you have a background image that is solid, or has a pattern subtle enough that it will appear to be seamless if multiple copies of itself are displayed which are not aligned.

1. create a WinForm: assign its BackgroundImage.

2. add a TabControl to the WinForm; add some TabPages to the TabControl. Put various WinForm Controls on each TabPage.

3. assuming the name of the TabControl is 'tabControl1: add the following to the Load EventHandler of the WinForm:

foreach(TabPage theTab in tabControl1.TabPages)
{
    theTab.BackgroundImage = this.BackgroundImage;
}

Now run the Project, and observe what happens visually.

I suppose if you really wanted to get "fancy," you could use a BackgroundImage that was complex (not solid, no subtle pattern) on the Form, and, at run-time, by analyzing the content areas of the TabPages, and extracting the portion of the Form's BackgroundImage in their DisplayRectangles into a separate bitmap, then assign that to each of the TabPages as the BackgroundImage.

If you really need more complex transparency functionality, I'd encourage you to consider WPF rather than WinForms.


这篇关于Transperent tabcontrol ....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆