.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

toolbar icon use resource file

2 REPLIES 2
Reply
Message 1 of 3
wesbird
275 Views, 2 Replies

toolbar icon use resource file

Hi,
Is there any I can use image in my resouce file as toolbar icon. I am not sure if this, SetBitmaps(string, string), work with ResourceManager? Has anybody tried this before?
Is this possible?



Thank you
Merry Christmas

Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
2 REPLIES 2
Message 2 of 3
smcclure
in reply to: wesbird

It is kind of possible in a kludgy way... I solve this by writing the image out at runtime and assigning it to the toolbar...

[code]
Dim lgBitmap As System.Drawing.Bitmap = TryCast(My.Resources.ResourceManager.GetObject(attr.LargeImage), System.Drawing.Bitmap)
Dim smBitmap As System.Drawing.Bitmap = TryCast(My.Resources.ResourceManager.GetObject(attr.SmallImage), System.Drawing.Bitmap)
CreateToolbarButton(toolbar, toolbar.Count, attr.Name, attr.Description, attr.Command, lgBitmap, smBitmap)

....

Public Sub CreateToolbarButton(ByVal toolbar As Autodesk.AutoCAD.Interop.AcadToolbar, ByVal index As Integer, ByVal name As String, ByVal desc As String, ByVal command As String, ByVal lgImg As Bitmap, ByVal smImg As Bitmap)
Dim button As Autodesk.AutoCAD.Interop.AcadToolbarItem = toolbar.AddToolbarButton(index, name, desc, "\x1b\x1b_" & command & "\n")
Dim lgImagePath As String = System.IO.Path.Combine(My.Application.Info.DirectoryPath, lgImg.GetHashCode().ToString() & ".bmp")
Dim smImagePath As String = System.IO.Path.Combine(My.Application.Info.DirectoryPath, smImg.GetHashCode().ToString() & ".bmp")
If lgImg IsNot Nothing Then
If Not System.IO.File.Exists(lgImagePath) Then lgImg.Save(lgImagePath, System.Drawing.Imaging.ImageFormat.Bmp)
Else
My.Application.Log.WriteEntry("Could not find large toolbar image for toolbar button: " & name, TraceEventType.Warning)
lgImagePath = String.Empty
End If
If smImg IsNot Nothing Then
If Not System.IO.File.Exists(smImagePath) Then smImg.Save(smImagePath, System.Drawing.Imaging.ImageFormat.Bmp)
Else
My.Application.Log.WriteEntry("Could not find small toolbar image for toolbar button: " & name, TraceEventType.Warning)
smImagePath = String.Empty
End If
button.SetBitmaps(smImagePath, lgImagePath)
End Sub
[/code]
Message 3 of 3
wesbird
in reply to: wesbird

Thank you, I will try it.



Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost