using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
int M=0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)//计算由G转化为M的NTFS格式
{
int mm = 0;
double ZhuMian = 7.84423828125;
try
{
mm = int.Parse(this.textBox1.Text.ToString());
}
catch{
MessageBox.Show(mm + "为一个不合法字符,请输入一个数字!");
this.textBox1.Focus();
this.textBox1.Clear();
return;
}
float SRF = (float)mm;
double a = SRF * 1024 / ZhuMian;
// Double D1 = new Double(a);
int D= (int)a;
double zui = 0.0;
zui = a / D;
if (zui >= 0.5)
{
D++;
}
double c = D * ZhuMian;
M = (int)c;
double mzui = c / M;
if (mzui >= 0.5)
{
M++;
}
this.textBox3.Text=M.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
int cc=0;
try
{
cc = int.Parse(this.textBox2.Text.ToString());
}
catch {
MessageBox.Show(cc + "为一个不合法字符,请输入一个数字!");
this.textBox2.Focus();
this.textBox2.Clear();
return;
}
float SRN =(float)cc;
double MN = (SRN - 1) * 4 + 1024 * SRN;
this.textBox4.Text = MN.ToString();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
String text2 = this.textBox2.Text.ToString();
if(!text2.Equals("")){
this.button2.Enabled=true;
}
else if (text2.Equals(""))
{
return;
}
try {
int text22 = int.Parse(text2);
}catch{
MessageBox.Show(text2 + "为一个不合法字符,请输入一个数字!");
this.textBox2.Focus();
this.textBox2.Clear();
return;
}
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
String text = this.textBox1.Text.ToString();
if (!text.Equals("")) {
this.button1.Enabled=true;
}
else if (text.Equals("")) {
return;
}
try
{
int h = int.Parse(text);
}
catch{
MessageBox.Show(text+"为一个不合法字符,请输入一个数字!");
this.textBox1.Focus();
this.textBox1.Clear();
return;
}
}
private void clear(object sender, MouseEventArgs e)
{
this.textBox1.Clear();
this.textBox3.Clear();
return;
}
private void clear2(object sender, MouseEventArgs e)
{
this.textBox2.Clear();
this.textBox4.Clear();
return;
}
}
}
------------------------------------------------
我的第一个C#小程序,哈哈~~~