Menu and Main app forms, correct way? - c#

I have a main Form app. OnLoad it displays with Docstyle=Fill the main menu which is done by user control. If the user selects a choice in that Menu control, it fires an event (with one parameter Choice) which main forms reacts on.
If the choice is run the app, it closes the user control (dipose) and call method starting the app. If the choice is to quit, it calls Application.Exit. Is that alright form programmers point of view?

If you don't have to save any data and you just like to quit the application, it's the best way to do like you described. If you're using other windows you could use the collection Application.OpenForms and close all open windows.

Related

WPF - View getting minimized during navigation

I have a WPF application which behaves weird when another application is also opened. 'Another' application is developed using Panther. WPF apps behaves correctly with all other apps in the machine.
While both the applications opened, and when we click next on the WPF app, the app getting minimized even though its active as per windows active event.
WPF application is built using galasoft and follows slightly different approach in navigation compared to the pattern available when we search.
We initiate the Page from app.xaml.cs and based on the click, we invoke currentPage.Hide() and nextPage.Show() methods. All the navigations are written within App.xaml.cs file. Through a delegate the button click will be passed to app.xaml.cs file and the pages are switched.
Did anyone else face similar kind of issues?
Finally, I managed find an answer/work around to this issue.
In the existing design, the sequence of actions were Hide() the current view and Show() the next view.
Now, we modified the sequence to perform Show() the next screen first and then hide() the current screen. This way, the window was kept active and was visible to the user.

How can I temporarily prevent a form from getting focus/activating?

my application opens n forms and the user can freely switch back and forth among these forms.
When the user decides to confirm the operations performed on one of the forms, I would like to block the other ones until this process (which can potentially open MessageBoxes and/or other forms) comes to an end.
It is not enough to disable the forms, since the user can't do anything on them, but the Activated event is fired, and this is exactly what I want to avoid.
I tried to set ControlStyles.Selectable to false to all these forms, but it doesn't work.
Just in order to make it clearer, the forms cover the whole screen, so the users activate them clicking on the taskbar. This is the situation where opening a modal form and having the confirm code executed there does not prevent the Activated event to be fired.
Try to use Form.ShowDialog() method.
You can use Form.ShowDialog Method method to display a modal dialog box in your application. When this method is called, the code following it is not executed until after the dialog box is closed.

how to prompt the user before form load event fires in windows forms application using c#?

i want to prompt the user to enter his number to get the details from database before the form Load event fire in windows forms application using c#?
can anyone please tell me how to implement this?
thanks in advance.
Put it into the Main method of Program.cs.
You can show a winform or dialog in the Main method before you run your main application. This allows the user to enter some data and you can then act on that before running your main form.
I have an application that can start in one of two ways. I display a selector window from Main. The user selects from the options and I collect that when the selector form closes.
I then start my main form taking account of that. This would also allow you to start different forms depending on the user input if you wish
Write your code in program.cs or in constructor of form

How to keep a window on top of all other windows in my application only?

I would like to display a status window in my C# Windows Forms application that informs the user when the application is waiting to acquire a lock. This is an application-defined thing, however, the window should be visible and always remain on top of all other windows of my application, even when the user clicks on another window (like for example the larger main window behind it).
It must not be modal (so ShowDialog() cannot be used) because the app needs to keep trying in the background and close the window automatically if the lock could eventually be acquired, and it really should not be top-most for the entire window station (i.e. all applications running in that terminal session).
I know the Form.TopMost property, but it can only bring and keep a single window above all others, even those from other applications. This is clearly not what I'm looking for.
I know that this is possible, I've seen it many times before in other applications. I just don't know how it can be done.
If you pass your main form into the Show method of the status form, it will stay on top of the main form, but not on top of other applications. So, in the main form you can have code like so:
StatusForm statusForm = new StatusForm();
statusForm.Show(this);
However, this will only point out one single window of your application as the owner.
You have to set the Owner property of the child form to the parent form, and use Show to show the child form.

Windows Mobile- only keeping one form open. Best design question

So I would consider myself a .Net and ASP.NET pro but I am a bit new to Windows Mobile (I am targeting .net 3.5 CF and Windows Mobile 6).
I am creating a data driven application that will have 3-4 tables. I have created a form for each table that allows the user to search through the table.
Each form inheretes from the Main form so that they each have the same Menu.
My question is how do I make sure that only one Window is open. I want to allow the user to go to the menu and choose a table which will open a new form. What I don't want is for the user to open say each form and then when they are done to have to close 3 or 4 windows. Is this possible? If so how do I do it? On a side note is there a better way to do this. I don't want all my logic on one form. So I don't just want to hide and show and panels.
I keep something I call an application hub that everything goes though.
So each menu click will call the applciation hub, and each form will reference it.
Then, when switching form, the application hub needs to keep track of the current form, close it, then load the requested form.
This isn't much code to write, and performs well.
Or...performance wise, keep the application hub idea, and keep the dialogs open. It will perform better that way, rather than having to reload the forms all the time.
Then on shut down, the application hub can check which forms are open (it should have a reference to each running form) and close them for the user.
Instead of having multiple Forms (inherited form mainForm) you could put the table stuff on UserControls and have total control about their Creation/Destruction/Visibility much easier.
Use an Interface or a BaseUserControl to implement common functionality.
This article, while not exactly what you are asking, was very helpful when I was redesigning a .NET CF application: Creating a Multiple Form Application Framework for the .NET Compact Framework
My application required a bit of both worlds - I wanted to have a single form open, but also sometimes wanted to stack a secondary form on top of the first (eg. if they go to a Prefs page or some other type of form where they should only ever dismiss it after a moment).
(Pseudo-coding after this)
I created a ViewManager and implemented it as a singleton. When the app first launches, I call ViewManager.GotoForm(frm). This sets the current form to be whatever form I need.
Then I immediately call ViewManager.CurrentForm.ShowDialog() - I'm sure there's a better way, but I found I had to call ShowDialog() at SOME point just to get a form to appear.
Subsequent calls to ViewManager can take the form .ReplaceForm or .StackForm. The differences should be fairly intuitive.
What you can also do in a view manager like this is cache forms that aren't being displayed, but probably will be again and have expensive setup costs (for instance, in a data-driven app you might have to query the database to determine the fields or tables to display on a form, and this won't change at runtime).
The trick here is that you never call .Show() or .ShowDialog() anywhere in your application - you route all form navigation through the view manager which handles loading the next instance of your form, disposing of old forms (if not being cached), and dispatching any sort of populate logic if you want to pass new data to a form's UI before it loads.

Categories

Resources