Skip to content

Commit

Permalink
fix:System.InvalidOperationException: 对象当前正在其他地方使用
Browse files Browse the repository at this point in the history
  • Loading branch information
indiff committed Feb 18, 2024
1 parent 9c6d158 commit ebd2505
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions QTTabBar/QTButtonBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,10 @@ public sealed class QTButtonBar : BandObject {
button.DropDownOpening += dropDownButtons_DropDownOpening;
return button;
}


// 控制图片多线程锁
private static object imgLock2 = new object();

internal bool CreateItems()
{
// 工具栏按钮标签文字
Expand Down Expand Up @@ -493,10 +496,20 @@ internal bool CreateItems()
}*/
item.ImageScaling = ToolStripItemImageScaling.None;
item.Text = item.ToolTipText = ButtonItemsDisplayName[index];
item.Image =
(Config.BBar.LargeButtons ? imageStrip_Large[index - 1] : imageStrip_Small[index - 1])
.Clone(
new Rectangle(Point.Empty, Config.BBar.LargeButtons ? sizeLargeButton : sizeSmallButton), PixelFormat.Format32bppArgb);
/*
************** 异常文本 **************
System.InvalidOperationException: 对象当前正在其他地方使用。
在 System.Drawing.Bitmap.Clone(Rectangle rect, PixelFormat format)
在 QTTabBarLib.QTButtonBar.CreateItems()
在 QTTabBarLib.QTTabBarClass.RefreshOptions()
*/
lock (imgLock2) // by indiff
{
item.Image =
(Config.BBar.LargeButtons ? imageStrip_Large[index - 1] : imageStrip_Small[index - 1])
.Clone(
new Rectangle(Point.Empty, Config.BBar.LargeButtons ? sizeLargeButton : sizeSmallButton), PixelFormat.Format32bppArgb);
}


item.Tag = index;
Expand Down

0 comments on commit ebd2505

Please sign in to comment.