I am facing a problem in my application. There are multiple forms which can be accessed by quick setup button in the home page,which contains next and back buttons.
And in the last form there is a finish button, which when clicked goes to another form named Scoreboard. The scoreboard form is having a user control which have home button, setting etc.
When I click on home button it goes back to home page and then when the user clicks the quick setup again, I needs to retain the previous values in the form instead of creating new instance.
In the finish button i am using this code :
Scoreboard sc = new Scoreboard();
sc.show();
this.hide();
Any suggestions ?
There are a couple of ways that you can go. The first is since you are loading your Scoreboard form from the same button you can just subscribe to the Scoreboard Forms FormClosing Event and use public properties to get the information back into your parent form, you could then pass that information back to the ScoreBoard when you create the Form. Your other option would be to use UserSettings to persist your values in between sessions.
Related
So basically, I have a C# winform and it has multiple pages (which are different forms) when going to one page to another it closes the previous form/page. However, I have a “Settings” page and on that form I have a toggle button. That toggle button changes the text of a label on form1. If I force the form the open while the “settings” form is open, the text changes. However, I do NOT want that form to actually open I just want the text to change but when I take out the form1.Show(); , and just toggle the button off and switch back to form1 the text is the original and when switching back to settings, the toggle button has re-enabled itself. I cannot figure this out.
I have 2 WPF windows. Both the windows have textboxes and combo boxes. Upon entering data into Window1, the user presses a "Next" button and Window2 is loaded. Window2 has a "Back" button which will reload Window1 incase the user wants to change some values. Since it is the same session, I want the last entered values in window1 to appear when the "Back" button in Window2 is pressed. How should I go about doing it in C# or XAML?
you have to take one property in window 1 like
public string ChangeValue { get; set; }
when you press back buttion at that time you can set the property value using instance of window 1
instanceofWindow1.ChangeValue="Value";
Each window should have its own ViewModel. These contains the values you type in the windows. If you click next (and destroy the first window) the you should implement some kind of save method (ICommand that is invoked when clicking on Next) that saves the current state of the ViewModel to a model class (or a database or a text file ...). When you click back you have to reload the model, connect it with the ViewModel and show the Window1.
It seams you are not familiar with WPF, maybe the links from another answer might help you to get started: https://stackoverflow.com/a/2034333/1015350
Furthermore you should get into the topics:
MVVM
ICommands
Databinding
Rule of thumb: Your code behind file should contain nothing. This is all done by databinding.
I have an application using C# wherein I have a form which is MdiContainer form named parentmdiform in which all my child form gets open.
From submenu of this parentmdiform a form named studentmasterform gets open.from this form on a click of a button a new form named existingstudent form gets open.
When I want go back to studentmasterform again from Existingstudentform, a click of a button on which studentmasterform gets open.But the problem is my earlier opened studentmasterform from parent form does not get focused or disposed off.That means I get two separate object of same form that is Studentmasterform which exists in my parentmdiform.
What I want is ,that same form object should get either focused or disposed of when i click on any other forms within my MDI application to access earlier form.
Can anyone tell me how?
You need to track the creation of studentmasterform. And if it is there, created, don't create new one, do Keyboard.Focus(oldOne);
P.S. There is studentmasterform.Closed event to help you keep the track.
I hope I understand what are you want to do.
First, if you want that a Form closes if it loses focus, take a look at the "Deactivate" event of the Form class. [MSDN Deactive Event]: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.deactivate.aspx
When you need a Form as only once opened, you can check "parentmdiform.MdiChildren" to get all the children of your MDI From. You can give your Forms an unique name, so it's easier to focus the right.
regards, C#er
I have a tray app that starts ( Form 1 ) and shows on right click a "Login" menu strip item.
On click, I setup a Form 2, asking for user and pass.
On a successful authentication, I'd like to close Form 2 and continue with Form 1 ( ie. I would like to start a timer ).
I was thinking of just setting up a timer which would check the Form 2 status ( basically a getter function inside Form 2 ).
Still, I think there has to be an easier way than having something tick.
I dont think you need a timer or any thing for that just show the form as a Modal Dialogue and return to main form when closed.
You should show the login form using the ShowDialog method.
This method shows a modal dialog which will prevent the user from interacting with the rest of your application until the dialog is closed.
You should then perform authentication in the login form's button click handler, and close the form when it's successful.
New to C# and .NET.
In a windows application I place a form to query a user for some input. The user fills out the form and presses 'ok'.
What is the "correct" or "appropriate" method of retrieving that data from the form? Do forms have a return statement? Do I send a message?
Thanks in advance.
you can have the parent form subscribe to events from the child form and still do the same thing or put the form results into an event arg statement
you should listen to the click event of the button and you will get a call back and you can simply read the properties from the form objects (txtBox.Text, etc . . )
After they press OK, the form will close, but (as long as the form variable is still in scope), its members will still contain all of the data. Save the input to a member variable and access it from your main program using an accessor. If the form is not modal, your main program can subscribe to the form closing event and get the information then.