单击后如何关闭button_click事件 [英] How to close button_click event after clicking
问题描述
所以我有button_click事件生成文件。我点击此按钮事件后要关闭它。如果我在按钮点击条件结束时使用close(),我的一些功能就不能完成所有工作。也许有其他关闭按钮事件的方法?
So I have button_click event which generate files. I want to close it after I click this button event. If I use close() at end of button click conditions, some of my functions isnt doing all their job. Maybe there is other way to close button event?
private void button2_Click(object sender, EventArgs e)
{
{
var header = File.ReadAllText(@"C:\dir\header.tex");
var footer = File.ReadAllText(@"C:\dir\footer.tex");
var sb = new StringBuilder();
sb.AppendLine(header);
foreach (TreeNode node in treeView1.Nodes)
{
var tag = node.Tag as string;
sb.AppendLine(string.IsNullOrEmpty(Text) ? node.Text : tag);
}
sb.AppendLine(footer);
File.WriteAllText(@"C: \dir\final.tex", sb.ToString());
//Close() I were using close here.
}
推荐答案
你的代码没有任何意义。这一行:
Your code is not making any sense. This line:
sb.AppendLine(string.IsNullOrEmpty(Text) ? node.Text : tag);
如果 Text
(无论是什么,它没有在您发布的代码片段中定义)为null或String.Empty,请附加 node.Text
字符串生成器的内容。如果 Text
不为null或为空,请附加 node.Tag
内容。
什么是文字
,因为这是推动附加内容的原因,可能不是你所期望的。
学习使用调试器并逐步执行代码并检查变量内容。没有这种技能,你只是猜测你的代码有什么问题。
says if Text
(whatever that is, it's not defined in the code snippet you posted) is null or String.Empty, append the node.Text
content to the string builder. If Text
is not null or empty, append the node.Tag
contents.
What's Text
, because that's what is driving what gets appended and is probably not what you expect.
Learn to the use the debugger and step through code and inspect variable contents. Without that skill, you're just guessing at what's wrong with your code.
这篇关于单击后如何关闭button_click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!