C#入门:显示窗口

https://learn.microsoft.com/zh-cn/dotnet/api/system.windows.forms.form?view=windowsdesktop-10.0

hello.cs

cs 复制代码
using System.Windows.Forms;
using System.Drawing;

class Program {
    static void Main() {
	   Form form1 = new Form();   
	   Button button1 = new Button ();
	   Button button2 = new Button ();
	   button1.Text = "OK";   
	   button1.Location = new Point (10, 10);
	   button2.Text = "Cancel";   
	   button2.Location = new Point (button1.Left, button1.Height + button1.Top + 10);   
	   form1.Text = "My Dialog Box";   
	   form1.HelpButton = true;   
	   form1.FormBorderStyle = FormBorderStyle.FixedDialog;   
	   form1.MaximizeBox = false;   
	   form1.MinimizeBox = false;   
	   form1.AcceptButton = button1;   
	   form1.CancelButton = button2;   
	   form1.StartPosition = FormStartPosition.CenterScreen;
	   form1.Controls.Add(button1);   
	   form1.Controls.Add(button2);   
	   form1.ShowDialog();
    }
}

编译

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /target:exe /out:hello.exe hello.cs

运行

hello

相关推荐
波力海苔夹心脆6752 天前
C# WPF 资源字典详解:ResourceDictionary、MergedDictionaries 与自定义控件案例
开发语言·c#·wpf·入门教程·resource·资源字典
AI导出鸭PC端2 天前
Perplexity批量导出没有PDF模式?AI导出鸭插件补上最后一块拼图
人工智能·pdf·c#·ai导出鸭
Risehuxyc2 天前
C# 选用更流行的语言版本
c#
淡海水3 天前
09-04-内存-Unity原生对象生命周期
unity·c#·游戏引擎·gc
吴可可1233 天前
富怡CAD二次开发指南
c#
1-1=03 天前
C# IO和序列化
c#·.net·.netcore
寂寞的船3 天前
【Unity Bug挑战】第10期 SerializeReference 内存泄漏之谜
unity·c#·游戏引擎·bug
CSharp精选营3 天前
从控制台到「会动手」的 AI:用 Semantic Kernel 搭应用(小白教程)
c#·.net·ai agent·semantickernel·functioncalling
宝桥南山4 天前
.NET 11 - 尝试一下Blazor中的新特性SupplyParameterFromTempData
microsoft·微软·c#·asp.net·.net·.netcore
1-1=04 天前
C# 中 Lambda、Linq 与 Expression
c#·linq