.NET

Reply
Distinguished Contributor
wesbird
Posts: 351
Registered: ‎12-05-2003
Message 1 of 3 (141 Views)

toolbar icon use resource file

141 Views, 2 Replies
11-29-2005 09:02 AM
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
Valued Contributor
smcclure
Posts: 60
Registered: ‎06-08-2006
Message 2 of 3 (141 Views)

Re: toolbar icon use resource file

07-14-2006 07:20 AM 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]
Distinguished Contributor
wesbird
Posts: 351
Registered: ‎12-05-2003
Message 3 of 3 (141 Views)

Re: toolbar icon use resource file

07-14-2006 08:26 AM in reply to: wesbird
Thank you, I will try it.



Wes
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.