Outlook 2013 Addin: Change Ribbon Button Image on click of button using c# - outlook

I have created Ribbon button for Outlook 2013 using c#.
And i have also set image for the ribbon.
Now on click of Ribbon button i want to change Ribbon Image.
Is it possible to achieve this using c#.?

Not sure how exactly you want it to work, but this could do the trick.
bool callback {get;set}
public Bitmap GetImage(IRibbonControl control)
{
switch (control.Id)
{
case "FooButtonId":
{
if(callback== true){
callback = false;
return new Bitmap(Properties.Resources.someimage1);
}else
callback =true;
return new Bitmap(Properties.Resources.someimage2);
}
}
}
}

This question is 3 yo but helped me to go further and I want to share this with you.
First, I accomplished this in VB.net so my code will be in VB.net. There are some online tools to convert the code into C#.
Second, I used a Toggle button instead of a Simple button.
Third, I used OnOff as a project setting in order to save the state of the Toggle button.
Step 1: Ribbon.xml file, code to place the toggle button on the ribbon.
Assuming you already have set up the tab and group tags in the file.
<toggleButton id="onoffTBTN" label="ON/OFF" showImage="true" onAction="OnOffToggle" getImage="OnOffImage"/>
Step 2: Ribbon.vb file, code to change the OnOff setting based on the Toggle button status(pressed or not) and forces to invalidate the custom control
Public Sub OnOffToggle(ByVal control As Office.IRibbonControl, ByVal pressed As Boolean)
My.Settings.OnOff = pressed
My.Settings.Save()
myRibbon.InvalidateControl("onoffTBTN")
End Sub
Step 3: Ribbon.vb file, reads the OnOff setting and changes the image accordingly. Have in mind that your images must have been added to your project resources in order to use them at My.Resources.*. I used png files that support transparent pixels. This function is called in two occasions, first when the Outlook starts and second when the toggle button is pressed and specifically with the command myRibbon.InvalidateControl("onoffTBTN").
Public Function OnOffImage(ByVal control As Office.IRibbonControl) As Drawing.Bitmap
Dim onoff As Boolean = My.Settings.OnOff
Select Case control.Id
Case "onoffTBTN"
If onoff = True Then
Return New Drawing.Bitmap(My.Resources._on)
Else
Return New Drawing.Bitmap(My.Resources.off)
End If
End Select
End Function
The only weird behaviour is when the OnOff setting has been set to TRUE. The correct image is displayed but the Toggle button looks unpressed. You have to click twice in order to set the OnOff setting to False.

Related

Dialog window positioning

I'm creating a small non-modal dialog in TornadoFX like this:
find<Grib>(scope).apply { openModal(block = true,
owner = FX.primaryStage,
stageStyle = StageStyle.UTILITY,
modality = Modality.NONE) }
How do I go about setting (and retrieving) it's window position for later? That is, I have a preferences object for the window location and I want to update it so that the next time the user opens the window, it opens in the same place they last closed it.
I was able to mostly solve my problem by digging through some of the TornadoFX source code.
I added this to my init{} function:
Platform.runLater {
root.scene.window.x = Main.preferences.getDouble(GRIB_WINDOW_X, 400.0)
root.scene.window.y = Main.preferences.getDouble(GRIB_WINDOW_Y, 400.0)
}
And then adding this to my close() function:
Main.preferences.putDouble(GRIB_WINDOW_X, root.scene.window.x)
Main.preferences.putDouble(GRIB_WINDOW_Y, root.scene.window.y)
This "mostly" solves the problem in that it does save/restore the window position, however the window flickers when it is created as it moves from some default position to the newly set position.

adding events to random buttons of the keyboard

Hello guys i really need your help . I want to make some program in javafx so i need to add listener to random generated button on the keyboard. For example :
i don't want to add some action if user type enter but i want to add action to some random button and nobody would know which is that button . so the user need to click every single button on the keyboard to find out which is that button.How would he knows that this is the correct button ? - > well the program will be executed , when he click on the wrong button -> nothing will happen.
Try something like this:
private void handleKeyPress(KeyEvent ke) {
String text = ke.getText();
KeyCode code = ke.getCode();
if ( ke.isControlDown() || ke.isMetaDown() ) {
//DO something for example
}
}

