Windows窗体控件最终不会显示在屏幕上

时间:2017-05-15 09:52:02

标签: c# winforms

我正在使用winforms,它有一个面板,在面板内部有一个groupbox。

在分组框中,它还有两个单选按钮控件。 在客户端计算机中,此屏幕显示为空白,没有单选按钮。它只显示组合框标题。

我已经检查过它只在一天内发生2-3次,否则它工作正常。

这个屏幕我们从父表单调用showdialog。

以下是向微软论坛报告的一个熟悉的问题 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);


    }

1 个答案:

答案 0 :(得分:3)

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

没有人能够从已发布的代码段中重新解决您的问题,我们不知道Cross.CustomControls.GroupBox类的功能。但这两个陈述对于潜在的问题是一个相当不错的线索。

FlatSystem.System对GroupBox类有一个非常不寻常的副作用。 通常控件会完成所有自己的绘制,但是在系统生效的情况下,它依赖于内置的本机Windows控件来完成工作。一个相当古怪的控件,它是“Button”类。 30年前,微软不得不使用其中一个黑客来填充256千字节RAM的GUI操作系统。

它根本不支持任何一种自定义绘画。 DrawTopOnly属性强烈暗示此控件实际上正在执行此操作。通过使用WndProc()方法重载拦截绘制消息,需要非常重要的hackorama。

这很容易出错。一种可能的情况是绘制代码本身会导致绘制区域再次失效。这有一个非常不直观的副作用,组框的任何子控件都不会被绘制。像那两个radiobuttons。很难诊断,一切看起来都是正常的,除了那些失踪的儿童控制。您可以看到的一件事,您的程序的UI线程开始刻录100%核心,一遍又一遍地绘制组框或其父级。任务管理器可以显示。

首先要做的是用普通的GroupBox替换自定义的GroupBox。接下来要做的就是让SO用户通过发布重现问题所需代码的所有来帮助您。

相关问题