[中秋]宇宙第一 IDE Visual Studio 了解一下

2022-10-15,,,,

官网

文档

第一个wpf桌面应用程序

安装visual studio

创建应用程序项目

工作区大概长这样子

写代码测试

  • 编辑mainwindow.xaml(类似安卓开发的xml语言)

在grid布局中添加

<textblock horizontalalignment="left" margin="252,47,0,0" textwrapping="wrap" text="select a message option and then choose the display button." verticalalignment="top"/>
        <radiobutton x:name="hellobutton" content="hello" ischecked="true" horizontalalignment="left" margin="297,161,0,0" verticalalignment="top" height="30.24" width="78.107"/>
        <radiobutton x:name="goodbyebutton" content="goodbye" horizontalalignment="left" margin="488,161,0,0" verticalalignment="top"/>
        <button content="display" click="button_click_1" horizontalalignment="left" height="40.061" margin="346.107,245.449,0,0" verticalalignment="top" width="201.689"/>

(可进行拖拽,放大缩小的图形化操作)

  • 在mainwindow.xmal.ca添加按钮事件

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows;
using system.windows.controls;
using system.windows.data;
using system.windows.documents;
using system.windows.input;
using system.windows.media;
using system.windows.media.imaging;
using system.windows.navigation;
using system.windows.shapes;

namespace wpfapp1
{
    /// <summary>
    /// mainwindow.xaml 的交互逻辑
    /// </summary>
    public partial class mainwindow : window
    {
        public mainwindow()
        {
            initializecomponent();
        }

        private void button_click_1(object sender, routedeventargs e)
        {
                            if (hellobutton.ischecked == true)
                                {
                               messagebox.show("hello.","提示");
                                }
                           else if (goodbyebutton.ischecked == true)
                            {
                                messagebox.show("goodbye.","提示");
                            }
         }
    }
}

其中button_click_1与之前xaml中click对应

  • 启动


小结

c# 开发的wpf对于非专业的开发者可以作为编写小工具的加持,毕竟现在pc桌面开发市场并不景气。

但是抛开市场经济的影响,c#加标记语言的开发模式和android开发有着异曲同工之妙,殊途同归的设计除了适应场景上的不同,不知道是否会带来对于编程本身更加深刻的认知。

就像刚过中秋的月饼一样,如果摆在面前的有10种月饼,每种月饼有10个,但是只能吃十个,假设从来没有尝过月饼的你是否会每种都去尝试一下呢?

《[中秋]宇宙第一 IDE Visual Studio 了解一下.doc》

下载本文的Word格式文档,以方便收藏与打印。