| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:照书编了个计算器,不会修改
只看楼主 加入收藏
Vergil_X
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2011-10-7
结帖率:100%
收藏
已结贴  问题点数:4 回复次数:1 
照书编了个计算器,不会修改
是用Form.cs和Form.cs[Design]做的,添加了一些button,然后双击各个button添加代码


程序代码:
using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace calculator
{
    public void PressNumber(string KeyType)
{
     
     SelectWays=0;
     Number1="";
     Number2="";
     Screen.Text="";
     NextInput=0;
}
if(SelectWays==0&&NextInput==0)
{
     Screen.Text="";
     NextInput=-1;
}
if(Screen.Text.Length<15)
{
     Screen.Text+=Keytype;
}
if((SelectWays==10||SelectWays==100)&&NextInput==2)
{
    Number2=Screen.Text;
}
    public void Operate(String op)
{
    Op_Add=false;
    Op_Minus=false;
    Op_Mul=false;
    Op_Div=false;
    switch(op)

 {
    case"div":
    Op_Div=true;
    break;
    case"mul":
    Op_Mul=true;
    break;
    case"minus":
    Op_Minus=true;
    break;
    case"add":
    Op_Add=true;
    break;

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

        private void progressBar1_Click(object sender, EventArgs e)
        {

        }

       

        

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        

        private void button16_Click(object sender, EventArgs e)
        {
            if (Screen.Text != "0" && Screen.Text.Length < 15)
                PressNumber("0");
        }

        private void button9_Click(object sender, EventArgs e)
        {
            PressNumber("1");
        }

        private void button11_Click(object sender, EventArgs e)
        {
            PressNumber("2");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            PressNumber("3");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            PressNumber("4");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            PressNumber("5");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            PressNumber("6");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PressNumber("7");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            PressNumber("8");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            PressNumber("9");
        }

        private void button14_Click(object sender, EventArgs e)
        {
            ShowResult();
        }
            public void ShowResult()
            {
                if(SelectWays==100||SelectWays==11)
                {
                    if(Op_Div==true)
                    {
                    }
                    if(Op_Div==true)
                    {
                        Screen.Text="1";
                    }
                    else if(Op_Mul==true)
                    {
                        Screen.Text=Convert.ToString(Convert.ToDouble(Screen.Text)*Convert.ToDouble(Number1));
                    }
                    else if(Op_Minus==true)
                    {
                        Screen.Text=Convert.ToString(Convert.ToDouble(Screen.Text)+oConvert.ToDouble(Number1));
                    }
                }
                Number2="";
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            Operate("add");
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Operate("minus");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Operate("mul");
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Operate("div");
        }

        private void button17_Click(object sender, EventArgs e)
        {
            Clear();
            public void Clear()
            {
                Screen.Text="0";
                Number1="";
                Number2="";
                Op_Mul=false;
                Op_Div=false;
            }

        private void button15_Click(object sender, EventArgs e)
        {
            foreach(char point in Screen.Text)
            {
                if(point=='.')
                {
                    IsReal=true;
                    break;
                }
                if(!IsReal)
                {
                    if(Screen.Text!="0")
                        PressNumber(".");
                }
                else
                {
                    Screen.Text="";
                    PressNumber("0.");
                }
                IsReal=true;
            }
        }
    }




图片附件: 游客没有浏览图片的权限,请 登录注册


小弟刚刚接触C#,不会修改,报的错基本都是这两个:
Error    9    Expected class, delegate, enum, interface, or struct   
Error    33    'System.Windows.Forms.Screen' does not contain a definition for 'Text'   

求教!!!!!
搜索更多相关主题的帖子: 计算器 button 
2011-10-25 21:50
chtml小兵
Rank: 5Rank: 5
等 级:职业侠客
威 望:3
帖 子:126
专家分:314
注 册:2011-10-3
收藏
得分:3 
我自己也做了一个计算器,不过程序不成熟,我好好看看你的这个代码

做个程序员吧,在里面找到万千对象~~~~~~
百名书阁(bmbook.5d6d)__最全IT图书免费下载中心
net图书资料/软件工具大全____免费!!!
各种编程语言教程应有尽有
2011-10-26 12:37
快速回复:照书编了个计算器,不会修改
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037853 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved