windows窗体ce中tabcontrol的透明背景
我试图在compact框架中自定义tabcontrol,但我找不到为该控件设置透明背景的解决方案。我试图重写“OnPaintBackground()”方法以开始对其设置背景,但未调用此函数。创建控件时如何使用此函数进行调用?编辑:我阅读了您关于尝试设置容器背景颜色而不是单个选项卡的评论,并进行了一些实验和研究 TabControl类的OnDrawItem方法似乎用于绘制选项卡“标题”(控件中包含每个选项卡文本的部分,用户单击该部分以选择选项卡)以及容器的背景(除所选选项卡内容之外的所有内容,这些内容由选项卡本身在其OnPaintBackground方法中绘制) 通过重写TabControl的windows窗体ce中tabcontrol的透明背景,windows,windows-mobile,compact-framework,Windows,Windows Mobile,Compact Framework,我试图在compact框架中自定义tabcontrol,但我找不到为该控件设置透明背景的解决方案。我试图重写“OnPaintBackground()”方法以开始对其设置背景,但未调用此函数。创建控件时如何使用此函数进行调用?编辑:我阅读了您关于尝试设置容器背景颜色而不是单个选项卡的评论,并进行了一些实验和研究 TabControl类的OnDrawItem方法似乎用于绘制选项卡“标题”(控件中包含每个选项卡文本的部分,用户单击该部分以选择选项卡)以及容器的背景(除所选选项卡内容之外的所有内容,这些
OnDrawItem
方法,您可以使TabControl的背景透明,但只需填充DrawItemEventArgs
传递的边界,也会使选项卡标题透明,使其不可单击(单击将穿过表单,到达表单后面的任何内容)
在我看来,你有几个选择来解决这个问题:
要使其工作,表单需要将其TransparencyKey设置为某个值,并且其AllowTransparency属性的值必须为true。我在tabcontrol中找不到ondrowitem来覆盖它。windows CE环境(smartDevice)不支持windows窗体中的所有功能谢谢您的回复,我需要做的是为选项卡容器而不是选项卡本身设置背景。 class TransparentisTabControl : TabControl { //Without declaring this as new, you'd probably get a warning saying this property hides a member of the base class. //The base class's BackColor property, as I'm sure you've found out, //is hidden with attributes anyway, so it doesn't really matter. public new Color BackColor {get; set;} public TransparentishTabControl(Color backColor) { if (backColor.A == 0) throw new ArgumentException("The alpha component of backColor cannot be zero, or this TransparentisTabControl's tab pages won't be selectable."); BackColor = backColor; } protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(fake); e.Graphics.Clear(BackColor); } }
class TransparentTabPage : TabPage
{
public TransparentTabPage()
: base("TransparentTabPage")
{
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Form form = FindForm();
e.Graphics.CompositingMode = CompositingMode.SourceCopy;
using (SolidBrush sb = new SolidBrush(form.TransparencyKey))
e.Graphics.FillRectangle(sb, Bounds);
}
}