开发没有表单设计师的UI软件



我有兴趣开发诸如文本编辑器等软件。

我目前知道如何在C#开发软件的唯一方法是使用Visual Studio的表单设计师:https://i.stack.imgur.com/wvxli.png

在Java中,有可能(我知道)做到这一点。

是否可以在C#中开发软件,例如在Java中完成的方式(通过100%代码)。

是的,很可能。Forms Designer只是一个视觉包装器,可以在幕后生成代码。您可以使用是UI设计的声明性方法的WPF。您可以使用Winforms做同样的事情。这是一个简单的表单示例手工编写的示例。不过,除了练习外,我不明白为什么您想为非平凡的UI应用程序这样做。

namespace MyTestApp
{
    public static class Program
    {
        [System.STAThread]
        private static void Main ()
        {
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
            System.Windows.Forms.Application.Run(new MyForm());
        }
        public class MyForm: System.Windows.Forms.Form
        {
            private System.Windows.Forms.Button ButtonClose { get; set; }
            private System.Windows.Forms.RichTextBox RichTextBox { get; set; }
            public MyForm ()
            {
                this.ButtonClose = new System.Windows.Forms.Button();
                this.RichTextBox = new System.Windows.Forms.RichTextBox();
                this.ButtonClose.Text = "&Close";
                this.ButtonClose.Click += new System.EventHandler(ButtonClose_Click);
                this.Controls.Add(this.ButtonClose);
                this.Controls.Add(this.RichTextBox);
                this.Load += new System.EventHandler(MyForm_Load);
            }
            private void MyForm_Load (object sender, System.EventArgs e)
            {
                int spacer = 4;
                this.RichTextBox.Location = new System.Drawing.Point(spacer, spacer);
                this.RichTextBox.Size = new System.Drawing.Size(this.ClientSize.Width - this.RichTextBox.Left - spacer, this.ClientSize.Height - this.RichTextBox.Top - spacer - this.ButtonClose.Height - spacer);
                this.ButtonClose.Location = new System.Drawing.Point(this.ClientSize.Width - this.ButtonClose.Width - spacer, this.ClientSize.Height - this.ButtonClose.Height - spacer);
            }
            private void ButtonClose_Click (object sender, System.EventArgs e)
            {
                this.Close();
            }
        }
    }
}

另外,使用设计器时,请查看包含与上述相同初始化代码的FormName.designer.cs文件。

最新更新