电阻色环查询器[原创]
本人有一个朋友是学电路的。这几天,找到了我 想让我给写一个电阻色环查询器(根据电阻上面表明的色环颜色,判断电阻的大小)。由于,不是电路的翻阅的许多资料,才知道怎么根据色环查阻值。今天,把源码发上来与大家学习一下。注:由于时间仓促只完成的4环型的,且代码不太规范 【高手无喷】
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Thread t = null;
private int btnTimes = 0;
public delegate void AddFileToListboxHandle(FileInfo fileFullName);
public event AddFileToListboxHandle addfilenameEvent;
private void AddFileToListbox(FileInfo f)
{
this.listBox1.Items.Add(f.Name);
this.label1.Text = f.FullName;
}
delegate void finishedFindFileHandle(string A);
private void FinishFindFile(string a)
{
this.label1.Text = a;
this.label1.ForeColor = Color.Red;
}
public Form1()
{
InitializeComponent();
this.addfilenameEvent += new AddFileToListboxHandle(AddFileToListbox);
}
private void button1_Click(object sender, EventArgs e)
{
string FilePath = "F:\\";
if (t == null)
{
t = new Thread(new ParameterizedThreadStart(this.getFileName));
if (t.IsAlive == false)
{
t.Start(FilePath);
t.IsBackground = true;
}
else
{
return;
}
}
}
private void getFileName(object b)
{
string filePath = b.ToString();
if (Directory.Exists(filePath) == true)
{
DirectoryInfo fileContext = new DirectoryInfo(filePath);
int fileCount = fileContext.GetFileSystemInfos().Length;
if (fileCount == 0)
{
return;
}
else
{
FileSystemInfo[] fs = fileContext.GetFileSystemInfos();
foreach (FileSystemInfo f in fs)
{
if (f is FileInfo)
{
this.listBox1.Invoke(new AddFileToListboxHandle(this.AddFileToListbox), f);
}
else if (f is DirectoryInfo)
{
getFileName(f.FullName);
}
}
}
}
}