在 Java Swing 中,我们只需编写 Java 代码即可创建 GUI(例如在 Eclipse 中)。使用 NetBeans 工具箱将组件拖放到 UI 是可选的。
我想知道C#中是否有相同的概念。我可以将组件放入 GUI 中并仅通过编码来添加它们的行为吗?这样我会觉得我对我的应用程序有更多的控制权。
示例:我不想通过工具箱将“mousehover”添加到我的按钮!相反,我想自己编写代码。我知道在哪里可以找到代码,但这是我应该编写该行代码的唯一位置吗?
请在此比较 Java Swing 和 C#。
关于 C#:
为了让您运行C#
申请来自cmd
,需要执行以下步骤:
- Go to
C:\Windows\Microsoft.NET\Framework\v4.0.30319
文件系统上的位置并复制路径。
- 现在右键单击
Computer
转到属性。
- Under
System Properties
, 选择Advanced
选项卡,然后单击Environment Variables
.
- On
Environment Variables
under User Variables
, 选择New
.
- For
Variable Name
write CSHARP_HOME
或其他东西,尽管我使用相同的东西来进一步需要解释这一点。为了Variable Value
simply Paste
你复制的内容Step 1。单击“确定”。
- 再次执行Step 4, if
path
变量不存在,否则您可以简单地选择path
然后单击Edit
执行接下来的事情(放置后;(分号)在结束时Variable Value
和写%CSHARP_HOME%\
(或者使用你用过的Step 5))。这次为了Variable Name
write path
,并且对于Variable Value
use %CSHARP_HOME%\
并单击“确定”。
- Open
cmd
and type csc
and press ENTER, you might be able to see something like this as an output
- 现在考虑我正在这个位置为我的 CSharp 项目创建一个目录结构,如下所示(在文件系统上)
C:\Mine\csharp\command
。这里我在里面创建了两个文件夹command
文件夹。source and build.
- 现在从任何
Text Editor
创建一个小示例程序(我使用的是Notepad++),如下,另存为WinFormExample.cs
under source
文件夹 :
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CSharpGUI {
public class WinFormExample : Form {
private Button button;
public WinFormExample() {
DisplayGUI();
}
private void DisplayGUI() {
this.Name = "WinForm Example";
this.Text = "WinForm Example";
this.Size = new Size(150, 150);
this.StartPosition = FormStartPosition.CenterScreen;
button = new Button();
button.Name = "button";
button.Text = "Click Me!";
button.Size = new Size(this.Width - 50, this.Height - 100);
button.Location = new Point(
(this.Width - button.Width) / 3 ,
(this.Height - button.Height) / 3);
button.Click += new System.EventHandler(this.MyButtonClick);
this.Controls.Add(button);
}
private void MyButtonClick(object source, EventArgs e) {
MessageBox.Show("My First WinForm Application");
}
public static void Main(String[] args) {
Application.Run(new WinFormExample());
}
}
}
- Now type
csc /out:build\WinFormExample.exe source\WinFormExample.cs
(more info is given at the end, for compiler options)and press ENTER to compile as shown below :
- Now simply run it using
.\build\WinExample
, as shown below :
- 现在你的简单
GUI Application
已启动并正在运行:-)
请告诉我,我可以解释同样的事情Java
如果需要的话也可以:-)
有关更多信息Compiler Options
可以找到按字母顺序列出的 C# 编译器选项 http://msdn.microsoft.com/en-us/library/6ds95cz0%28v=vs.80%29.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)