Disable MDI child Form buttons

Is there possible to disable child's form buttons from parent form?
For example, I have 2 radio-buttons in parent form, one is True second False, when I choose one of them fires radiobutton.CheckedChanged event and there I have code what goes like this, but it's not working:
ChildForm.Button1.Enabled = False
where seems to be the problem? Can anyone help with this?
You would need to create an instance of the childform.
So...
ChildForm cf = new ChildForm();
cf.Button1.Enabled = false;
You have to keep in mind though, it could be a different instance than the child form that is currently being shown.
To be sure, depending on your code (which I can't see) and how your program is laid out I would probably do something like this...
ChildForm cf = new ChildForm();
cf.show();
cf.Button1.Enabled = false;
so here I know that the ChildForm that is showing is the one that has the button disabled.
In VB6 the following project works:
1 MDI form:
Option Explicit
Private Sub MDIForm_Click()
Form1.Option1.Enabled = False
End Sub
Private Sub MDIForm_Load()
Form1.Show
End Sub
Form1 is a MDI child form with 2 radio buttons on it

Click and CheckStateChanged VB6

According to Microsoft:
"In Visual Basic 6.0, the Click event is raised when the CheckBox state is changed programmatically. "
and this is exactly what i do not want.
I want click event only raise when i click on the checkbox and not when the state is changed.
Any idea how to do it ?
Thank you
you can set a flag when you are populating the form from code to ignore changes. This can get messy if the code is not organized well.
Form Level:
Public IgnoreChange As Boolean
Form Load:
IgnoreChange = False
Event:
If IgnoreChange Then Exit Sub
Your code:
frmReference.IgnoreChange = True
frmReference.Checkbox1.Checked = True
frmReference.IgnoreChange = False
Code should only respond to user actions
Not sure if it's the best way, but one way would be to have a variable called something like IgnoreEvents and set that to true right before changed the state programmatically.
Then in the event handler if that variable is true, you just exit the event handler without doing anything.
Put your Click event code in the MouseDown event instead. You'll have to manually set the checkstate though:
Private Sub Check1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Check1.Value = IIf(Check1.Value = vbChecked, vbUnchecked, vbChecked)
' run other necessary code here
End Sub

Edit Control not updating with Spin Control MFC

I am trying to use an edit control along with a spin control using MFC visual studio .net 2003. I have carried out the basic settings for the spin control like setting the "AutoBuddy" property and "SetBuddyInteger" property to True so that the Spin control works in coordination with the edit control next to it. In my Spin control's event handler, I am facing a problem when I am trying to call my Invalidate() function. The float value in my edit control does not update and stays zero. If I remove the Invalidate(), then the value increments but my paint function is not updated obviously. A code of the following is given below:
void CMyDlg::OnSpinA(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
m_A = m_ASpinCtrl.GetPos(); // m_A is my edit control float value variable
Invalidate(); // Invalidate is to be called to update my paint function to redraw the drawing
UpdateData(false);
*pResult = 0;
}
I have carried out the tab order correctly as well for the two controls.
Any suggestions on where I am going wrong?
Thanks in advance.
If you just want to have a spinning integer, you don't have to override anything.
The spin control has to be right next to the edit control in the tab order. With AutoBuddy that's all you have to do.
m_A when getting the position back would do something weird and would not return you the correct value. Try using the pointer to get your position and value and then carry out the invalidate().
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
CString tempStr;
m_A += pNMUpDown->iDelta;
tempStr.Format("%f",m_A);
m_ACtrl.SetWindowText(tempStr); // Like a CEdit m_ACtrl to display your string
Invalidate();
UpdateData(false);
*pResult = 0;
}
This should work perfectly well. Let me know if you still get any problems.

Resources