C# 使用背景色Gainsboro时,服务器2016上的GroupBox边框不可见
我们使用标准的C# 使用背景色Gainsboro时,服务器2016上的GroupBox边框不可见,c#,winforms,groupbox,windows-server-2016,C#,Winforms,Groupbox,Windows Server 2016,我们使用标准的GroupBox和Flat样式。表单背景色为Gainsboro 在我的Windows 7开发计算机上,它如下所示: 但是,在Windows Server 2016计算机上运行应用程序时,它看起来如下所示: 边界消失(不可见) 它似乎与背景颜色有关,但我们不确定如何修复它。使用浅蓝色时,此情况发生在服务器2016上: 你们有什么线索吗,为什么我们看不到背景色为Gainsboro的白色边框?这没有任何意义……我没有server 2016来测试它,但是重写borderColor的绘
GroupBox
和Flat
样式。表单背景色为Gainsboro
在我的Windows 7开发计算机上,它如下所示:
但是,在Windows Server 2016计算机上运行应用程序时,它看起来如下所示:
边界消失(不可见)
它似乎与背景颜色有关,但我们不确定如何修复它。使用浅蓝色时,此情况发生在服务器2016上:
你们有什么线索吗,为什么我们看不到背景色为Gainsboro的白色边框?这没有任何意义……我没有server 2016来测试它,但是重写borderColor的
绘制事件可能会解决这个问题,这里有一个自定义GroupBox
控件,您可以在构造函数内更改borderColor
颜色
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CustomGroupBox gb = new CustomGroupBox();
gb.Location = new Point(5, 5);
gb.Size = new Size(200, 100);
this.Controls.Add(gb);
}
}
public class CustomGroupBox : GroupBox
{
private Color borderColor;
public Color BorderColor
{
get { return this.borderColor; }
set { this.borderColor = value; }
}
public CustomGroupBox()
{
this.borderColor = Color.Red;
}
protected override void OnPaint(PaintEventArgs e)
{
Size tSize = TextRenderer.MeasureText(this.Text, this.Font);
Rectangle borderRect = e.ClipRectangle;
borderRect.Y += tSize.Height / 2;
borderRect.Height -= tSize.Height / 2;
ControlPaint.DrawBorder(e.Graphics, borderRect, this.borderColor, ButtonBorderStyle.Solid);
Rectangle textRect = e.ClipRectangle;
textRect.X += 6;
textRect.Width = tSize.Width;
textRect.Height = tSize.Height;
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), textRect);
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);
}
}
}
您是本地登录还是通过RDP登录?我是本地用户,使用的是virtual Box。我尝试了类似的方法,但看起来与以前不同。但如果效果更好,我会在周一告诉你