Dynamically Change Button Image in Excel 2010 - excel

I'm using XML to create a custom Excel Ribbon in which I have a button that contains an image. I would like to be able to change this image when the button is pressed (like a toggle) to show what state it's in. I have the following XML to describe the button:
<button id="MyButton"
label="MyLabel"
screentip="Some useful info."
onAction="MyAction"
getImage="GetImage"
size="large"/>
Where the MyAction method is defined as:
public void MyAction(Office.IRibbonControl control)
{
// Change button image here...
}
Is there some way I can change the button's image in the MyAction() method?
Cheers

EDIT: sorry, I just realised this was on the C# forum and I wrote the functions in VB. Do you need me to have the code translated into C#? Note that the callback behavior should be the same.
I find the easiest way to do update a control is to Invalidate the control or the whole ribbon and have the parameters update through the control's callbacks like getImage, getVisible, getLabel, etc
What I write here will work for any of a controls' parameters (label, enabled, visible, ...)
So if you define your button in the XML this way:
<button id="MyButton"
label="MyLabel"
onAction="OnAction"
getImage="GetImage"/>
You can then use the OnAction callback to update the button's paramater this way (assuming that you have a boolean variable called condition):
Public Sub OnAction(ByVal control As Office.IRibbonControl)
// Do your button stuff here
condition = Not condition
gui.InvalidateControl(control.Id)
End Sub
Then the callbacks of the button will get called, for getImage you can use:
Public Function GetImage(ByVal control As Office.IRibbonControl) As String
If condition Then
Return "MacroPlay"
Else
Return "DeclineInvitation"
End If
End Function
Note that for all this to work you need to store the Ribbon into the gui variable. For this you need to use in the XML:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnRibbonLoad"> ...
and in the code:
Public Sub OnRibbonLoad(ByVal ribbon As Office.IRibbonUI)
gui = ribbon
End Sub

It looks as though you are correct. The only way I have found to edit the appearance of custom ribbon elements is to use 'Ribbon (Visual Designer)' and not XML.
For example, if I want to change an image on a toggle button called toggleButton1 I can do the following:
public void toggleButton1_Click(object sender, RibbonControlEventArgs e)
{
toggleButton1.Image = GetImage(toggleButton1.Checked);
}
where GetImage is defined as:
public Bitmap GetImage(bool pressed)
{
return new Bitmap(pressed ? Properties.Resources.img_1 : Properties.Resources.img_2);
}
Cheers

<button id="MyButton" label="MyLabel" onAction="OnAction" getImage="GetImage"/>
The solution above worked for me. Just make sure that you don't use loadImage event on your customUI xml node. Looks like if you use both loadImage and GetImage then addin fails to load.

Related

How to show/hide an radio button dependant on option set field CRM 2011

I'm newbie on javascript. I'm triying to hide an radio button when a user choose a specific value of the option set. I have wrote this script
function showhideradiobuttom(){
var optValue = Xrm.Page.getAttribute("nav_phone1type").getValue();
if (optValue == 1) {
Xrm.Page.ui.controls.get("nav_phone1spam").setVisible(false);
}
else {
Xrm.Page.ui.controls.get("nav_phone1spam").setVisible(true);}
}
Unfortunatelly this is not working...
Make sure that you are running your javaScript function on the OnChange even of Option Set.

DialogTabPage object does not have method 'frameType'

This is related to my question posted here:
How to make dialog elments collapsible?
Another developer has added two groups to the dialog that is displayed when creating a payment proposal (CustVendPaymJournal_Vend Class) and the "Ok" and "Cancel" buttons are no longer displayed on smaller resolutions (1024x768).
To overcome this I am trying to group some dialog elements in DialogTabPage tabs. However I haven't had any success in my attempts.
This is what I have in the first couple lines of code in the dialog() method for CustVendCreatePaymJournal_Vend
public Object dialog()
{
LedgerJournalType ledgerJournalType;
DialogTabPage tab;
super();
tab = dialog.addTabPage("First tab");
}
I keep on receiving this error anywhere I try to add a tab in the dialog. I have tried to put it on CustVendPaymJournal (from which CustVendPaymJournal_Vend is inherited) also, but to no avail.
DialogTabPage object does not have method 'frameType'.
Try:
dialog = super();
tab = dialog.addTabPage("First tab");

