How to focus an Outlook 2010 custom ribbon tab - c#

I have a custom Outlook 2010 Ribbon tab that has the type Microsoft.Outlook.Appointment.
In that tab, I have several buttons that change the current appointment item, and call its Save method. However, that method always changes the focus to the first tab of the inspector. I want the focus to remain on my custom tab.
Here is my current code:
private void ButtonSaveAppointment(object sender, RibbonControlEventArgs e)
{
Outlook.Inspector inspector = (Outlook.Inspector)this.Context;
Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)inspector.CurrentItem;
appointment.Save();
this.RibbonUI.ActivateTab(this.Tabs[0].ControlId.ToString());
}
This does not work for me. Can anyone tell me what am i doing wrong?
Thank you.

This is what i use in my load event:
ThisRibbonCollection ribbonCollection = Globals.Ribbons[_inspector];
ribbonCollection.RibbonSMS.RibbonUI.ActivateTab("the_name_of_the_ribbon_tab");
And that would correspond to what i see in your code:
this.RibbonUI.ActivateTab(this.Tabs[0].ControlId.ToString());
That code fires well in the load event, but i tested it and it does not work when you are calling it from a function. Please try and move it to the load event and you will see that the code works. My guess is that it does not work properly from a method but just form the load event.
Good luck

Related

VSTO Outlook: Catching Send Event

I am trying to create plug-in that will catch any send item and show warning before sent out.
Currently I am using the below code
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Application application = Globals.ThisAddIn.Application;
application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
However, I noticed it catches almost all the send event but when send button is pressed from main screen of Outlook, I mean when the mail is not popped out to separate window, it does not catch the event and my plugin function is not executed. My environment is Visual Studio 2019 and Outlook 2019. Any advise is appreciated.
Thank you,
Catch all the send event from Outlook.
Update 11/7/2022: it turned out that the event is caught but
I am tryning to catch the item type by the below method and inline item does not detected as an item.
itemtype = Application.ActiveWindow().CurrentItem.Class;
I can confirm that the ItemSend event is fired for all outgoing emails in Outlook, including inline responses. To make sure I've just created a sample VSTO add-in and placed your code there. Everything works correctly when I reply to items in-place. Try to declare the Application object at the class level. But I think everything should work as is now.
Outlook.Application application = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
application = Globals.ThisAddIn.Application;
application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}
You may consider subscribing to the Explorer.InlineResponse event which is fired when the user performs an action that causes an inline response to appear in the Reading Pane. So, you may get the item composed and do whatever you need (subscribe to the Send event).
Be aware, a low level API such as Extended or Simple MAPI doesn't trigger the ItemSend event in Outlook - only actions made in the Outlook object model or made manually can trigger the event.
It should work in all cases, but Outlook disables most OOM events for the items created using Simple MAPI or from the "mailto:" links. Is that the case?

VSTO my add in is prevent other Outlook items

I am adding a plugin in Outlook (2013 and up). Click on My Add-on Open a specific parameters window, this window becomes modal and prevents access to other Outlook items.
Only if I confirm or cancel this parameters can I access other items.
I probably need to add some functionality in Click_event to the ribbon in my-add-in.
private void Button_Click(object sender, RibbonControlEventArgs e){
//e.Control.Tag is "RibbonId=Microsoft.Outlook.Explorer"
}
Any idea how can I prevent this behavior? What I need add to my click_event ?
It seems you need to show a non-modal window by using the Form.Show(IWin32Window) method instead of Form.ShowDialog.

Click button after webBrowser1_DocumentCompleted event

