Tag: toolstripbutton

为什么在单击ToolStrip按钮两次时抛出NullReferenceException – openFileDialog.showDialog()?

我创建了一个干净的WindowsFormsApplication解决方案,在主窗体上添加了一个ToolStrip ,并在其上放置了一个按钮。 我还添加了一个OpenFileDialog ,因此ToolStripButton的Click事件如下所示: private void toolStripButton1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); } 我没有改变任何其他属性或事件。 有趣的是,当我双击ToolStripButton (第二次单击必须非常快,在对话框打开之前),然后取消两个对话框(或选择一个文件,它并不重要),然后单击客户端主窗体的区域, NullReferenceException崩溃应用程序(post末尾附加的错误详细信息)。 请注意, Click事件是在DoubleClick未执行时实施的 。 更奇怪的是,当OpenFileDialog被任何用户实现的表单替换时, ToolStripButton 阻止被点击两次 。 我在Windows 7 Professional (来自MSDNAA)上使用VS2008和.NET3.5进行最新更新。 我没有在VS中更改很多选项(只有fontsize,工作区文件夹和行编号)。 有谁知道如何解决这个问题? 它在我的机器上是100%可复制的,是否也在其他机器上? 我能想到的一个解决方案是在调用OpenFileDialog.ShowDialog()然后再启用按钮之前禁用该按钮(但这并不好)。 还有其他想法吗? 现在承诺的错误细节: System.NullReferenceException未处理 Message =“对象引用未设置为对象的实例。” 来源= “System.Windows.Forms的” 堆栈跟踪: 在System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG&msg,HandleRef hwnd,Int32 msgMin,Int32 msgMax,Int32 remove) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 […]

ToolStripButton:以编程方式分配图像有什么问题

有一个带有ToolStrip的表单。 此ToolStrip包含ToolStripButton。 我想为此按钮指定图像: this.btnSaveFile.Image = Bitmap.FromFile(“C:\\Work\\Icons\\png\\save.png”); 仅当指定路径上有save.png时才有效。 否则,我得到一个FileNotFoundexception。 如果我通过表单设计器创建了一个表单,Visual Studio将创建如下代码: this.toolStripButton9.Image = ((System.Drawing.Image) (resources.GetObject(“toolStripButton9.Image”))); toolStripButton9.Image这里不是真名。 Visual Studio将我的文件save.png删除并将其转换为toolStripButton9.Image。 但我以编程方式创建了一个表单,没有Designer。 我的问题是如何以编程方式将图像分配给ToolStripBotton? 我试图将图像添加到项目中,但它没有多大帮助。 我不知道如何让Visual Studio抓住它并嵌入到我的可执行文件中,以便我不需要在指定位置使用此文件。 在MSDN中,我只看到这样的解决方案: this.toolStripButton1.Image = Bitmap.FromFile(“c:\\NewItem.bmp”); 但它并没有像我上面所说的那样起作用。 我知道有一个简单的解决方案,但没有看到它。 你能给我一个提示吗?

如何以编程方式在C#中连接ToolStripButton事件?

我是以编程方式将ToolStripButton项添加到上下文菜单中。 那部分很容易。 this.tsmiDelete.DropDownItems.Add(“The text on the item.”); 但是,我还需要连接事件,以便当用户点击该项时实际发生的事情! 我该怎么做呢? 处理点击的方法还需要接收某种与用户点击的特定ToolStripButton相关的id或对象。

如何在选中时更改System.Windows.Forms.ToolStripButton高亮/背景颜色?

我有一个ToolStripButton用作单选按钮。 选中时,按钮周围会出现蓝色轮廓,但没有背景颜色。 对于用户来说,检查按钮是不够清楚的,所以我想更改背景颜色以使检查状态更加明显。 当Checked属性设置为true时,如何更改高亮颜色? 这是一段代码: this.hideInactiveVehiclesToolstripButton.CheckOnClick = true; this.hideInactiveVehiclesToolstripButton.ForeColor = System.Drawing.Color.Blue; this.hideInactiveVehiclesToolstripButton.AutoSize = false; this.hideInactiveVehiclesToolstripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.hideInactiveVehiclesToolstripButton.Image = global::ClientUI.Properties.Resources.toggleInactive; this.hideInactiveVehiclesToolstripButton.ImageTransparentColor = System.Drawing.Color.Black; this.hideInactiveVehiclesToolstripButton.Name = “hideInactiveVehiclesToolstripButton”; this.hideInactiveVehiclesToolstripButton.Size = new System.Drawing.Size(48, 48); this.hideInactiveVehiclesToolstripButton.Text = “Hide Inactive Vehicles”; this.hideInactiveVehiclesToolstripButton.Click +=new System.EventHandler(this.hideInactiveVehiclesToolstripButton_Click);