我先用截图展示一下我的实验成果
下图为整体的样式
以下是依次展示一下加减乘除(加减乘都差不多所以就展示一个,除单独展示),以及 1/x、C
因为截图的话不够直观,所以决定用视频,然而只支持少数视频格式,为了这个,我还向b站投稿了,就为了转为b站视频的格式,顺便也记录一下我的学习。想不到我的up主生涯会从这开始。。
一个记录计算机学习的小视频
我以为是要下载,再放上来。搞了老半天,原来只要复制连接即可。
代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
[video(video-FFqfmSNa-1588992212265)(type-bilibili)(url-https://player.bilibili.com/player.html?aid=668064612)(image-https://i-blog.csdnimg.cn/blog_migrate/064ac45bbe84ff4a5f14b006a238d22a.jpeg)(title-一个记录计算机学习的小视频)]
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double i,j,k;
string x,y=""; /* x用来记录使用的运算符,y用来标记 1/x */
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text += "2";
}
private void button3_Click(object sender, EventArgs e)
{
textBox1.Text += "3";
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.Text += "4";
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.Text += "5";
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.Text += "6";
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Text += "7";
}
private void button12_Click(object sender, EventArgs e)
{
textBox1.Text += "8";
}
private void button13_Click(object sender, EventArgs e)
{
textBox1.Text += "9";
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text += "0";
}
private void button4_Click(object sender, EventArgs e) /* / */
{
i = Convert.ToDouble(textBox1.Text);
textBox1.Text = "";
x = "/";
}
private void button8_Click(object sender, EventArgs e) /* * */
{
i = Convert.ToDouble(textBox1.Text);
textBox1.Text = "";
x = "*";
}
private void button11_Click(object sender, EventArgs e) /* 1/ */
{
textBox1.Text += "1/";
y = "/";
}
private void button14_Click(object sender, EventArgs e) /* - */
{
i = Convert.ToDouble(textBox1.Text);
textBox1.Text = "";
x = "-";
}
private void button18_Click(object sender, EventArgs e) /* + */
{
i = Convert.ToDouble(textBox1.Text);
textBox1.Text = "";
x = "+";
}
private void button17_Click(object sender, EventArgs e) /* . */
{
textBox1.Text += ".";
}
private void button15_Click(object sender, EventArgs e) /* = */
{
if(y=="/")
{
string h,c;
h = textBox1.Text;
h=h.Substring(2, h.Length-2);
j = Convert.ToDouble(h);
y = "";
k = 1 / j;
textBox1.Text = k.ToString();
}
else
{
j = Convert.ToDouble(textBox1.Text);
if (x == "+")
{
k = i + j;
textBox1.Text = k.ToString();
}
else if (x == "-")
{
k = i - j;
textBox1.Text = k.ToString();
}
else if (x == "*")
{
k = i * j;
textBox1.Text = k.ToString();
}
else if (x == "/")
{
if (j != 0)
{
k = i / j;
textBox1.Text = k.ToString();
}
else
{
MessageBox.Show("除数不能为零");
textBox1.Text = "";
}
}
else
{
textBox1.Text = i.ToString();
}
}
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.Text = ""; /* C */
}
}
}
我是学了java的,但当时只带过了一下可视化操作,我没记住,书也没带。所以就决定用C#,顺便学习一下新知识,学会操作新软件。下载Visual Studio的时候教程没找好,导致下了两遍。。现在就和已学的语言建立了联系,做的也比较有效率。
唯一一个就是当时用到 Substring(x, y)是时候一直绕圈子,我一直以为x是起始位置,y是结束位置,然后就一直报错:“索引和长度必须引用该字符串内的位置。” 后来发现,y是指要截取的长度。知识点又增加了,实验果然比较直观。