1、生成条形码
首先我们先设计好一个界面,如下图:
接下来写生成按钮点击事件;
//生成点击事件
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = new CSharpCode39() {DataToEncode=this.textBox1.Text,
HumanReadable=true,
Checksum=true,
IsDisplayCheckCode=true
//,IsDisplayStartStopSign=true
//,CodeBarColor=Color.Red
}.getBitmapImage(96);
}
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
pictureBox1.Image.Save(Guid.NewGuid().ToString() + ".png");
MessageBox.Show("Save OK");
}
运行效果图如下:
2、获取文件夹中的文件
首先设计界面:
代码如下:
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = folderBrowserDialog1.SelectedPath; //获取文件夹位置
}
else
{
MessageBox.Show(this, “浏览文件夹错误!”, “提示对话框”, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show(this, "请选择文件夹!", "提示对话框", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
string[] files = Directory.GetFiles(textBox1.Text); //提取文件夹中的文件
for (int i = 0; i < files.Length; i++)//利用For循环语句在textBox2文本框中列表文件夹中所有文件
{
textBox2.Lines = files;
}
}
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit(); //退出程序
}
效果图如下: