06-12-2010 12:56 PM
TestStand 4.1
C# 2008
I am looking for an example of how to assign an icon to an AxExpressionEdit custom button. My code builds and seems to do the icon to stdole.iPictureDisp conversion fine but the icon does not appear on the custom button.
ExpressionEditButtons eeb = axExprEdit.Buttons;
ExpressionEditButton btn = eeb.GetItem(0, SpecifyExpressionEditButton.SpecifyButton_ByIndex);
btn.Icon = (stdole.IPictureDisp)Support.ImageToIPictureDisp((Image)Icon.ExtractAssociatedIcon("c:\\myIcon.ico").ToBitmap());
I've also tried to use a bitmap with the same result:
btn.Icon = (stdole.IPictureDisp)Support.ImageToIPictureDisp(Bitmap.FromFile("c:\\MyBitmap.bmp"));
Solved! Go to Solution.
06-14-2010 02:36 PM
Hello skribling,
If you don't need to change it programmatically you can right click on the control and select properties. From there select Buttons and change the icon from there.
Let us know if you are trying to do it programmatically and we can do some more research and find out the best way to do this. Have a great day!
Best Regards,
Adam G
06-14-2010 04:27 PM
06-15-2010 12:21 PM
Hello skribling,
After doing some research I believe we may have found a way on how to add the icon. I am posting the code so you can take a look at it. Let me know if this works out for you and have a great day!
Key namespaces used:
using System.Drawing; //used to access the Icon class
using NationalInstruments.TestStand.Interop.UI; //used to access the ExpressionEditButton interface
using stdole; //used to access the IPictureDisp interface
using Microsoft.VisualBasic.Compatibility.VB6; //used to access the Support class which contains the IconToIPicture() method
Code to programmatically insert a new ExpressionEditButton and set the icon for it:
Icon myIcon = Icon.ExtractAssociatedIcon("C:\\Program Files\\National Instruments\\TestStand 4.1.1\\Components\\Icons\\ArrowDown.ico");
axExpressionEdit1.Buttons.Insert(0, 1000).Icon = (IPictureDisp)Support.IconToIPicture(myIcon);
Best Regards,
Adam G
06-15-2010 03:28 PM
06-15-2010 04:16 PM
skribling -
Is your icon stored in the <TestStand>\Components\Icons or <TestStand Public>\Components\Icons search directory? If you store your icon in one of these directories (preferably the <TestStand Public>\Components\Icons directory), then there is an easier way of accomplishing your goal with the following pseudo code:
ExpressionEditButton.Icon = (stdole.IPictureDisp)Engine.Images.FindImage("ArrowDown.ico", 16, 16)
Let me know if this helps.
06-15-2010 04:25 PM