在C#中显示隐藏标签 [英] show hide label in C#

查看:865
本文介绍了在C#中显示隐藏标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧我正在做这个表格,当我从下拉菜单中选择一个特定的项目时它会改变它的样子,



Alright I'm doing this form that's supposed to change it's look when I choose a specific item from a drop down menu,

private void ChangeGUI(int option)
   {
       switch (option)
       {
           case 0:
           case 1:
               labelAntal.Visible = true;
               txtAntal.Visible = true;
               labelWeight.Visible = false;
               txtWeight.Visible = false;
               break;

           case 2:
               labelAntal.Visible = false;
               txtAntal.Visible = false;
               labelWeight.Visible = true;
               txtWeight.Visible = true;
               break;
       }

   }





我一直在txtWeight.Visible上得到nullReferenceException ,那就是我从下拉菜单中选择第3个选项。



谁能看到我在这里做错了什么?:(



I keep getting a nullReferenceException on txtWeight.Visible , that is when i choose the 3'rd option from the drop down menu.

Can anyone see what I'm doing wrong here?:(

推荐答案

从那个?没有。

你需要查看变量本身,并确保它附加到一个真正的控件实例。

右键单击源代码中的任意名称,然后从上下文菜单中选择查找所有引用。



其中至少有一个应该是对新实例的赋值(它可能在designer.cs文件中)如果没有,那么它就不在你的表单上了!(而且你需要查看你的代码并找出它是什么和它应该在哪里)
From that? No.
You need to look at variable itself, and make sure that it is attached to a genuine control instance.
Right click the name anywhere in your source code, and select "Find all references" from the context menu.

At least one of them should be an assignment to a new instance (it could well be in the designer.cs file) If there isn't one, then it isn't on your form! (And you need to look at your code and work out what it is and where it should be)


在第三种情况下是否存在 txtWeight

可能是这个文本框是在n的表单上动态生成或生成的当您选择第三个选项时激活。
Does txtWeight exist in the third case?
It could be this text box is dynamically generated or generated on a form that is not active when you are choosing the third option.


这篇关于在C#中显示隐藏标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