Checkbox1 在当前上下文中不存在

Checkbox1 does not exist in the current context

我的 checkbox1 名称有什么问题?

if (checkBox1.CheckState == CheckState.Checked) sb.AppendLine(@"\include{chapter2.tex}");

我的其他 class 行:

 config.Parts = new List<DocPart>();

                var part1 = new DocPart
                {
                    Title = "Second Chapter",
                    Checked = checkBox1.Checked
                };

                config.Parts.Add(part1);

它说 chechBox1 在当前上下文中不存在。怎么了?

谢谢。

MSDN 清楚地说明了这个错误:

This error frequently occurs if you declare a variable in a loop or a try or if block and then attempt to access it from an enclosing code block or a separate code block.

所以你需要检查你定义的范围 chechBox1