我对开发像文本编辑之类的软件很感兴趣。
目前我知道如何在C#中开发软件的唯一方法是使用Visual的窗体设计器:http://i.imgur.com/oRAd6M4.png
在Java中,可以(而且我知道如何)这样做。
是否可以像在C#中那样(通过100%的代码)来开发软件。
发布于 2014-01-25 01:38:42
是的很有可能。表单设计器只是一个视觉包装器,它在幕后生成代码。您可以使用WPF,这是一种UI设计的声明性方法。您也可以对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文件,该文件包含与上面相同的初始化代码。
https://stackoverflow.com/questions/21338447
复制相似问题