2017-08-25 35 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

相關問題