NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a C# example of assigning an icon to an AxExpressionEdit Control Custom button?

Solved!
Go to solution

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"));

0 Kudos
Message 1 of 7
(4,564 Views)

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.

 

IMAGE$79A37B3C194B3081.jpg 

 

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

National Instruments
Applications Engineer
0 Kudos
Message 2 of 7
(4,523 Views)
Yes, this needs to be done programatically.  The controls are being created on the C# side at runtime.
0 Kudos
Message 3 of 7
(4,514 Views)

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

National Instruments
Applications Engineer
0 Kudos
Message 4 of 7
(4,481 Views)
Just to make sure my icon wasn't the problem, I tried the icon from your example - ArrowDown.ico.  I get a similar problem.  It looks like the icon is trying to be painted as a 24x24 icon instead of a 16x16 icon.
0 Kudos
Message 5 of 7
(4,472 Views)
Solution
Accepted by topic author skribling

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.

Manooch H.
National Instruments
Message 6 of 7
(4,454 Views)
Yes, that worked.  Thanks.
0 Kudos
Message 7 of 7
(4,449 Views)