admin管理员组文章数量:1537048
1 PictureBox控件
- PictureBox控件可以显示来自位图、图标或者原文件,以及来自增强的元文件、Jpeg或GIF文件的图形。如果控件不足以显示整幅图像,则捡钱图像以适应控件的大小
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _1_PictureBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label3.Visible = false;
label4.Visible = false;
label5.Visible = false;
label6.Visible = false;
label7.Visible = false;
}
private void radioNomal_CheckedChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
label3.Visible = true;
label4.Visible = false;
label5.Visible = false;
label6.Visible = false;
label7.Visible = false;
}
private void radioStretchImage_CheckedChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
label3.Visible = false;
label4.Visible = true;
label5.Visible = false;
label6.Visible = false;
label7.Visible = false;
}
private void radioAutoSize_CheckedChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
label3.Visible = false;
label4.Visible = false;
label5.Visible = true;
label6.Visible = false;
label7.Visible = false;
}
private void radioCenterImage_CheckedChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
label3.Visible = false;
label4.Visible = false;
label5.Visible = false;
label6.Visible = true;
label7.Visible = false;
}
private void radioBZoom_CheckedChanged(object sender, EventArgs e)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
label3.Visible = false;
label4.Visible = false ;
label5.Visible = false;
label6.Visible = false;
label7.Visible = true ;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _1_PictureBox
{
public partial class showPicture : Form
{
public showPicture()
{
InitializeComponent();
}
public int i = 0; //图片索引参数
public string[] path = Directory.GetFiles(@"C:\Users\Admin\Desktop\Images\"); //Directory需要引入命名空间using System.IO
private void 图片查看器_Load(object sender, EventArgs e)
{
//设定图片如何在PictureBox中显示
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
//设定PicturBox默认显示图片
pictureBox1.Image = Image.FromFile(path[i]);
//获取指定文件夹下所有文件的全路径
//下面循环仅仅是验证获取的路径都是什么文件路径,与此示例功能无关
//foreach (string onePicturePath in path)
//{
// MessageBox.Show(onePicturePath); //是路径下所有的文件,不仅仅是图片文件
// //Console.WriteLine(onePicturePath); //不能空控制台输出
//}
}
private void button1_Click(object sender, EventArgs e)
{
i--;
if (i < 0) i = path.Length - 1; //翻到第一张后此时i变为负数,将i重新赋值为“总长度-1”即最后一张索引值,从而达到训话浏览
pictureBox1.Image = Image.FromFile(path[i]);
}
private void button2_Click(object sender, EventArgs e)
{
i++;
if (i > path.Length - 1) i = 0;//i大于总长度减一,即翻到最后一张后又点击了一次下一张,此时翻到第一张
pictureBox1.Image = Image.FromFile(path[i]);
}
}
}
2 ImageList控件
- ImageList,又叫存储图像控件,用来存储图像的组合,但它不能显示图像,要显示它存储的图像需要借用第二个控件
- 第二个控件是包含ImageList属性的控件(例如:ListView或TreeView),这个属性一般和ImageIndex属性一起使用。ImageList属性设置为ImageList组件的一个实例,ImageIndex属性设置为ImageList中对应图像的索引
- ImageList控件两个常用属性
- ImageSize用来设置图像的大小,Width属性和Height属性,用来设置图像的宽和高,其默认值都为16,取值范围1~256之间。
- ColorDepth,用来设置颜色深度,取值为4位~32位。
- ImageList一个方法
- Draw:用于绘制指定的图像(可以理解为显示图像)
add()和addstrip()的区别 :AddStrip图像条方法的宽度必须为整数(是ImageList.size的整数倍),否则会发生异常
- Draw:用于绘制指定的图像(可以理解为显示图像)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _3_ImageList控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click_1(object sender, EventArgs e)
{
//声明一个图像变量
Image image1 = Image.FromFile(@"C:\Users\Admin\Desktop\Images\1.png");
//imageList控件添加元素的方法
//方法1,添加单个元素
imageList1.Images.Add(image1);
//创建了一个窗口句柄(Handle) H wnd(windows)
Graphics mygph = Graphics.FromHwnd(this.Handle);
//Draw有三种方法
//第一种 (graphics对象,左上角点坐标,索引值)
imageList1.Draw(mygph, new Point(50, 50), 0); //第一个参数是句柄,第二个参数是图片显示起始位置(图片左上角的位置,用于定位图片),第三个参数是图片索引值,即ImageList中的图片索引
//第二种:(graphics对象,水平坐标,垂直坐标,索引值)
//第三种:(graphics对象,水平坐标,垂直坐标,图像宽度,图像高度,索引值)
}
private void button1_Click(object sender, EventArgs e)
{
//imageList控件添加元素的方法
//方法2 一次添加多个元素
Image image2 = Image.FromFile(@"C:\Users\Admin\Desktop\Images\2.png");
Image image3 = Image.FromFile(@"C:\Users\Admin\Desktop\Images\3.png");
Image image4 = Image.FromFile(@"C:\Users\Admin\Desktop\Images\4.png");
Image[] images = { image2, image3, image4 };
imageList1.Images.AddRange(images);
//方法3 AddStrip
Image image5 = Image.FromFile(@"C:\Users\Admin\Desktop\Images\5.png");
Image image6 = Image.FromFile(@"C:\Users\Admin\Desktop\Images\6.png");
imageList1.Images.AddStrip(image5);
imageList1.Images.AddStrip(image6);
//创建了一个窗口句柄(Handle) H wnd(windows)
Graphics mygph = Graphics.FromHwnd(this.Handle);
for (int i = 0; i < imageList1.Images.Count; i++)
{
imageList1.Draw(mygph, new Point(50, 50), i);
//因为显示速度太快,给线程添加一个休眠时间;
System.Threading.Thread.Sleep(1000);
}
}
private void button2_Click(object sender, EventArgs e)
{
//删除imageList对象的方法
//removeAt(索引值)
imageList1.Images.RemoveAt(5);
imageList1.Images.RemoveAt(4);
imageList1.Images.RemoveAt(3);
}
}
}
3 ListView控件
- ListView控件是Windows列表视图控件,该控件显示可用五种不同视图之一显示的向集合
- LargeIcon:在想文本胖显示大图标,如果控件足够大,则显示在多列中
- SmallIcon:除显示小图标外,其他方面与大图标视图模式相同
- List:显示小图标,单总是显示在单列中。
- Details:在多列中显示向。
- Tile:每个向都显示一位一个完整大小的图标,在他的右边带向标签和子项信息(仅支持XP/SERVER2003)
using System;
using System.Windows.Forms;
namespace _5_ListView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
String[,] myCountry = { { "China", "中国", "北京" }, { "Korea", "韩国", "首尔" }, { "Canada", "加拿大", "渥太华" }, { "American", "美国", "纽约" }, { "Jpan", "日本", "东京" }, { "SingPore", "新加坡", "新加坡" }, { "UK", "英国", "伦敦" }, { "Vietnam", "越南", "河内" }, };
for (int i=0; i < myCountry.Length/3; i++) //length获取数组的长度,是指最小元素的数量。例如上面数组共24个元素。
{
ListViewItem mylvi = listView1.Items.Add(i.ToString()); //可以理解为添加了一个对象名称,或者行名称
mylvi.ImageIndex = i;
mylvi.SubItems.Add(myCountry[i,0]);
mylvi.SubItems.Add(myCountry[i,1]);
mylvi.SubItems.Add(myCountry[i,2]);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString() == "LargeIcon") listView1.View = View.LargeIcon;
if (comboBox1.SelectedItem.ToString() == "SmallIcon") listView1.View = View.SmallIcon;
if (comboBox1.SelectedItem.ToString() == "Details") listView1.View = View.Details;
if (comboBox1.SelectedItem.ToString() == "List") listView1.View = View.List;
if (comboBox1.SelectedItem.ToString() == "Tile") listView1.View = View.Tile;
}
}
}
4、TreeView控件
- Tree View控件可以为用户显示节点层次结构,就想在Windows资源管理器功能的左创个中显示文件和文件夹一样。树视图中的各个节点可能包含其他节点。称为子节点。用户可以按照展开或折叠的方式显示父节点或包含子节点的节点。通过将树是的CheckBoxes属性设置为True,还可以在节点旁边显示带有复选框的树视图。
- 添加和算出树节点
- Tree View控件以层侧结构的方式显示节点,Nodes属性包含舒适图中的顶级节点列表,它是TreeNode对象集合。
- 添加节点:先创建TreeNode对象,然后通过Nodes的Add方法创建的TreeNode对象添加为TreeView节点;
- 删除节点,可用Nodes属性的Remove方法或RemoveAt方法
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TreeView
{
public partial class Form1 : Form
{
public string[] nodeName = new string[100];
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TreeNode mytn = new TreeNode(); //实例化一个树节点对象
if (textBox1.Text.Trim() != "")
{
mytn.Text = textBox1.Text.Trim(); //给节点对象赋值
treeView1.Nodes.Add(mytn); //将节点添加到TreeView控件中
}
else
{
MessageBox.Show("请先添加节点的名称");
}
}
private void button2_Click(object sender, EventArgs e)
{
TreeNode mytn = new TreeNode(); //实例化一个树节点对象
if (textBox1.Text.Trim() != "")
{
mytn.Text = textBox1.Text.Trim(); //给节点对象赋值
treeView1.SelectedNode.Nodes.Add(mytn);
}
else
{
MessageBox.Show("请先添加节点的名称");
}
}
private void button3_Click(object sender, EventArgs e)
{
TreeNode mytn = new TreeNode();
mytn = treeView1.SelectedNode;
if (mytn.Nodes.Count > 0)
{
DialogResult myDR = MessageBox.Show("该节点下有子节点不允许删除,请先删除子节点");
}
else
{
mytn.Remove();
}
}
private void button4_Click(object sender, EventArgs e)
{
TreeNode mytn = new TreeNode();
mytn = treeView1.SelectedNode;
if (textBox1.Text.Trim() != "")
{
if(((System.Collections.IList)nodeName).Contains(textBox1.Text) != true) mytn.Text = textBox1.Text.Trim();
else MessageBox.Show("已经存在\""+textBox1.Text+"\"的节点不能重复添加","错误提示");
}
else
{
MessageBox.Show("请先添加节点的名称");
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
//TreeNode mytn = new TreeNode();
//mytn = treeView1.SelectedNode;
//MessageBox.Show(mytn.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
int i = 0;
foreach (TreeNode mynode in treeView1.Nodes)
{
nodeName[i] = mynode.Text;
i++;
}
}
}
}
5、DateTimePicker控件使用户可以从日期
- DateTimePicker控件使用户可以从日期或时间列表中选择打个项。在用来日期时,显示为两部分,即一个下拉列表和一个类似于MonthCalendar控件的网格。
- 显示时间
- DateTimePicker控件默认是显示日期,显示时间时,必须将ShowUpDown属性设置为true,将Format属性设置为Time。
-
- 自动以格式显示日期
- 想要DateTimePicker控件以自定义格式显示日期,就的湘江Format属性设置为Custom,然后将CustomFormat属性设置为一个格式字符串
- DateTimepicker控件中当选定的日期和事件有Value属性确定。默认情况下,此空间的Value属性设置为当前日期。如果在代码中更改了此空间的Value属性,则此空间在窗体上自动更新一反应新设置。Value属性将DateTime结构作为它的值返回,有若干个DateTime结构的属性返回关于显示日期的特定信息。这些属性只用用于返回值,而不能用来设置值。
using System;
using System.Windows.Forms;
namespace _8_DateTimePicker控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
string tg = "甲乙丙丁午己庚辛壬癸";
string dz = "子丑寅卯辰巳午未申申酉戌亥";
string sx = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
int year = dateTimePicker1.Value.Year;
label1.Text = "您选择的年为:农历" + tg[(year - 4) % 10] + dz[(year - 4) % 12] + "年,生肖是" + sx[(year - 4) % 12] + "年";
}
}
}
6、MonthCalendar控件
-
MonthCalendar控件是用来查看和设置日期信息。它是一个可视化网络图形界面,网格内包含月份的编号日期,这些日期排列在周一~周日下方的七个列表中。用户可以单击月份标题任何一侧的箭头按钮来选择不同的月份。该控件还有一个更强的功能。就是可以选择日期范围。
-
以粗体显示特定日期
-
MonthCalendar控件以粗体显示特殊的日期或重要出现的日子,用此控件显示特殊日期的属性有三个:
- BoldedDates属性包含单个日期,(仅设置单个日期以粗体显示,上/下一个月以及上一年/下一年的日期都不影响)
- AnnuallyBoldeDates属性包含每年以粗体显示的日期;(设置每年的同一日期粗体显示)
- MonthlyBoleedDates属性包含每月以粗体显示的日期;(设置每月的同一日期粗体显示)
- 这三个属性中的每一个都包含有一个DateTime对象数组。若要从这些列表中添加或移除日期,必须添加或移除DateTime对象。 -
显示多个月份
- MonthCalendar控件可显示多个月份,最多可同时显示十二个月。默认情况下,控件只显示一个月,用户可通过CalendarDimensions属性来设置要显示的月份个数,它有两个属性width属性和height属性,分别用来设置列数和行数。在设置或更改月历尺寸时,控件的大小也会随之改变:因此应确保窗体上有足够的空间共新尺寸用。 -
选择日期范围
- MaxDate属性和MinDate属性:这两个属性分别用来设置选择的最大日期和最小日期
- 注意:如果代码中设置日期范围,则MaxDate属性和MinDate属性的值都为DateTime对象。
-
更改外观(在win7及以后的系统中已经被放弃)
起作用的前提是按照下图所示进行设置设置,
ErrorProvide控件
- ErrorProvider控件可以对窗体或控件上的用户输入进行验证。当验证用户在窗体中输入或显示的数据集的内部错误时,一般要用该控件。
- ErrorProvide控件的主要属性是DataSource(与数据库相关)、ContainerControl和Icon。将ErrorProvider控件与数据绑定控件结合使用时,必须要将containerControl属性设置为相应的容器(通常是Windows窗体),以便于该组件可以在窗体上显示错误图标。
- Icon属性可以设置为自定义错误图标而不是默认图标。
- 设置DataSource属性后,ErrorProvider控件可为数据集显示错误信息
- ErrorProvider控件的主要方法时SetError方法,该方法可以指定错误信息字符串和错误图标应出现的位置。其使用格式为:Errorprovider变量名.SetError(需要在哪个控件旁边显示信息(textBox1),显示错误的信息的字符串(您输入的数据不正确))
using System;
using System.Drawing;
using System.Windows.Forms;
namespace _12_ErrorProvider控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Length < 8 || textBox1.Text.Length > 10)
{
errorProvider1.SetError(textBox1, "用户名必须为8~12位");
errorProvider1.Icon = new Icon(@"E:\C#\project\Windows窗体高级控件\ico\error.ico");
}
else
{
errorProvider1.SetError(textBox1, "通过验证");
errorProvider1.Icon = new Icon(@"E:\C#\project\Windows窗体高级控件\ico\true.ico");
}
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
if (textBox3.Text != textBox2.Text)
{
errorProvider2.SetError(textBox3, "两次输入的密码不一致");
errorProvider2.Icon = new Icon(@"E:\C#\project\Windows窗体高级控件\ico\error.ico");
}
else
{
errorProvider2.SetError(textBox3, "通过验证");
errorProvider2.SetError(textBox2, "通过验证");
errorProvider2.Icon = new Icon(@"E:\C#\project\Windows窗体高级控件\ico\true.ico");
}
}
}
}
HelpProvide控件
- HelpProvide控件用于将html帮助文件(.btm文件或chm文件)与windows应用程序相关联。用户可通过多种方式提供帮助:
- HelpNamespace属性将帮助文件与HelpProvider组件相关联;关联后需要设置窗体的HelpProvidershowHelp才可以在按下F1键后弹出帮助文件。
- 通过调用SetHelpNavigator并提供指定控件的HelpNavigator枚举值来指定提供的帮助类型:
- 通过调用setHelpKeyWord方法为帮助提供关键字或主题
注:网页可以用 Web DreamWeaver编辑器编辑网页帮助文档,chm可以用Easy chm进行编辑.
ProgressBar控件
- ProgressBar控件通过在水平条中显示响应数据的矩形来只是操作的进度。操作完成时,进度栏被填满。进度栏通常用于帮助用户了解等待一项长时间的操作(例句,加载大文件)完成所需的事件
- ProgressBar控件主要属性有value、setp、minimum和maximum。Minimum和Maximum属性设置进度栏可以显示的最大值和最小值;Value属性标识操作过程中已完成的进度:Step属性用于指定Value属性定增的值。
- 除直接设置Value属性修改ProgressBar控件显示的值外,还可以使用Increment方法来指定Value属性递增的值。
- 其格式为:ProgressBar对象.Inrement(进度值)
- ProgressBar一个重要的方法时PerformStep方法,主要用于递增该值Stem属性指定Value属性递增值
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProgressBar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//progressBar1.Value = 1000;
//progressBar1.Increment(1500);
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.PerformStep();
}
}
}
实例:
using System;
using System.Windows.Forms;
namespace ProgressBar
{
public partial class Form1 : Form
{
//日志输出方法
public void outlog(string str)
{
textBox2.AppendText(DateTime.Now.ToString() + str + "\r\n");
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
btnSet.Enabled = true;
btnStart.Enabled = false;
btnPause.Enabled = false;
btnStop.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.PerformStep();
}
private void btnSet_Click(object sender, EventArgs e)
{
try
{
if (tbSettime.Text.Trim() != "")
{
progressBar1.Minimum = 0;
progressBar1.Maximum = Convert.ToInt32(tbSettime.Text);
progressBar1.Step = -1;
progressBar1.Value = progressBar1.Maximum;
btnSet.Enabled = false;
btnStart.Enabled = true;
textBox2.AppendText("========================================================\r\n");
outlog("时间正确设置,请点击开始键继续。。。");
}
else
{
MessageBox.Show("请输入正确的秒数,必须为正整数");
}
}
catch (Exception)
{
MessageBox.Show("请输入正确的秒数,必须为正整数");
}
}
private void btnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
btnPause.Enabled = true;
btnStop.Enabled = true;
timer1.Enabled = true;
timer1.Interval = 1000;
timer1.Start();
}
private void timer1_Tick_1(object sender, EventArgs e)
{
if (progressBar1.Value > progressBar1.Minimum)
{
progressBar1.PerformStep();
outlog("进度条工作正在进行,已经完成了" + Convert.ToInt32(((1 - Convert.ToDouble(progressBar1.Value) / Convert.ToDouble(progressBar1.Maximum)) * 100)).ToString() + "%");
//(最大值-当前值)/最大值=进度百分比
// 1-当前值/最大值=进度百分比
}
else
{
outlog("进度已经完成");
timer1.Stop();
btnSet.Enabled = true;
btnStart.Enabled = false;
btnPause.Enabled = false;
btnStop.Enabled = false;
}
}
private void btnPause_Click(object sender, EventArgs e)
{
if (timer1.Enabled == true)
{
outlog("进度已经被暂停");
btnPause.Text = "继续";
timer1.Stop();
}
else
{
outlog("进度条继续工作");
btnPause.Text = "暂停";
timer1.Start();
}
}
private void btnStop_Click(object sender, EventArgs e)
{
outlog("进度条停止工作\r\n===================");
timer1.Enabled = false;
progressBar1.Value = 0;
btnPause.Enabled = false;
btnSet.Enabled = true;
btnStart.Enabled = false;
btnStop.Enabled = false;
btnPause.Text = "暂停";
}
}
}
任务实施
using System;
using System.Drawing;
using System.Windows.Forms;
namespace 任务实施
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
ListViewItem myLVI = lv1.Items.Add((lv1.Items.Count + 1).ToString());
myLVI.SubItems.Add(tbName.Text);
myLVI.SubItems.Add(cbGender.Text);
myLVI.SubItems.Add(TbTel.Text);
myLVI.SubItems.Add(tbDepartment.Text);
myLVI.SubItems.Add(DTPJOinTime.Value.ToString("yyyy年MM月dd日"));
tbName.Clear();
cbGender.Text = "";
TbTel.Clear();
tbDepartment.Clear();
DTPJOinTime.Value = DTPJOinTime.MaxDate;
tbName.Focus();
}
private void Form1_Load(object sender, EventArgs e)
{
//设置时间最大值为当前日期,并将最大值复制给value
DTPJOinTime.MaxDate = DateTime.Now;
DTPJOinTime.Value = DTPJOinTime.MaxDate;
progressBar1.Maximum = 5;
progressBar1.Minimum = 0;
progressBar1.Step = 1;
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox1.Image = Image.FromFile(@"E:\C#\project\Windows窗体高级控件\任务实施\banner\雪上行者.PNG");
}
private void btnModi_Click(object sender, EventArgs e)
{
//修改选定内容,首先判断是否有选定的内容,选定的项目数量大于0代表有被选中
if (lv1.SelectedItems.Count > 0)
{
lv1.SelectedItems[0].SubItems[1].Text = tbName.Text;
lv1.SelectedItems[0].SubItems[2].Text = cbGender.Text;
lv1.SelectedItems[0].SubItems[3].Text = TbTel.Text;
lv1.SelectedItems[0].SubItems[4].Text = tbDepartment.Text;
lv1.SelectedItems[0].SubItems[5].Text = DTPJOinTime.Value.ToString("yyyy年MM月dd日");
tbName.Clear();
cbGender.Text = "";
TbTel.Clear();
tbDepartment.Clear();
DTPJOinTime.Value = DTPJOinTime.MaxDate;
tbName.Focus();
}
}
private void btndel_Click(object sender, EventArgs e)
{
//删除所选定的项目
lv1.SelectedItems[0].Remove();
}
private void btnClear_Click(object sender, EventArgs e)
{
//清除ListView中所有内容
lv1.Items.Clear();
}
//声明图片存放的路径,并声明一个随机变量,以便随机显示图片
string[] path = System.IO.Directory.GetFiles(@"E:\C#\project\Windows窗体高级控件\任务实施\banner");
Random r = new Random();
private void timer1_Tick(object sender, EventArgs e)
{
int num = 0;
if (tbName.Text.Trim() != "") num++;
if (cbGender.Text != "") num++;
if (TbTel.Text.Trim() != "") num++;
if (tbDepartment.Text.Trim() != "") num++;
if (DTPJOinTime.Value != DTPJOinTime.MaxDate) num++;
progressBar1.Value = num;
//随机显示图片
pictureBox1.Image = Image.FromFile(path[r.Next(0,path.Length)]);
}
private void btnCheck_Click(object sender, EventArgs e)
{
lv1.ForeColor = Color.Black;
//在ListView中查询文本
ListViewItem checkItem = lv1.FindItemWithText(tbCheck.Text);
//判定是否查询到
if (checkItem != null)
{
this.lv1.TopItem = checkItem;
checkItem.ForeColor = Color.Red;
}
else
{
MessageBox.Show(tbCheck.Text+"不存在");
}
}
}
}
版权声明:本文标题:十四、windows窗体高级控件 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726945781a1091128.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论