2017-05-15 66 views
-2

我使用的winforms有一個面板,並且在該面板內部有一個groupbox。Windows窗體控件最終沒有顯示在屏幕上

在組框中它有兩個單選按鈕的控制。 在客戶端機器中,有時候這個屏幕會變成空白而沒有單選按鈕。它只顯示組框標題。

我已檢查它發生在一天2-3只否則它工作正常。

我們稱之爲父窗體中的showdialog。

以下是報告給微軟論壇smiliar問題 https://social.msdn.microsoft.com/Forums/windows/en-US/8bfb02d5-70df-45a0-96ae-7aef4d4d427c/win-form-is-not-loading-properly-with-windows-8?forum=winforms

,但沒能找到這個解決方案。 請讓我知道是否有人遇到類似的問題,以及解決方案是什麼。

此示例代碼:

private void InitializeComponent() 
    { 
     this.groupBox1 = new Cross.CustomControls.GroupBox(); 
     this.rb1 = new System.Windows.Forms.RadioButton(); 
     this.rb2 = new System.Windows.Forms.RadioButton(); 
     this.btnOK = new System.Windows.Forms.Button(); 
     this.lblMessage = new System.Windows.Forms.Label(); 
     this.groupBox1.SuspendLayout(); 
     this.SuspendLayout(); 
     // 

     // groupBox1 
     // 
     this.groupBox1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(208)))), ((int)(((byte)(191))))); 
     this.groupBox1.Controls.Add(this.rb1); 
     this.groupBox1.Controls.Add(this.rb2); 
     this.groupBox1.DrawTopOnly = false; 
     this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System; 
     this.groupBox1.Font = new System.Drawing.Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.groupBox1.Location = new System.Drawing.Point(72, 141); 
     this.groupBox1.Name = "groupBox1"; 
     this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 21, 3, 2); 
     this.groupBox1.Size = new System.Drawing.Size(277, 74); 
     this.groupBox1.TabIndex = 1; 
     this.groupBox1.Text = "DF"; 
     this.groupBox1.TitleColor = System.Drawing.Color.Blue; 
     // 
     // rb1 
     // 
     this.rb1.AutoSize = true; 
     this.rb1.Checked = true; 
     this.rb1.Location = new System.Drawing.Point(30, 35); 
     this.rb1.Name = "rb1"; 
     this.rb1.Size = new System.Drawing.Size(101, 21); 
     this.rb1.TabIndex = 0; 
     this.rb1.TabStop = true; 
     this.rb1.Text = "rb1"; 
     this.rb1.UseVisualStyleBackColor = true; 
     this.rb1.CheckedChanged += new System.EventHandler(this.rb1_CheckedChanged); 
     // 
     // rb2 
     // 
     this.rb2.AutoSize = true; 
     this.rb2.Location = new System.Drawing.Point(149, 35); 
     this.rb2.Name = "rb2"; 
     this.rb2.Size = new System.Drawing.Size(96, 21); 
     this.rb2.TabIndex = 1; 
     this.rb2.TabStop = true; 
     this.rb2.Text = "rb2"; 
     this.rb2.UseVisualStyleBackColor = true; 
     this.rb2.CheckedChanged += new System.EventHandler(this.rb2_CheckedChanged); 
     // 
     // btnOK 
     // 
     this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System; 
     this.btnOK.Location = new System.Drawing.Point(274, 221); 
     this.btnOK.Name = "btnOK"; 
     this.btnOK.Size = new System.Drawing.Size(75, 29); 
     this.btnOK.TabIndex = 2; 
     this.btnOK.Text = "&OK"; 
     this.btnOK.Click += new System.EventHandler(this.btnOK_Click); 
     // 
     // lblMessage 
     // 
     this.lblMessage.Location = new System.Drawing.Point(72, 85); 
     this.lblMessage.Name = "lblMessage"; 
     this.lblMessage.Size = new System.Drawing.Size(337, 42); 
     this.lblMessage.TabIndex = 3; 

     // 
     // frmDFCardType 
     // 
     this.ArchSubTitle = "c"; 
     this.ArchTitle = "CT"; 
     this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 16F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(421, 273); 
     this.Controls.Add(this.lblMessage); 
     this.Controls.Add(this.btnOK); 
     this.Controls.Add(this.groupBox1); 
     this.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
     this.Name = "frmDFCardType"; 
     this.Controls.SetChildIndex(this.PleaseWait, 0); 
     this.Controls.SetChildIndex(this.groupBox1, 0); 
     this.Controls.SetChildIndex(this.btnOK, 0); 
     this.Controls.SetChildIndex(this.lblMessage, 0); 
     this.groupBox1.ResumeLayout(false); 
     this.groupBox1.PerformLayout(); 
     this.ResumeLayout(false); 


    } 
+2

顯示完整的代碼,因爲您粘貼的這部分根本沒有意義。 –

+0

添加了設計師代碼! – Akhilesh

+0

嘗試使用SuspendLayout,ResumeLayout和PerformLayout刪除代碼並查看會發生什麼 –

回答

3
this.groupBox1.DrawTopOnly = false; 
    this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System; 

沒有人將能夠從張貼片段瑞普您的問題,我們不知道Cross.CustomControls.GroupBox類做什麼。但是,這兩個陳述是解決潛在問題的一半線索。

FlatSystem.System對GroupBox類有一個非常不尋常的副作用。 通常,該控件完成自己的所有繪畫,但通過System實際上它依賴於內置的本機Windows控件來完成作業。一個相當怪異的控制,它是「按鈕」類。微軟不得不在30年前使用256K字節RAM來填充GUI操作系統。

它根本不支持的一件事是任何類型的自定義繪畫。 DrawTopOnly屬性強烈表明這是該控件實際上在做什麼。通過使用WndProc()方法重載攔截繪製消息,需要非常顯着的hackorama。

這很容易出錯。一種可能的情況是繪製代碼本身導致繪製區域再次失效。這有一個非常不直觀的副作用,groupbox的任何子控件都不會被繪製。就像那兩個單選按鈕。很難診斷,一切都看起來完全正常超越那些剛剛失蹤的兒童控制。有一件事你可以看到,你的程序的UI線程開始燃燒100%的核心,一遍又一遍地繪製groupbox或其父母。任務管理器可以顯示。

首先要做的是用普通的GroupBox替換自定義的GroupBox。接下來要做的就是讓SO用戶在發佈所有的代碼時幫助你。