2017-08-25 57 views
1

我们使用标准GroupBoxFlatStyle。表单backgroundcolor为Gainsboro使用背景色时,GroupBox边框在服务器2016上不可见Gainsboro

在我的Windows 7的开发机,它看起来像这样:

Win7Example

然而,在Windows Server上运行的应用程序2016机的时候,它看起来像这样:

Windows Server 2016

边框消失了(不可见)。

它似乎与背景颜色有关,但我们不知道如何解决它。当使用淡蓝色,这种情况服务器2016上:

othercolor

你们是否有任何线索,为什么我们不能看到白色边框与BG-颜色Gainsboro?它没有任何意义....

+0

您是本地登录还是通过RDP登录? – Filburt

+0

我是本地人,使用虚拟方块 – Jannik

回答

0

我没有服务器2016年测试它,但也许重写Paint事件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); 
     } 
    } 
} 
+1

我尝试了一些类似的方法,但它看起来并不像以前那样完全一样。但是我会在星期一让你知道,如果这样做更好。 :) – Jannik