WinFrom复习

WinFrom程序属于桌面应用程序,像我们常用的QQ或迅雷,这些都是桌面应用程序,那么这些桌面应用程序都有一个什么特点呢?就是,我们都需要运行一个.exe的可执行程序,然后它会出来一个类似于Windows窗体的图形用户界面。

而我们的web应用程序,比如淘宝网,我们登录淘宝后,购物,充值等等,这些操作都是在浏览器中进行,而这样的程序也是用代码写出来的,而开发出来的这种程序,挂在网站上,不需要用户去下载,去点击.exe可执行程序的应用程序,我们叫做Web应用程序。

WinFrom当中有下面这些控件:

TextBoxTimerCheckBoxTreeViewGroupBoxLabelButtonRadioButtonCheckBoxListRadioButtonListFormPictureBoxComboBoxPanel......

我要求大家把这些控件的操作全部掌握,等这些你都熟悉了,那么剩下的其它控件的操作跟上面这些控件的操作都是类似的。原理一样,大家要做到,一通百通。像你们以后学习ASP.NET的分页,那么会有很多的分页控件,那么这时候你只需要看下它的文档说明就会用了。当然,如果你感觉他们的控件用的不爽,自己开发一些第三方控件,赚点烟钱。

那么下面我们做一个简易计算器,来复习下我们的WinFrom的东西。

 

===========================================

我们先画出啦界面:

WinFrom复习

 

然后我们需要设置下ComboBox的一个属性,DropDownStyle为DropDownList,这样用户就不能随便更改ComboBox里面的值了。

=========================================================

然后我们写代码:

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

namespace _02简易计算器
{
    public partial class simpleCalculator : Form
    {
        public simpleCalculator()
        {
            InitializeComponent();
        }

        private void btnCal_Click(object sender, EventArgs e)
        {
            if (comboxOperator.SelectedIndex==0)
            {
              DialogResult result =  MessageBox.Show("请输入一个操作符");

            }
            else
            {
                int num1 = int.Parse(tbNum1.Text);
                int num2 = int.Parse(tbNum2.Text);
                switch (comboxOperator.Text)
                {
                    case "+":
                        lbResult.Text = (num1 + num2).ToString();
                        break;
                    case "-":
                        lbResult.Text = (num1 - num2).ToString();
                        break;
                    case "*":
                        lbResult.Text = (num1 * num2).ToString();
                        break;
                    case "/":
                        lbResult.Text = (num1 / num2).ToString();
                        break;
                    case "%":
                        lbResult.Text = (num1 % num2).ToString();
                        break;
                    default:
                        break;
                }

            }
           
        }

        private void simpleCalculator_Load(object sender, EventArgs e)
        {
            comboxOperator.SelectedIndex = 0;
        }
    }
}

 

 


原文链接: http://blog.csdn.net/mypc2010/article/details/8013058

你可能感兴趣的:(WinFrom复习)