Mah*_*aly 2 c# eclipse swing netbeans visual-studio
在Java Swing中,我们可以创建仅使用Java编码的GUI(例如在Eclipse中).使用NetBeans的工具箱将组件拖放到UI是可选的.
我想知道C#中是否有相同的概念.我可以将我的组件放入我的GUI并仅使用编码添加它们的行为吗?这样我觉得我可以更好地控制我的应用程序.
示例:我不想在工具箱中添加"mousehover"到我的按钮!相反,我想自己编写代码.我知道在哪里可以找到代码,但它是我应该编写那行代码的唯一地方吗?
请将Java Swing与C#进行比较.
为了C#从a 运行应用程序cmd,需要执行以下步骤:
C:\Windows\Microsoft.NET\Framework\v4.0.30319文件系统上的位置并复制路径.Computer转到"属性".System Properties,选择AdvancedTab,然后单击Environment Variables.Environment Variables下面User Variables选择New.Variable Name写CSHARP_HOME或其他东西,虽然我使用相同的进一步需要来解释这一点.对于Variable Value只是Paste你在复制的第1步.单击确定.path变量不存在,否则你可以简单地选择path,然后单击Edit以执行下一个操作(在放置;(分号)结束后Variable Value写入%CSHARP_HOME%\(或使用您在步骤5中使用的内容) ).这次Variable Name写入path和Variable Value使用%CSHARP_HOME%\,然后单击确定.cmd并输入csc并按下ENTER,您可能会看到类似这样的输出

C:\Mine\csharp\command.我在这里创建了两个文件command夹.来源和构建.Text Editor创建一个小样本程序(我使用的是Notepad ++),如下所示,将其保存WinFormExample.cs在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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
csc /out:build\WinFormExample.exe source\WinFormExample.cs(对于编译器选项,最后给出更多信息)并按下ENTER编译,如下所示:

.\build\WinExample,如下所示:

GUI Application运行起来了:-)请告诉我,我也可以解释同样的事情Java,如果需要的话:-)
有关更多信息Compiler Options可能被发现在按字母顺序列出的C#编译器选项
| 归档时间: |
|
| 查看次数: |
9666 次 |
| 最近记录: |