public double numinput=0;
public bool dot = false;
if(textBox1.Text.Equals("0.")&& !dot) textBox1.Text="1";
else textBox1.Text = textBox1.Text+"1";
numinput = double.Parse(textBox1.Text);主要是dot在这里的用途不太理解。
public bool dot = false;
if(textBox1.Text.Equals("0.")&& !dot) textBox1.Text="1";
else textBox1.Text = textBox1.Text+"1";
numinput = double.Parse(textBox1.Text);主要是dot在这里的用途不太理解。
解决方案 »
- winform中怎样使DataGridView的某一列可以添加两个Button控件
- 客户端连数据库,是直连还是用socket?
- C# form 中显示Flash显示不出来
- winform 上传图片
- 大家给介绍一个好点的C#书,最好偏向C#操作数据库的.
- 程序在进程里不停止
- System.Windows.Forms.ListBox生成的窗口如何设计属性可以copy里面的数据?
- 如何读取Excel生成的XML文件?
- LINQ“操作失败:指定的转换无效”请大家帮忙
- 想做个花生分屏王一样的单屏多软件分屏的程序,有案例吗?
- C#写的dll能本能跨.net版本使用?
- 发现高手果然是不仅仅凭学历的!(和大家一起共勉)
估计是记录用户是否输入小数点的意思
找找其他赋值的地方是不是计算器的代码?
“0.”为默认值
用户如果按了“.”界面还是显示“0.”再按“1”就要合成“0.1”
如果没有按“.”就将是“1”
我不太懂那个bool dot =false; 在下面的语句中的含义,
还有if(textBox1.Text.Equals("0.")&& !dot) textBox1.Text="1";中的!dot的作用是什么啊
请赐教```
是不是“没有“点”的意思啊” 但是没有给dot赋值啊
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplicationTry
{
public partial class Form1 : Form
{
public double numinput=0;
public double onepart =0;
public char i;
public bool dot = false;
public double baifenhao; public Form1()
{
InitializeComponent();
}
private void buttonNum1_Click(object sender, EventArgs e)
{
if(textBox1.Text.Equals("0.")&& !dot) textBox1.Text="1";
else textBox1.Text = textBox1.Text+"1";
numinput = double.Parse(textBox1.Text);
} private void buttonNum2_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "2";
else textBox1.Text = textBox1.Text + "2";
numinput = double.Parse(textBox1.Text);
} private void buttonNum3_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "3";
else textBox1.Text = textBox1.Text + "3";
numinput = double.Parse(textBox1.Text);
} private void buttonNum4_Click(object sender, EventArgs e)
{
if(textBox1.Text.Equals("0.")&&!dot) textBox1.Text="4";
else textBox1.Text = textBox1.Text+"4";
numinput = double.Parse(textBox1.Text);
} private void buttonNum5_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "5";
else textBox1.Text = textBox1.Text + "5";
numinput = double.Parse(textBox1.Text);
} private void buttonNum6_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "6";
else textBox1.Text = textBox1.Text + "6";
numinput = double.Parse(textBox1.Text);
} private void buttonNum7_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "7";
else textBox1.Text = textBox1.Text + "7";
numinput = double.Parse(textBox1.Text);
} private void buttonNum8_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "8";
else textBox1.Text = textBox1.Text + "8";
numinput = double.Parse(textBox1.Text);
} private void buttonNum9_Click(object sender, EventArgs e)
{
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "9";
else textBox1.Text = textBox1.Text + "9";
numinput = double.Parse(textBox1.Text);
}
private void buttonNum0_Click(object sender, EventArgs e)
{
//textBox1.Text = textBox1.Text + "0";
//numinput = double.Parse(textBox1.Text);
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "0";
else textBox1.Text = textBox1.Text + "0";
numinput = double.Parse(textBox1.Text);
}
private void buttonNumDot_Click(object sender, EventArgs e)
{ if (!textBox1.Text.Contains(".") )textBox1.Text = textBox1.Text + ".";
dot = true;
// numinput = double.Parse(textBox1.Text);
} private void buttonNumEqual_Click(object sender, EventArgs e)
{
//textBox1.Text = (numinput + onepart).ToString(); // MessageBox.Show("分母不能为“0”", "HELP", MessageBoxButtons.OK, MessageBoxIcon.Error);
} private void buttonNumPlus_Click(object sender, EventArgs e)
{
onepart = double.Parse(textBox1.Text);
i = '+';
textBox1.Text = "";
}
private void buttonNumSubtraction_Click(object sender, EventArgs e)
{
onepart = double.Parse(textBox1.Text);
i = '-';
textBox1.Text = "";
} private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "0.";
dot = false;
} private void buttonNumMultiplication_Click(object sender, EventArgs e)
{
onepart = double.Parse(textBox1.Text);
i = '*';
textBox1.Text = "";
} private void buttonNumDivision_Click(object sender, EventArgs e)
{
onepart = double.Parse(textBox1.Text);
i = '/';
textBox1.Text = "";
} private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "0.";
} private void button2_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.Show();
} private void button3_Click(object sender, EventArgs e)
{
switch (i)
{
case '+': onepart = onepart + numinput; textBox1.Text = (onepart).ToString(); break;
case '-': onepart = onepart - numinput; textBox1.Text = (onepart).ToString(); break;
case '*': onepart = onepart * numinput; textBox1.Text = (onepart).ToString(); break;
case '/': if (numinput == 0)
{ MessageBox.Show("分母不能为“0”", "HELP", MessageBoxButtons.OK, MessageBoxIcon.Error); } else onepart = onepart / numinput; textBox1.Text = (onepart).ToString(); break; }
} private void buttonNumPrecentage_Click(object sender, EventArgs e)
{
numinput = numinput * 0.01;
if (textBox1.Text.Equals("0.") && !dot) textBox1.Text = "%";
else textBox1.Text = textBox1.Text + "%";
// numinput = double.Parse(textBox1.Text);
}
}
}