奥萨瓦·本·萨卡

导航

C#初学第十五天

1. 复习
常用控件属性
Name 标识该对象的名称
BackColor组件的背景颜色
BackgroundImage控件的背景图像
ForeColor组件的前景颜色 主要显示文本
Image控件显示图像
TabIndex占用Tab键索引
TabStop 为Tab键控件提供焦点
Text与控件关联的文本
TextAlingn显示文本的对齐方式
Visible确定该控件是可见的还是隐藏的
ControlBox确定窗体是否有"控件/系统"菜单框
Cursor指针移过该控件时显示的光标
Enabled指示是否启用控件
Font显示控件中文本的字体
FormBorderStyle窗体边框和标题栏的外观行为
Locked确定是否可以移动控件或调整控件大小
MaximizeBox标题栏的右上角是否有最大化框
MinimizeBox标题栏的右上角是否有最小化框
ShowIntaskbar窗体是否出现在任务栏

 

2. Winform窗体
Button 控件 按钮
Label控件 文本显示信息
LinkLabel控件 标签
PictureBox控件 图片
TxtBox控件 用户输入文本
Timer控件 间隔引发事件的控件

3. 初始化窗体有三种方法
在属性对话框中修改
在构造函数里修改
在窗体的Load事件中修改
4. Image通过FromFile可以获得图片
5. 通过Application.StartupPath可以得到当前运行的路径(没有最后一个"\")
6. 事件
Click 单击组件的时候发生 常用
MouseClick 鼠标事件 常用
MouseDown
MouseEnter
MouseLeave
MouseUp

KeyDown 键事件
KeyUp
KeyPress
Enter
Leave
TextChanged 更改Text属性的值时引发的事件

 

 

public partial class Form1 : Form
{
int num = 1;
double res = 0;
string[] filep;
public Form1()
{
InitializeComponent();
}
private void btnjs_Click(object sender, EventArgs e)
{
res = Convert.ToDouble(txtc.Text)*Convert.ToDouble(txtk.Text);
txtmj.Text = res.ToString();
}

private void btnCler_Click(object sender, EventArgs e)
{
txtc.Clear();
txtk.Clear();
txtmj.Clear();
}

private void txtc_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar>'9'||e.KeyChar<'0'&&e.KeyChar!='\b'&&e.KeyChar!='.')
{
e.Handled = true;
}
if (e.KeyChar=='.'&&(txtc.Text==""||txtc.Text.Contains('.')))
{
e.Handled = true;
}
}

private void txtk_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar >'9'||e.KeyChar<'0'&&e.KeyChar!='\b'&&e.KeyChar!='.')
{
e.Handled = true;
}
if (e.KeyChar == '.' && (txtk.Text == "" || txtk.Text.Contains('.')))
{
e.Handled = true;
}
}

private void 不自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
{
txtwenben.WordWrap = true;
}

private void 自动换行ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
txtwenben.WordWrap = false;
}

private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
//System.IO.FileAttributes.
}

private void btnPrev_Click(object sender, EventArgs e)
{
if (num<1)
{
num = 41;
}
string pict = @"G:\C#应用图片\mmguoguo\" + num.ToString("00") + ".jpg";
pictureBox1.Image = Image.FromFile(pict);
labXs.Text = "当前图片为" + num.ToString("00") + ".jpg";
num--;
}

private void btnNext_Click(object sender, EventArgs e)
{
if (num>41)
{
num =1;
}
string pict = @"G:\C#应用图片\mmguoguo\" + num.ToString("00") + ".jpg";
pictureBox1.Image = Image.FromFile(pict);
labXs.Text = "当前图片为" + num.ToString("00") + ".jpg";
num++;
}

private void Form1_Load(object sender, EventArgs e)
{
labLj.Text += Application.StartupPath;
}

private void btnWej_Click(object sender, EventArgs e)
{
OpenFileDialog opf = new OpenFileDialog();
opf.Multiselect = true;
opf.Filter = "显示信息(exe程序)|*.exe|pdb格式|*.pdb|音乐格式|*.mp3";
opf.FilterIndex = 2;//显示第几个
opf.InitialDirectory = @"J:\";
opf.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
opf.Title = "显示信息";
if (opf.ShowDialog() == DialogResult.OK)
{
//string temp=opf.FileName;
filep = opf.FileNames;
foreach (string item in filep)
{
txtShow.Text += item + "\r\n";
}

}

}

private void btnDaoru_Click(object sender, EventArgs e)
{
//pictureBox1.Load(@"G:\C#应用图片\播放器皮肤\1184666896039_副本.jpg");
pictureBox1.ImageLocation = @"G:\C#应用图片\播放器皮肤\1184666896039_副本.jpg";
pictureBox1.Load();
}

private void timer1_Tick(object sender, EventArgs e)
{
labXing.Text = labXing.Text.Substring(1)+labXing.Text[0];
}
}

posted on 2011-11-24 00:05  奥萨瓦·本·萨卡  阅读(252)  评论(0编辑  收藏  举报