首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >没有显示带有自定义设计代码的c#表单

没有显示带有自定义设计代码的c#表单
EN

Stack Overflow用户
提问于 2014-11-29 17:24:55
回答 1查看 371关注 0票数 0

我目前正在进行一个项目,允许用户设计自己的WinForm (使用DesignSurface)。因此,我编写了一个算法来为表单创建Designer-Code。一切都很好,除了一件事:表单一旦编译,就不会出现。一切都应该正常工作,我不知道问题出在哪里。总之,这是密码:

代码语言:javascript
运行
复制
public partial class mainForm : Form
{
    public mainForm()
    {
        InitializeComponent();
    }

    private System.Windows.Forms.CheckBox checkBox3;
    private System.Windows.Forms.CheckBox checkBox2;
    private System.Windows.Forms.CheckBox checkBox1;
    private CustomButton button1;
    private CustomTextBox textBox3;
    private System.Windows.Forms.Label label3;
    private CustomTextBox textBox2;
    private System.Windows.Forms.Label label2;
    private CustomTextBox textBox1;
    private System.Windows.Forms.Label label1; 
    private System.ComponentModel.IContainer components = null;


    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
        this.checkBox3 = new System.Windows.Forms.CheckBox();
        this.checkBox2 = new System.Windows.Forms.CheckBox();
        this.checkBox1 = new System.Windows.Forms.CheckBox();
        this.button1 = new CustomButton();
        this.textBox3 = new CustomTextBox();
        this.label3 = new System.Windows.Forms.Label();
        this.textBox2 = new CustomTextBox();
        this.label2 = new System.Windows.Forms.Label();
        this.textBox1 = new CustomTextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        //
        //checkBox3
        //
        this.checkBox3.AutoCheck = false;
        this.checkBox3.AutoSize = true;
        this.checkBox3.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.checkBox3.Text = @"";
        this.checkBox3.ForeColor = System.Drawing.Color.FromName("Black");
        this.checkBox3.Location = new System.Drawing.Point(187, 151);
        this.checkBox3.Name = @"checkBox3";
        this.checkBox3.Size = new System.Drawing.Size(87, 17);
        this.checkBox3.TabIndex = 9;
        this.checkBox3.Tag = @"XC";
        //
        //checkBox2
        //
        this.checkBox2.AutoCheck = false;
        this.checkBox2.AutoSize = true;
        this.checkBox2.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.checkBox2.Text = @"";
        this.checkBox2.ForeColor = System.Drawing.Color.FromName("Black");
        this.checkBox2.Location = new System.Drawing.Point(101, 151);
        this.checkBox2.Name = @"checkBox2";
        this.checkBox2.Size = new System.Drawing.Size(60, 17);
        this.checkBox2.TabIndex = 8;
        this.checkBox2.Tag = @"XC";
        //
        //checkBox1
        //
        this.checkBox1.AutoCheck = false;
        this.checkBox1.AutoSize = true;
        this.checkBox1.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.checkBox1.Text = @"";
        this.checkBox1.ForeColor = System.Drawing.Color.FromName("Black");
        this.checkBox1.Location = new System.Drawing.Point(15, 151);
        this.checkBox1.Name = @"checkBox1";
        this.checkBox1.Size = new System.Drawing.Size(70, 17);
        this.checkBox1.TabIndex = 7;
        this.checkBox1.Tag = @"XC";
        //
        //button1
        //
        this.button1.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.button1.Text = @"";
        this.button1.UseVisualStyleBackColor = false;
        this.button1.ForeColor = System.Drawing.Color.FromName("Black");
        this.button1.Location = new System.Drawing.Point(12, 187);
        this.button1.Name = @"button1";
        this.button1.Size = new System.Drawing.Size(309, 38);
        this.button1.TabIndex = 6;
        this.button1.Tag = @"XC";
        //
        //textBox3
        //
        this.textBox3.UseForCustoming = true;
        this.textBox3.CustomingName = @"";
        this.textBox3.BackColor = System.Drawing.Color.FromName("White");
        this.textBox3.ForeColor = System.Drawing.Color.FromName("Black");
        this.textBox3.Location = new System.Drawing.Point(15, 116);
        this.textBox3.Name = @"textBox3";
        this.textBox3.Size = new System.Drawing.Size(306, 20);
        this.textBox3.TabIndex = 5;
        this.textBox3.Tag = @"XC";
        //
        //label3
        //
        this.label3.AutoSize = true;
        this.label3.Text = @"";
        this.label3.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.label3.ForeColor = System.Drawing.Color.FromName("Black");
        this.label3.Location = new System.Drawing.Point(12, 100);
        this.label3.Name = @"label3";
        this.label3.Size = new System.Drawing.Size(100, 13);
        this.label3.TabIndex = 4;
        this.label3.Tag = @"XC";
        //
        //textBox2
        //
        this.textBox2.UseForCustoming = true;
        this.textBox2.CustomingName = @"";
        this.textBox2.BackColor = System.Drawing.Color.FromName("White");
        this.textBox2.ForeColor = System.Drawing.Color.FromName("Black");
        this.textBox2.Location = new System.Drawing.Point(15, 71);
        this.textBox2.Name = @"textBox2";
        this.textBox2.Size = new System.Drawing.Size(306, 20);
        this.textBox2.TabIndex = 3;
        this.textBox2.Tag = @"XC";
        //
        //label2
        //
        this.label2.AutoSize = true;
        this.label2.Text = @"";
        this.label2.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.label2.ForeColor = System.Drawing.Color.FromName("Black");
        this.label2.Location = new System.Drawing.Point(12, 55);
        this.label2.Name = @"label2";
        this.label2.Size = new System.Drawing.Size(82, 13);
        this.label2.TabIndex = 2;
        this.label2.Tag = @"XC";
        //
        //textBox1
        //
        this.textBox1.UseForCustoming = true;
        this.textBox1.CustomingName = @"";
        this.textBox1.BackColor = System.Drawing.Color.FromName("White");
        this.textBox1.ForeColor = System.Drawing.Color.FromName("Black");
        this.textBox1.Location = new System.Drawing.Point(15, 25);
        this.textBox1.Name = @"textBox1";
        this.textBox1.Size = new System.Drawing.Size(306, 20);
        this.textBox1.TabIndex = 1;
        this.textBox1.Tag = @"XC";
        //
        //label1
        //
        this.label1.AutoSize = true;
        this.label1.Text = @"";
        this.label1.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.label1.ForeColor = System.Drawing.Color.FromName("Black");
        this.label1.Location = new System.Drawing.Point(12, 9);
        this.label1.Name = @"label1";
        this.label1.Size = new System.Drawing.Size(51, 13);
        this.label1.Tag = @"XC";
        //
        //mainForm
        //
        this.AutoScaleDimensions = new SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(455, 275);
        this.BackColor = System.Drawing.Color.FromArgb(-986896);
        this.MaximizeBox = false;
        this.ShowIcon = false;
        this.Size = new System.Drawing.Size(349, 276);
        this.Text = @"";
        this.TopLevel = false;
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.AllowDrop = true;
        this.ForeColor = System.Drawing.Color.FromName("Black");
        this.Name = @"opForm";
        this.Tag = @"";
        this.Controls.Add(checkBox3);
        this.Controls.Add(checkBox2);
        this.Controls.Add(checkBox1);
        this.Controls.Add(button1);
        this.Controls.Add(textBox3);
        this.Controls.Add(label3);
        this.Controls.Add(textBox2);
        this.Controls.Add(label2);
        this.Controls.Add(textBox1);
        this.Controls.Add(label1);
        this.ResumeLayout(false);
        this.PerformLayout();
    }
}

下面是创建表单的代码:

代码语言:javascript
运行
复制
static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
        }
    }

我不明白这个密码有什么问题。也许有人能帮我。切斯特

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-29 20:12:51

首先,我认为ClientSize和Size的值是相互冲突的。事实上,我相信只有一个应该被设定,而最后一个将被设定将获胜。

但是,阻止窗口出现的一行是:

代码语言:javascript
运行
复制
this.TopLevel = false;

忽略它或将其设置为true (默认值),您的窗口就会显示得很好。

来自MSDN

顶层窗体是没有父窗体或其父窗体为桌面窗口的窗口。顶层窗口通常用作应用程序中的主要窗体。

因此,如果DesignSurface将其设置为false,您可能已经告诉它,您正在创建的不是主窗体。我相信MDI子窗口已经设置为false了,但我不确定,MDI已经很久了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27204917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档