我遇到关于tabcontrol的错误 [英] I got an error about tabcontrol

查看:79
本文介绍了我遇到关于tabcontrol的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击选项卡时,错误消息会弹出,如下所示:

控件System.Windows.Forms.TabControl在设计器中引发了未处理的异常,并且已被禁用.

When I click the tab then the error message popup as follows:

The control System.Windows.Forms.TabControl has thrown an unhandled exception in the designer and has been disabled.

Exception:
Object reference not set to an instance of an object.

Stack trace:
at
System.Windows.Forms.TabControl.UpdateTabSelection(Boolean updateFocus)
at
System.Windows.Forms.TabControl.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.TabControl.WmSelChange()
at System.Windows.Forms.TabControl.Wndproc(Message& m)



只有两个标签



only two tabs

     //
            // tabControlServings
            //
            this.tabControlServings.Appearance = System.Windows.Forms.TabAppearance.FlatButtons;
            this.tabControlServings.Controls.Add(this.tabPageServingList);
            this.tabControlServings.Controls.Add(this.tabPageServingType);
            this.tabControlServings.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControlServings.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.tabControlServings.ItemSize = new System.Drawing.Size(120, 40);
            this.tabControlServings.Location = new System.Drawing.Point(0, 0);
            this.tabControlServings.Name = "tabControlServings";
            this.tabControlServings.SelectedIndex = 0;
            this.tabControlServings.Size = new System.Drawing.Size(409, 567);
            this.tabControlServings.SizeMode = System.Windows.Forms.TabSizeMode.Fixed;
            this.tabControlServings.TabIndex = 11;
//
// tabPageServingType
//
this.tabPageServingType.Controls.Add(this.panel2);
this.tabPageServingType.Controls.Add(this.panel1);
this.tabPageServingType.Controls.Add(this.dataRepeaterServingType);
this.tabPageServingType.Location = new System.Drawing.Point(4, 44);
this.tabPageServingType.Name = "tabPageServingType";
this.tabPageServingType.Padding = new System.Windows.Forms.Padding(3);
this.tabPageServingType.Size = new System.Drawing.Size(401, 519);
this.tabPageServingType.TabIndex = 1;
this.tabPageServingType.Text = "Serving Type";
this.tabPageServingType.UseVisualStyleBackColor = true;



它构建成功,仅在设计器视图中单击选项卡时才会出现错误.
F5和调试没有出现错误,我不知道为什么.



It build success, the error appears just when clicking the tab in the designer view.
F5 and debugging there is no error appeared, I don''t know why.

推荐答案

您正在显示不相关的代码.不,现在不显示任何代码,您不是很了解自己的代码的功能.您的样本是不相关的,因为System.Windows.Forms中存在异常:
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.updatetabselection.aspx [ ^ ].

而且,您没有在堆栈跟踪中显示任何有关此调用的代码.您会发现,例外是最容易解决的问题之一.在调试器下运行它.首先,找到对上面显示的方法的调用,并在此行上放置一个断点.尝试运行.调用之前,请先查看所涉及的成员和变量.其中至少有一个为空,但不应假定为空.调用前检查调试器下的所有相关值,并找出错误.将这种方法应用于其他情况.修复错误:确保有问题的引用变量或成员使用非空引用进行初始化(调用了构造函数,或者将您的引用分配给了一些已初始化的变量),或者在适当的情况下执行了条件语句:检查变量或有问题的成员为null,如果为null,则不要在使用该成员的位置进行操作.

—SA
You are showing unrelated code. No, don''t show any code right now, you don''t really understand what your own code does. You sample is unrelated, because the exception is in System.Windows.Forms:
http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.updatetabselection.aspx[^].

And you did not show any code around this call shown in your stack trace. You see, you exception is one of the easiest to fix. Run it under debugger. To start with, locate your call to the method shown above and put a breakpoint on this line. Try to run. Before the call, look at the members and variables involved. At least one of them is null but is not supposed to be null. Inspect all relevant value under debugger before a call and find out the bug. Apply this approach to other cases. Fix the bug: either make sure the problematic reference variable or member is initialized with a non-null reference (constructor called or your reference is assigned to some already initialized variable), or, if appropriate, make a conditional statement: check a variable or a member in question for null and don''t the operation where it is used if it is null.

—SA


这篇关于我遇到关于tabcontrol的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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