Disabling applications for form tasks (C#) - c#

I'm creating an add-in for Microsoft Excel that helps to automate some of my accounting processes. One of the pieces of the add-in is a ribbon tab with a button. Clicking this button opens a form with a list box that displays each account (worksheet) name and their respective balances.
The problem is that the rest of the controls in Excel are still tangible while the form is open. If, for example, a person were to change the name of the worksheet while the form was open, it may cause an error.
I noticed that message boxes render an application unclickable until they exit the screen. It isn't limited to just message boxes, either- I've seen the Nexus Mod Manager do the same thing when installing mods for games. I've seen it in many applications, but I haven't figured out how to do it myself.
My question is simple: how do I change the properties of a form such that the rest of the application is disabled until the form is closed?

What you need is a modal form. Opening a modal form will "block" the entire UI until it is closed, just like message boxes do.
Have a look at http://msdn.microsoft.com/en-us/library/aa984358(v=vs.71).aspx

Related

How do I create a popup for windows form settings

I need to create a popup in a windows form. For example if an user tries to change anything in the windows form settings they should get a popup dialogue. In the form there are five toolbar buttons. If the user jumps into another toolbar and tries to save changes they should get a popup dialogue.
May you design a new form and use the ShowDialog() method. It will open the form as a modal window. You will not be able to focus something different until this window is closed. The advantage is that you're able to design this "Pop-up" by yourself.
If you want to show something like a short message, a MessageBox.Show() will do your job! For more information about MessageBoxes you better read the official MSDN page, especially the parts concerning the Show() method and it's overloads.
Use this
MessageBox.Show("Error message",
"Title of error");

How to have a user navigate multiple "screens" within one form/window?

I am working on a project that simulates a company's program for performing various functions within a GUI (using C# on VS2010). Currently there are about 10 or so different forms, one for each function (serving as a menu, filling out assorted forms, management of said forms, ect). So far we've been using things along the line of:
Form1 myForm1 = new Form1();
myForm1.Show();
to open new screens and
this.Hide();
when finished with the currently active form. (this.Close() just seems to close the entire program)
This causes some issues in that the process has an issue of continuing to run after the X at the top right of the form is clicked (I think that this is due to hidden forms not being closed properly). I also suspect that if a user uses in-program navigation without killing the process long enough, the constant generation and hiding of forms will end up hogging up all the memory.
In the wild, I rarely see programs that rely on opening new windows/forms constantly to enable user navigation. Programs, such as an installer, typically use an event of some sort to cause the current displayed content to disappear and new content to appear without changing to a new form/window. How can I go about doing this? Is it a matter of having buttons/textboxes/labels all stacked on each other in the one screen, but hidden or is there something more intuitive that I am missing?
Have you looked in to using some kind of MDI setup: http://www.codeproject.com/Articles/7571/Creating-MDI-application-using-C-Walkthrough
The way you can do this (but isn't always feasible) is to make a UserControl for each screen. When its time to move on to the next screen, you simply hide the current user control and show the next one. So if you have 8 screens for example, you make each one into a user control.
Then on your MainForm's Load event, you initially hide all except the first one. When its time to move onto the second screen, you hide the first control and show the second, etc etc

control dialogbox of an external application

I'm writing a program in C# to automate another application. I use user32 api. When the external application needs user input, my C# program fills the boxes and presses the buttons. When a new window comes up, I can find it and it's controls using findwindow() and findwindowex() function but when this dialog comes up (in the picture) I cannot find the controls in it(the buttons). Even UI Spy cannot show them. I tried to send key events to this window but nothing happened. Can you give me some tips how to go on?

Can you open a form or window in an Outlook Addin (VSTO)

I am new to VSTO programming. I have created a basic addin for Outlook 2007 that monitors a folder containing XML text files which it opens and then sends them as an email, then deletes them. this all works fine.
I want the user to be able to configure certain settings for the way the addin/program will operate, such as the folder that it will monitor, and other things. The logical way to do this is to create a menu item in the addin (which I have also done) that opens a windows form (or XAML window) that allows them to enter the parameters.
In my addin I added a new item Windows Form, which worked, and the designer opened. However, in my addin code I cannot open the form. The Show() method normally associated with form objects is not available.
Is this simply something you cannot do, or am I just doing it the wrong way?
I have read about Outlook form regions, but these seemed to be attached to outlook items such as a new email, task, appointment etc... there doesnt seem to be a way to create a form region that can be opened in the main window of Outlook.
Ideally, I would like to go with my original method of opening a new window from a menu item, but if this isnt possible I would like to hear other solutions.
Thanks,
Will.
For a normal form, it sounds like you didn't just add System.Windows.Forms as a reference,
create the object then show it eg.
Form myFrm = new frmFlightList();
myFrm.Show();
This should work in a VSTO addin, as it does in any other form. The CMSConnectorControl object you refer to is a distraction to others for the general case of just wanting to display a form.
figured this out, After I built my form I just had to add these lines
CMSConnectorControl formMain = new CMSConnectorControl();
formMain.ShowDialog();
to the ThisAddin_Startup() function.

Activating Modal Windows after switching to an application

We have a C# application which contains both modal and non-modal windows. It is possible for a user to have several non-modal windows open and open a modal window from one of these.
If the user switches to another application and then switches back to ours by clicking one of the non-modal windows (other than the one which opened the modal window) in the Task Bar, the non-modal window becomes activated but does not accept input because the modal window is open, but is behind other windows.
How can we ensure that no matter which of our windows the user switches back to, the one which is modal is the one which is actually activated? This is the behaviour exhibited by Microsoft Outlook, for example.
Any assistance would be appreciated.
Its certainly possible, but is really annoying to maintain. I regularly work on an application which mixes modal and non-modal windows. This is my strategy (which isn't 100% full-proof)
Set the modal windows TOPMOST when
possible.
When certain actions are
detected (like pressing windows-d button),
you have to manually set the window
back to topmost. I dont know why the windows go to the back, but the behavior is not consistent between windows XP, vista, 2003, etc.
Its really annoying maintaining the code that rearranges the windows. I would urge you to try to not mix modal and non-modal windows.
Edit
I forgot to mention that i use WTL and alot of native win32 functions. I also try to create windows which have parent / child relationship so that keyboard and mouse messages get REFLECTED as much as possible to the child windows.

Categories

Resources