private void RunRibbonTask( Func<Task> action, [CallerMemberName] string actionName = "" )
{
Task.Run( async () =>
{
try
{
await action();
}
catch ( Exception ex )
{
ShowException( ex, actionName );
}
finally
{
ExcelAsyncUtil.QueueAsMacro( () => application.Cursor = MSExcel.XlMousePointer.xlDefault );
}
} );
}
public Bitmap Ribbon_GetImage( IRibbonControl control )
{
try
{
switch ( control.Id )
{
case "katShowDiagnosticLog":
{
using var ms = new MemoryStream( auditShowLogImage );
var img = Image.FromStream( ms );
if ( auditShowLogBadgeCount > 0 )
{
var flagGraphics = Graphics.FromImage( img );
flagGraphics.FillEllipse(
new SolidBrush( Color.FromArgb( 242, 60, 42 ) ),
new Rectangle( 11, 0, 19, 19 )
);
flagGraphics.DrawString(
auditShowLogBadgeCount.ToString(),
new Font( FontFamily.GenericSansSerif, 6, FontStyle.Bold ),
Brushes.White,
x: auditShowLogBadgeCount < 10 ? 16 : 13,
y: 3
);
}
return (Bitmap)img;
}
default: throw new ArgumentOutOfRangeException( nameof( control ), $"The id {control.Id} does not support custom image generation." );
}
}
catch ( Exception ex )
{
ShowException( ex, $"Ribbon_GetImage {control.Tag}" );
return null!;
}
}