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.
Related
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
I am developping an Outlook 2007 Add-In.
I have designed a Windows Form allowing to display operations the Add-In performs. The form is displayed modally.
In this form, I have 2 buttons, one to open an inspector on a mail item, the other to open an inspector on a contact item.
The "Show Mail" button behaves nicely, but the "Show Contact" always raises an exception saying that there is a dialog box open and I should close it before opening the contact inspector.
As the code for these 2 buttons is exactly the same, what would be the problem with the contact item inspector?
private void btnShowMail_Click(object sender, EventArgs e)
{
logEvent.MailItem.Display(true);
}
private void btnShowContact_Click(object sender, EventArgs e)
{
logEvent.ContactItem.Display(true);
}
If the problem is that my Form is open, I don't see how to work around.
Thanks for your help!
I have the same problem, I found that method ContactItem.Display is in colision with your form (If your form is a modal dialog)
Workaround:
If you are opening your form like:
myForm.ShowDialog();
change it to:
myForm.Show();
I know - thats not a good solution, but I didnt found better. :-(
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
How do I kill a windows form application other than clicking the x button. More specifically, I need to close the program from a menu option. I am coding this in c# 2010.
You mean Application.Exit()? It can be called from any block of code, such as a menu option or a button click.
Use the Close method on your main form.
Use the following code for proper exit.
Environment.Exit(0).
This will terminate the application and inform the Operating system as process completed successfully.
You can call it from menu, text click event, button event etc..
More info
You need to assign a custom handler to your menu item's OnClick event handler:
(Pseudocode)
MenuItem_CloseWindow.OnClick += new OnClickHandler(YourMethodHere)
....
YourMethod(object sender, EventArgs e)
{
this.Close();
}
That should do the trick.
All Windows Forms come with the built-in ability to close them using the System Menu. Just press ALT + SPACE and it will show the Close option unless you have set the ControlBox property to False.
You can use for a basic Windows Form
System.Windows.Forms.Application.Exit();
If you are using Xaml/WPF you can use:
System.Windows.Application.Current.Shutdown();
Note: I only added this because some people think WPF and c# are the same.
I'm trying to get my application to display a popup context menu when a user right-clicks on my notify icon in the system tray... but there's a twist.
I'm aware that the NotifyIcon class I'm using to get the icon in the system tray has a ContextMenu property. I don't want to use that to get a right-click popup menu, because it ALWAYS displays a right-click popup menu, and never does anything else. When my main form is displaying a modal dialog, I want right-click to activate the main form, NOT display a popup menu.
So, I'm guessing I need to use the NotifyIcon.MouseClick event, and manually pop up the menu in that event? Here's where I've got to so far:
private NotifyIcon trayIcon;
private ContextMenu iconMenu;
private void frmMain_Load(object sender, EventArgs e) {
// [...]
this.trayIcon.MouseClick += new MouseEventHandler(trayIcon_MouseClick);
iconMenu = new ContextMenu();
// [...]
}
private void trayIcon_MouseClick(object sender, MouseEventArgs ea) {
this.iconMenu.Show(Program.instanceFrmMain, new Point(System.Windows.Forms.Cursor.Position.X - Program.instanceFrmMain.Left, System.Windows.Forms.Cursor.Position.Y - Program.instanceFrmMain.Top));
}
Notice how in iconMenu.Show, because it takes popup co-ordinates relative to the parent control (my main form here), I'm annoyingly having to subtract the parent control's co-ordinates from popup co-ordinates, something I already don't want to have to do.
Apart from that, here are the problems I'm having:
Although the menu does popup on right-click, it doesn't close if I click somewhere else on the screen outside the menu - and it should.
The menu doesn't quite popup in the right location; for other system tray apps, it pops up so its bottom-right or bottom-left corner are at the tip of the mouse cursor. For mine, the popup menu is at the base of the screen, to the side of the mouse cursor.
Any ideas how I can get this to work better? I know it's possible, plenty of other apps manually handle the displaying of a popup menu manually instead of using some NotifyIcon.ContextMenu property.
Use the ContextMenuStrip property rather than ContextMenu. The ContextMenuStrip class has an Opening event, which you can cancel by setting e.Cancel = true. That way you don't have to worry about the location of the menu, since it is automatically handled
OK, well I didn't manage to get the functionality I wanted as I described in the original question, but I have managed to find a way to achieve the desired effect using a different method.
I DO attach a ContextMenu to the trayIcon.ContextMenu property, but I attach event handler code to the Popup property of the context menu itself. If, in that handler, I .Clear the ContextMenu, it actually doesn't appear at all, allowing my code to elect to effectively stop the trayicon's popup menu from showing if it wants to. This was the effect I was looking to achieve. If I populate the ContextMenu in the Popup event handler code instead, the menu pops up as usual containing what I populated it with.
Sooo, I managed to solve the problem a different way. :-)