窗体上的所有控件都看不见 [英] All controls on a form are invisible
问题描述
我碰到一个奇怪的问题。鉴于只有这code(我已经削减到最基本的要素),窗体将出现,但其上的所有控件都看不见,即使他们的个人可见
属性是真实的:
I've run into a bizarre problem. Given only this code (that I've cut down to the bare essentials), the form will appear but all controls on it are invisible, even though their individual Visible
properties are true:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new WaveformWindow());
}
}
// ...
public partial class WaveformWindow : Form
{
public WaveformWindow()
{
InitializeComponent();
}
}
// ...
partial class WaveformWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(27, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 4;
this.label1.Text = "label1";
//
// WaveformWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(398, 373);
this.Name = "WaveformWindow";
this.ShowInTaskbar = false;
this.Text = "WaveformWindow";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label label1;
}
工作和破碎的版本的非剥离方案之间的比较,改变了只有文件的形式为设计文件。
Comparing between working and broken versions of the non-stripped program, the only file that changed is the form designer file.
推荐答案
添加控件到窗体,以使其可见。 见... this.Controls.Add(this.label1); 下面
Add the controls to the form to make them visible. See... this.Controls.Add(this.label1); below
//
// WaveformWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(398, 373);
this.Name = "WaveformWindow";
this.ShowInTaskbar = false;
this.Text = "WaveformWindow";
**this.Controls.Add(this.label1);**
this.ResumeLayout(false);
Windows窗体产生code到所有控件自动添加到表单。所以每当ü面对这样的问题,删除旧的控制,并再次将其拖放。它必须是然后可见的。 (编辑了解这一问题)
Windows forms generates the code to add all the controls to forms automatically. So whenever u face such problem, delete the old control and again drag and drop it. It must be then visible. (Edit for understanding the issue)
这篇关于窗体上的所有控件都看不见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!