我遇到了一个奇怪的问题。仅给出这段代码(我已将其缩减为最基本的部分),表单将出现,但其上的所有控件都是不可见的,即使它们各自的Visible
属性为真:
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;
}
比较未剥离程序的工作版本和损坏版本,唯一更改的文件是表单设计器文件。
将控件添加到窗体中以使其可见。
看...this.Controls.Add(this.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.Controls.Add(this.label1);**
this.ResumeLayout(false);
Windows 窗体生成代码以自动将所有控件添加到窗体中。因此,每当您遇到此类问题时,请删除旧控件并再次拖放它。那么它一定是可见的。 (编辑以理解问题)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)