C#Bunifu UI System.NullReferenceException未处理

时间:2018-03-25 01:00:04

标签: c# winforms user-interface button bunifu

我使用的是Bunifu UI Framework, 一切都很好,直到我添加一个"退出"来自Bunifu UI的按钮是bunifuFlatButton,我试过这两个.Close();和Close();我得到了System.NullReferenceException,未处理错误。

按钮:

enter image description here

错误:

enter image description here

System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Bunifu_UI_v1.5.3
  StackTrace:
       at Bunifu.Framework.UI.BunifuFlatButton.method_5()
       at Bunifu.Framework.UI.BunifuFlatButton.BunifuFlatButton_MouseClick(Object sender, MouseEventArgs e)
       at System.Windows.Forms.Control.OnMouseClick(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Label.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Project.Program.Main() in C:\Project\Project\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

谢谢

2 个答案:

答案 0 :(得分:4)

我认为这是因为bunifu按钮有一些方法,比如"悬停时改变颜色,鼠标点击时改变颜色等等#34; ,当你点击按钮时,表单关闭,但是也许应用程序试图调用该bunifu按钮上的方法,例如鼠标单击后更改颜色,但表单已关闭,然后发生错误。
我通过在表单关闭前禁用按钮来解决此问题:

private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
    bunifuFlatButton1.Enabled = false;
    this.Close();
}

答案 1 :(得分:2)

是的,目前Bunifu Flat Button存在问题。然而,如果你想设置一个"退出&#34,你可以使用(如我在这样的设计用例中所做的那样)Bunifu Thin Button甚至更好,Bunifu Image Button ;仅带图像的按钮。

相关问题