C#-Winform窗体程序基础环境搭建

发布时间:2026/8/17 15:49:06
C#-Winform窗体程序基础环境搭建 一.创建csproj文件Project SdkMicrosoft.NET.Sdk PropertyGroup Version0.0.1/Version TargetFrameworksnet472/TargetFrameworks Platformsx64/Platforms OutputTypeWinExe/OutputType !--指定输出exe名称,输出exe路径-- DebugTypenone/DebugType DebugSymbolsfalse/DebugSymbols AppendTargetFrameworkToOutputPathfalse/AppendTargetFrameworkToOutputPath AppendRuntimeIdentifierToOutputPathfalse/AppendRuntimeIdentifierToOutputPath OutputPathD:\work/OutputPath /PropertyGroup !--指定使用C#接口-- ItemGroup Reference IncludeSystem / Reference IncludeSystem.Core / Reference IncludeSystem.Design / Reference IncludeSystem.Xml.Linq / Reference IncludeSystem.Data.DataSetExtensions / Reference IncludeMicrosoft.CSharp / Reference IncludeSystem.Data / Reference IncludeSystem.Deployment / Reference IncludeSystem.Drawing / Reference IncludeSystem.Net.Http / Reference IncludeSystem.Windows.Forms / Reference IncludeSystem.Xml / /ItemGroup /Project二.创建Test.cs[STAThread] public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form()); }三.添加控件public void AddWidget() { Label label new Label(); this.Controls.Add(label); }四.WinForm窗体事件回调Button button new Button(); button.Click OnOkButtonClicked; public void OnOkButtonClicked(object sender, EventArgs e) { MessageBox.Show(OK BUTTON CLICKED!, Warning); }五.窗体循环System.Windows.Forms.TimerTimer timer new Timer(); timer.Enabled true; timer.Interval 10; timer.Tick OnTick; timer.Start(); #重写OnTick函数 public void OnTick(object sender, EventArgs e) { }