【问题标题】:C# Bunifu UI System.NullReferenceException was unhandledC# Bunifu UI System.NullReferenceException 未处理
【发布时间】:2018-09-03 10:07:21
【问题描述】:

我正在使用 Bunifu UI 框架, 一切都很好,直到我从 Bunifu UI 添加了一个“退出”按钮,即 bunifuFlatButton,我尝试了 this.Close();和关闭();并且我都得到 System.NullReferenceException 是未处理的错误。

按钮:

错误:

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:

谢谢

【问题讨论】:

    标签: c# winforms user-interface button bunifu


    【解决方案1】:

    我认为这是因为 bunifu 按钮有一些方法,例如“悬停时更改颜色,鼠标单击时更改颜色等”,
    当您单击按钮时,表单会关闭,但随后应用程序可能会尝试调用该 bunifu 按钮上的方法,例如单击鼠标后更改颜色,但表单已关闭,然后发生错误。
    我通过在表单关闭之前禁用按钮来解决此问题:

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

    【讨论】:

      【解决方案2】:

      是的,目前Bunifu Flat Button 存在问题。但是,如果您希望仅使用图像设置“退出”按钮,则可以使用(就像我在此类设计用例中一直使用的那样)Bunifu Thin Button 或更好的Bunifu Image Button

      【讨论】:

      • 这是为什么呢?试图找到有关该行为的任何文档(您提供的链接不再可用),但没有发现任何有用的东西......我遇到了与 OP 相同的问题,这里的问题是,我做了在我的应用程序的其他形式上也有同样的事情(完成操作后,关闭它),但问题只发生在其中一个中。
      猜你喜欢
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 2015-12-17
      • 2020-10-17
      • 2022-11-19
      • 1970-01-01
      相关资源
      最近更新 更多