Click OK in Dialog box display output text in SDI

I have a dialog box displayed when I press a menu item in the SDI window. In the Dialog box When i press OK button it should display "SUCESS" in the SDI window... In ONVIEW() i have to use pDC->TEXTOUT() but how to execute that statement on pressing OK button.. I am using visual C++ 6
you should define a user defined message and use PostMessage to call your method in SDI Window.
I am working on assumption that your dialog is modal.
You do not have to define or send any messages.
Retrieve data from the dialog.
Presumably you store 2D vector data in some kind of an array declared as a member variable of the dialog.
When OK button is pushed and copy data to a view’s member variable of the same type. Use it to draw whatever you desire.
void CSDIPopupSampleView::OnViewDialog()
{
CSimpleDlg dlg;
int iResponse = dlg.DoModal();
if(IDOK == iResponse)
{
//Copy data from a dialog here.
}
Invalidate(); // this will cause redraw
}

Hold-Hover drop down menu Delay Time

Im creating a drop down menu and i want to know if there is anyway to implement the following:
I need to keep the sub-menu open for like 1 sec if the user moves the mouse away from the tab he selected. Much likely like in current intel web page www.intel.com , here u hover over menu, but if u take the mouse away from the tab or the sub-menu is opens it takes a few to hide the sub menu.
Im using .mouseover from jquery to show the menu (a div) but i cant find a way to make it stay for a few moments.
Thanks in advance
This may be of service
What is the JavaScript version of sleep()?
If you want to do something in the interim setTimeout() takes the arguments as shown where continue execution is another subroutine. If you just want this one tab to work this way have mouseover call doStuff and set a boolean (e.g. mouseStillIn) to TRUE. When the mouse exits set this boolean to FALSE, call a recursive function everytime mouseStillIn is TRUE.
e.g.
var mouseStillIn : boolean = false;
function MouseIn()
{
mouseStillIn=true;
CheckMouse();
}
function CheckMouse()
{
if(mouseStillIn)
{
setTimeout(CheckMouse, 1000);
}
}
function MouseOut()
{
mouseStillIn=false;
}

Setting command button visibility in VC++ 6.0?

How can I make the command button in my VC++ 6.0 dialog visible or invisible on load?
From the resource editor once you select the button, you can see its properties in the properties window. Here you can set the visible property to true / false. (assuming this functionality is present in 6.0 - i use 2003 now and cannot remember if this used to be present in 6.0)
Add CButton variable
If you want to dynamically change the buttons visibility during load, add a variable for your button using the MFC class wizard. (you are lucky to have this - this wizard seems to have been removed from Visual Studio .NET)
Override CDialog InitDialog
Next override the initdialog function of your dialog box and then once the base InitDialog function has been successfully called, set the buttons showwindow property to SW_HIDE / before showing the dialog box.
Code
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
if (ConditionShow)
m_MyButton.ShowWindow(SW_SHOW);
else
m_MyButton.ShowWindow(SW_HIDE);
return TRUE;
}
You can also do it without adding a CButton variable - just call
In the OnInitDialog method of the window containing the button/control, put in code:
CWnd *wnd = GetDlgItem (YOUR_RESOURCE_NAME_OF_THE_BUTTON)
wnd->ShowWindow(SW_SHOW) or SW_HIDE
What do you mean by 'commnad button' exactly ?
Anyway, you need to obtain the handle of the button then call ShowWindow function:
BOOL prevState = ShowWindow( itemHandle, SW_HIDE );
Only use
ShowDlgItem(Your_DLG_ITEM_ID,1); // visible = true
ShowDlgItem(Your_DLG_ITEM_ID,0); // visible = false

Resources