using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
namespace s_h_c
{
/// <summary>
/// form1 的摘要说明。
/// </summary>
///
public class form1 : system.windows.forms.form
{
private system.windows.forms.groupbox groupbox1;
private system.windows.forms.label label1;
private system.windows.forms.label label2;
private system.windows.forms.textbox textbox1;
private system.windows.forms.textbox textbox2;
private system.windows.forms.groupbox groupbox2;
private system.windows.forms.label label3;
private system.windows.forms.label label4;
private system.windows.forms.label label5;
private system.windows.forms.textbox textbox3;
private system.windows.forms.textbox textbox4;
private system.windows.forms.textbox textbox5;
private system.windows.forms.button button1;
private system.windows.forms.button button2;
private system.windows.forms.label label6;
private system.windows.forms.timer timer1;
private system.componentmodel.icontainer components;
public form1()
{
//
// windows 窗体设计器支持所必需的
//
initializecomponent();
//
// todo: 在 initializecomponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}
#region windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.components = new system.componentmodel.container();
this.groupbox1 = new system.windows.forms.groupbox();
this.textbox2 = new system.windows.forms.textbox();
this.textbox1 = new system.windows.forms.textbox();
this.label2 = new system.windows.forms.label();
this.label1 = new system.windows.forms.label();
this.button1 = new system.windows.forms.button();
this.groupbox2 = new system.windows.forms.groupbox();
this.button2 = new system.windows.forms.button();
this.textbox5 = new system.windows.forms.textbox();
this.textbox4 = new system.windows.forms.textbox();
this.textbox3 = new system.windows.forms.textbox();
this.label5 = new system.windows.forms.label();
this.label4 = new system.windows.forms.label();
this.label3 = new system.windows.forms.label();
this.label6 = new system.windows.forms.label();
this.timer1 = new system.windows.forms.timer(this.components);
this.groupbox1.suspendlayout();
this.groupbox2.suspendlayout();
this.suspendlayout();
//
// groupbox1
//
this.groupbox1.controls.add(this.textbox2);
this.groupbox1.controls.add(this.textbox1);
this.groupbox1.controls.add(this.label2);
this.groupbox1.controls.add(this.label1);
this.groupbox1.controls.add(this.button1);
this.groupbox1.location = new system.drawing.point(24, 16);
this.groupbox1.name = "groupbox1";
this.groupbox1.size = new system.drawing.size(288, 112);
this.groupbox1.tabindex = 0;
this.groupbox1.tabstop = false;
this.groupbox1.text = "ascii转换";
//
// textbox2
//
this.textbox2.location = new system.drawing.point(112, 64);
this.textbox2.name = "textbox2";
this.textbox2.size = new system.drawing.size(80, 21);
this.textbox2.tabindex = 3;
this.textbox2.text = "";
//
// textbox1
//
this.textbox1.location = new system.drawing.point(112, 24);
this.textbox1.name = "textbox1";
this.textbox1.size = new system.drawing.size(80, 21);
this.textbox1.tabindex = 2;
this.textbox1.text = "";
this.textbox1.textchanged += new system.eventhandler(this.textbox1_textchanged);
//
// label2
//
this.label2.location = new system.drawing.point(8, 72);
this.label2.name = "label2";
this.label2.size = new system.drawing.size(72, 24);
this.label2.tabindex = 1;
this.label2.text = "ascii码";
//
// label1
//
this.label1.location = new system.drawing.point(8, 24);
this.label1.name = "label1";
this.label1.size = new system.drawing.size(80, 24);
this.label1.tabindex = 0;
this.label1.text = "字符";
//
// button1
//
this.button1.location = new system.drawing.point(200, 40);
this.button1.name = "button1";
this.button1.tabindex = 2;
this.button1.text = "确定";
this.button1.click += new system.eventhandler(this.button1_click);
//
// groupbox2
//
this.groupbox2.controls.add(this.button2);
this.groupbox2.controls.add(this.textbox5);
this.groupbox2.controls.add(this.textbox4);
this.groupbox2.controls.add(this.textbox3);
this.groupbox2.controls.add(this.label5);
this.groupbox2.controls.add(this.label4);
this.groupbox2.controls.add(this.label3);
this.groupbox2.location = new system.drawing.point(24, 152);
this.groupbox2.name = "groupbox2";
this.groupbox2.size = new system.drawing.size(288, 144);
this.groupbox2.tabindex = 1;
this.groupbox2.tabstop = false;
this.groupbox2.text = "数字进制转换器";
//
// button2
//
this.button2.location = new system.drawing.point(208, 56);
this.button2.name = "button2";
this.button2.size = new system.drawing.size(64, 24);
this.button2.tabindex = 6;
this.button2.text = "确定";
this.button2.click += new system.eventhandler(this.button2_click);
//
// textbox5
//
this.textbox5.location = new system.drawing.point(120, 104);
this.textbox5.name = "textbox5";
this.textbox5.size = new system.drawing.size(80, 21);
this.textbox5.tabindex = 5;
this.textbox5.text = "";
//
// textbox4
//
this.textbox4.location = new system.drawing.point(120, 64);
this.textbox4.name = "textbox4";
this.textbox4.size = new system.drawing.size(80, 21);
this.textbox4.tabindex = 4;
this.textbox4.text = "";
//
// textbox3
//
this.textbox3.location = new system.drawing.point(120, 24);
this.textbox3.name = "textbox3";
this.textbox3.size = new system.drawing.size(80, 21);
this.textbox3.tabindex = 3;
this.textbox3.text = "";
//
// label5
//
this.label5.location = new system.drawing.point(16, 112);
this.label5.name = "label5";
this.label5.size = new system.drawing.size(88, 24);
this.label5.tabindex = 2;
this.label5.text = "十六进制";
//
// label4
//
this.label4.location = new system.drawing.point(16, 72);
this.label4.name = "label4";
this.label4.size = new system.drawing.size(88, 24);
this.label4.tabindex = 1;
this.label4.text = "二进制";
//
// label3
//
this.label3.location = new system.drawing.point(16, 24);
this.label3.name = "label3";
this.label3.size = new system.drawing.size(88, 24);
this.label3.tabindex = 0;
this.label3.text = "十进制";
//
// label6
//
this.label6.location = new system.drawing.point(88, 304);
this.label6.name = "label6";
this.label6.size = new system.drawing.size(208, 16);
this.label6.tabindex = 2;
//
// timer1
//
this.timer1.tick += new system.eventhandler(this.timer1_tick);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(342, 323);
this.controls.add(this.label6);
this.controls.add(this.groupbox2);
this.controls.add(this.groupbox1);
this.name = "form1";
this.text = "数据转换器";
this.load += new system.eventhandler(this.form1_load);
this.groupbox1.resumelayout(false);
this.groupbox2.resumelayout(false);
this.resumelayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
///
string str;
[stathread]
static void main()
{
application.run(new form1());
}
private void form1_load(object sender, system.eventargs e)
{
timer1.start();
}
//调用系统时间
void datetimetostring()
{
datetime now=datetime.now;
string format;
label6.text="";
format="yyyy-mm-dd hh:mm:ss";
label6.text=now.tostring(format);
}
private void button1_click(object sender, system.eventargs e)
{
//转ascii码
str=textbox1.text;
int a;
if(str.length>1)
messagebox.show("error,please input the char!");
a=(int)str[0];
textbox2.text=a.tostring();
}
private void textbox1_textchanged(object sender, system.eventargs e)
{
}
private void button2_click(object sender, system.eventargs e)
{
if(textbox3.text!="")
{
t_s();
t_tw();
}
else if(textbox4.text!="")
{
tw_t();
tw_s();
}
}
//由十进制转十六进制
void t_s()
{
string ten;
int b=0;
ten=textbox3.text;
for(int i=0;i<ten.length;i++)
{
int c=1;
for(int j=ten.length-i-1;j>0;j--)
{
c=c*10;
}
if(ten[i]>57 || ten[i]<48)
messagebox.show("错,输入的应该是十进制整数。");
else
b=b+((int)ten[i]-48)*c;
c=1;
}
textbox5.text=b.tostring("x8");
}
//由十进制转二进制
void t_tw()
{
int b=0;
string ten;
int c=1;
ten=textbox3.text;
for(int i=0;i<ten.length;i++)
{
for(int j=ten.length-i-1;j>0;j--)
{
c=c*10;
}
b=b+((int)ten[i]-48)*c;
c=1;
}
textbox4.text=convert.tostring(b,2);
}
//二进制转十进制
void tw_t()
{
string two;
two=textbox4.text;
int p=convert.toint32(two,2);
textbox3.text=p.tostring();
}
//二进制转十六进制
void tw_s()
{
string two;
two=textbox4.text;
int s=convert.toint32(two,2);
textbox5.text=s.tostring("x8");
}
private void timer1_tick(object sender, system.eventargs e)
{
datetimetostring();
}
}
}