----------------------
ASP.Net+Android+IOS开发、
.Net培训、期待与您交流! ----------------------
一、WinForm
1、加计算器练习:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace lianxi
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text;
string str2 = textBox2.Text;
int i1,i2,sum;
if (!int.TryParse(str1, out i1))
{
MessageBox.Show("error");
return;
}
else
{
i1 = Convert.ToInt32(str1);
}
if (!int.TryParse(str2, out i2))
{
MessageBox.Show("error");
return;
}
else
{
i2 = Convert.ToInt32(str2);
}
sum = i1 + i2;
textBox3.Text = sum.ToString();
}
}
}
2、身份证校验练习:
1)不能用tryparse,超出int范围;
2)提取身份证出生年,用substring(a,b)方法,从第a位开始b个数;
3、字符左滚动:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace lianxi2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text;
char a = str1[0];
string str2 = str1.Substring(1);
textBox1.Text = str2 + a;
}
}
}
4、trim()方法:去掉字符串前后空格。
二、文本框
1、PasswordChar属性:密码输入显示。
2、mulitline属性:多行显示。
3、对于多行显示:AppendText方法,可以连续显示多行,用text.line可以读取一行字符串;
三、下拉列表
1、通过Items属性加入下拉列表内容。
2、通过DropDowmStyles属性改变下拉列表风格。
3、选择下拉列表中的某一项,用selectedIndex方法读取序号,用selectedItem方法读取内容。
---------------------- ASP.Net+Android+IOS开发、 .Net培训、期待与您交流! ----------------------