如果文件存在,则自动选中复选框 [英] Automatically check a checkbox if file exists
本文介绍了如果文件存在,则自动选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I want to create a program such that if the file exists, the checkbox will auto check.
我尝试过:
What I have tried:
private void autoCheckChkBoxes(CheckBox theChkBox, TextBox theTxtBox)
{
private void button3_Click(object sender, EventArgs e)
{
//check whether the file is exist or not
if (string curFile = @"C:\s\test.txt")
{
}
else
{
}
}
推荐答案
private void button3_Click(object sender, EventArgs e)
{
autoCheckChkBoxes(checkBoxObj,TextBox);
}
private void autoCheckChkBoxes(CheckBox theChkBox, TextBox theTxtBox)
{
string curFile = @"C:\s\test.txt"
theChkBox.checked=system.IO.File.Exist(curFile);
}
希望它对您有用。
Hope it works for you.
您是否尝试过使用谷歌搜索? c#检查文件是否存在 - Google搜索 [ ^ ] - 有一些如何做你想要的例子...
Have you tried using google search? c# check if file exists - Google Search[^] - there are a tonne of examples of how to do what you want...
theChkBox.IsChecked = System.IO.File.Exists(theTxtBox.Text);
**更新**
如何自动完成...
** UPDATE **
How to do it automatically...
private void theTextBox_TextChanged(object sender, EventArgs e)
{
theCheckBox.Checked = System.IO.File.Exists(theTextBox.Text);
}
这篇关于如果文件存在,则自动选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文