I have a C# 4.0 WinForms application, which has a WebBrowser control and 2-buttons.
Clicking the first button sends a URL to the browser to navigate to a specified webSite.
Clicking the second button parses the OuterHtml of the webBrowser1.Document, looking for an "https://..." link for File Download.
The code then uses a webClient.DownloadFileAsync to pull down a file for further use in the application.
The above code successfully works, if I manually click those buttons.
In an effort to automate this for the end-user, I place the first button's click event, i.e. btnDisplayWeb.PerformClick(); in the form's Form1_Load event. This also works, allowing the webBrowser1 to populate its Document with the desired webSite.
However, I am unable to programatically click the 2nd button to acquire the web link for file download.
I have tried to place the 2nd buttons click event within the browser's DocumentCompleted event, as shown below.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
btnMyUrl.PerformClick();
}
However, from what I've read on StackOverFlow and other sites, it's possible that this particular event gets called more than once, and hence it fails.
I've also attempted to loop for a number of seconds, or even use a Thread.Sleep(xxxx), but the browser window fails to populate until the sleep or timer stops.
I attempted to use the suggestions found on the following StackOverFlow site shown below.
How to use WebBrowser control DocumentCompleted event in C#?
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string url = e.Url.ToString();
if (!(url.StartsWith("http://") || url.StartsWith("https://")))
{
// in AJAX
}
if (e.Url.AbsolutePath != this.webBrowser.Url.AbsolutePath)
{
// IFRAME
}
else
{
// REAL DOCUMENT COMPLETE
}
}
However, in parsing the OuterHtml, nothing is returned in the first two sections, and in the third section, other elements are returned instead of the desired "https://..." link for File Download.
Interestingly, if I use a webBrowser1.ReadyState event, as shown below, and place a MessageBox inside DocumentCompleted, this seems to allow the browser document to complete, because after clicking the OK button, the parsing is successful.
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
MessageBox.Show("waiting", "CHECKING");
btnMyUrl.PerformClick();
}
However, I then have the difficulty of finding a way to click the OK button of the MessageBox.
Is there another event that occurs after the DocumentCompleted event.
OR, can someone suggest how to programmatically close the MessageBox?
If this can be done in code, then I can perform the buttonClick() of the 2nd button in that section of code.
After finding that the addition of a MessageBox allows the webBrowser1.Document to complete, and using webBrowser1.ReadyState event within the webBrowser_DocumentCompleted event, all I needed to do, was to find a way to programmatically close the MessageBox.
Further searching on StackOverFlow revealed the following solution on the site below.
Close a MessageBox after several seconds
Implementing the AutoClosingMessageBox, and setting a time interval, closed the MessageBox and allowed my button click, i.e. btnMyUrl.PerformClick(); to successfully parse the OuterHtml and now the code works properly.
Hopefully, if someone else discovers that placing a MessageBox within the webBrowser_DocumentCompleted event allows the document to complete; the aforementioned AutoClosingMessageBox will assist them as well.

MaskedTextBox.SelectAll on GotFocus doesn't work with mouse

I want to select all the contents of a MaskedTextBox when the clicks (or tabs onto) the control, so they can easily replace the old content. I tried calling SelectAll() in the Enter event, but that didn't work at all.
I switched to using the GotFocus event, which works great when tabbing through controls, but doesn't work when I click on it with the mouse. I would only want to select all the contents when first entering/focusing on the control (subsequent clicks might be used to position the cursor to edit the existing text).
I added a button and tried calling SelectAll() in the button click event, but that didn't do anything either. What's going on? Is this a bug?
How can I get around this?
Steps to reproduce
Create a new Windows Form Application in .NET 4.0 in Visual
Studio 2010.
Add a TextBox, MaskedTextBox, and Button to the default form
Change the Mask property on the MaskedTextBox to "_____".
Add some event handlers:
private void maskedTextBox1_GotFocus(object sender, EventArgs e)
{
Debug.WriteLine("GotFocus");
maskedTextBox1.SelectAll();
}
private void button1_Click(object sender, EventArgs e)
{
Debug.WriteLine("Click");
maskedTextBox1.SelectAll();
}
Run the program, entered some data into the MaskedTextBox, tab through controls back to it. It selects the contents of the MaskedTextBox.
Select the other TextBox. Try clicking on MaskedTextBox. Output shows that GotFocus event was called, but text doesn't get selected.
Try clicking on button in form. Text doesn't get selected.
Tested in Visual Studio 2010 with .NET 4.0 in a Windows Forms Application project
Why this isn't a duplicate of TextBox.SelectAll() does not work with TAB
If you notice, the title says "SelectAll doesn't work with TAB". In my case, it does work with Tab, it doesn't work with the mouse - completely opposite scenario. The answer for that question is to use the GotFocus event. I'm already using the GotFocus event, but it doesn't work. That answer does not answer this question. It is clearly not a duplicate. If I'm wrong, please explain in the comments.
Your SelectAll() is being overwritten by the default functionality of the masked textbox select. I would use the Enter event, it allows for tabbed entry or mouse click entry to the masked text box. You will most likely need to use the BeginInvoke method. Try the code below. It worked for me when I tried...
private void maskedTextBox1_Enter(object sender, EventArgs e)
{
BeginInvoke((Action) delegate { SetMaskedTextBoxSelectAll((MaskedTextBox) sender); });
}
private void SetMaskedTextBoxSelectAll(MaskedTextBox txtbox)
{
txtbox.SelectAll();
}
Executing Focus before Select All worked for me:
private void Masked_Enter(object sender, EventArgs e) {
((MaskedTextBox)sender).Focus();
((MaskedTextBox)sender).SelectAll();
}

What is the event which fires every time when i click outside for my wpf page?

i am developing windows application using wpf. I want to do some functionality when i click outside of my control created. for example, if i have Message-box open in my window, i want to do some function if i click outside of my Message-box window.
I tried,
private void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
.....
}
but its not working.. please any one tell me, what is the event fire when i click outside of my control?
you have two supposed solutions:
one of them is to get Mouse.X, Mouse.Y from System not from application, this article will help
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
second which is better is not using Dialog, but use PopUp window and this article will help
how to close a WPF Dialog Window when the user clicks outside it

Categories