如何创建一个Windows软件

分享如何在Windows11 Pro Insider Build 22H2环境下,使用Visual Studio Community 2022创建并运行第一个Windows程序,包括设置步骤和关键代码段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

很久以前我创造了一个Windows软件,我今天把这个方法分享给大家。

我的系统:

Edition	Windows 11 Pro Insider Preview
Version	22H2
Installed on	‎7/‎30/‎2022
OS build	25169.1000
Experience	Windows Feature Experience Pack 1000.25169.1000.0

用到的软件:

一个好用的PC或者苹果也阔以。

一个浏览器

一个Visual Studio,MAC朋友们用Visual Studio for MAC。

提前说一下:

本人没有Mac电脑,步骤大同小异。

开干:

1、下载Visual Studio or Visual Studio For MAC

        访问Visual Studio: IDE and Code Editor for Software Developers and Teams,看到这个:

66927b35ed494f00a853282d356ce011.png

         往下拉,看见这个:

25b4605e8502416c95989cd22e3707e1.png

        Windows下载Visual Studio Community 2022(在下拉栏里)

        苹果用户直接下载Visual Studio for Mac(直接点按钮)

        下载完毕以后按照步骤走到这里:

        492b8510f3d94d61a43bb60e969d9c2d.png

        勾选.NET desktop development,可以在Installation Location里面修改安装路径。

        点击Install,看到这样既可:

50bac8e7904b4e02a19b3694369a4deb.png (我这个是更新)

        等待安装完毕即可。

2、打开软件并配置。

        1、打开软件

        2、跟着步骤走即可。

        3、然后重启电脑(下载的文件太多了)

3、开始创建项目并创建第一个Windows程序。

         打开VS

560774d42eb748359900c82fb953ed19.png

        点击Create a new project,进到这里:

4b56a079674642528cad81132119a6f5.png

        点击Windows Forms App (.NET Framework) 点击Next

48d9b2d181bc464aa24909f09372dbe5.png

        Project name随便设

        Location随便选

        Solution name建议勾选下面的Place solution and project in the same directory

        剩下的默认

        点击Create

03778f0c83444b62814e5e129e40e366.png

左面的toolbox是工具箱,方便拖拽使用,右上面是Git Changes and Solution Explorer,这里点击Solution Explorer即可。有下面你们可以自己看一看(有中文版的官方)汉化很完全。

在工具箱里,把一个Checkbox拖出来

04bb765046d54b46ae4d043f1c2c219e.png

转到右下角,找到Right to left,选Yes,把Text改成quit。 

a554e129401c43d6a6bb56ba64673b90.png

双击checkbox,看到这个:

0717b17d1d5542ff9cc725812091f27e.png

这个是代码界面,我们可以编代码,这个是按钮的代码。

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{

}

 这里的意思是当按钮按下是所作的事情,相当于

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a == b){
        //上面的代码相当于这里
    }
    return 0;
}

这次搞一个简单点的,直接退出程序。

退出程序也有说到

第一种是在后台运行的退出程序,另一种是直接给你干干净净的结束关于这个程序的所有进程,我们选第二个。

这个是代码:

System.Environment.Exit(0);

这个代码就能实现我上面说的第二种退出程序的样子。

整个代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
        }
    }
}

运行一下:

666ba40fd84f485eb3aa500ca51a9d87.png

点击复选框后:

 程序结束。

成功!

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱波音的肥友

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值