首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在没有表单设计器的情况下开发UI软件?

在没有表单设计器的情况下开发UI软件?
EN

Stack Overflow用户
提问于 2014-01-24 17:11:26
回答 1查看 1.8K关注 0票数 1

我对开发像文本编辑之类的软件很感兴趣。

目前我知道如何在C#中开发软件的唯一方法是使用Visual的窗体设计器:http://i.imgur.com/oRAd6M4.png

在Java中,可以(而且我知道如何)这样做。

是否可以像在C#中那样(通过100%的代码)来开发软件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-25 01:38:42

是的很有可能。表单设计器只是一个视觉包装器,它在幕后生成代码。您可以使用WPF,这是一种UI设计的声明性方法。您也可以对WinForms进行同样的操作。下面是一个用手工编写的简单表单示例。不过,除了练习之外,我不明白为什么您会想要在非平凡的UI应用程序中这样做。

代码语言:javascript
复制
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文件,该文件包含与上面相同的初始化代码。

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

https://stackoverflow.com/questions/21338447

复制
相关文章

相似问题

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