Hiding or Closing a Windows Form on C# [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a windows form which have a textbox & a button on it.
I'll show & use this form for filtering some datagrid columns when right clicked their column header.
And this form will be using constantly obviously.
Now I'm thinking,
Should I close it everytime or simply hide & reshow when needed?
Which is the best for performance & memory? Or do you suggest any other thing for this filtering type?

Which is the best for performance & memory?
"Best" isn't a question nor a SMART requirement.
Of course if you just hide the form, it and its contents will stay in memory. This means your application uses more memory, but on the other hand, when you need to show the form again, you won't have to load the entries from the database again - making it appear faster.
If it's a form you really frequently need, I'd just hide and re-show it. See Hide form instead of closing when close button clicked how to do this.

If the app runs very fast, it may be better to close it. If loading is heavy - hide it.

Related

Where to store all the logic of the form's controls? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm creating WindowsForm app now and have a Form. For example, at this form i have a lot of different controls like, buttons, labels, panels, comboBoxes and etc. Most of the controls have events like doubleClick, dragAndDrop and etc. So the question is where should i store all the logic for this events? I can store it of course inside the methods that implement this evenets like btnOpen_Click() and etc. It works fine, but is it right? Cause all the logic will be now only at one file Form1.cs. Or maybe i should create some kind of a static classes for that? Usually i'm creating separate classes for storing and working with specific data, but at this case, when we need to store only logic i'm kind a stuck. If it's possible, can you provide some examples please or links of good looking code or materials to read in the internet? I tried to find something by myself, but i couldn't form my question for short searcher form.
I don't know if there is a 'right' way. The approach I used in the past when developing in large WinForms applications was to create custom controls then the control logic could be encapsulated in the control classes. Even if the control simply inherits from a standard control.

Status strip vs notify Icon [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
As part of a program, there are situations in which the user has to be quickly notified that something is going on.
I was thinking of using Notify Icons. For some reason, they appear but don't dissapear automatically as I expected. (As in toasts in other platforms)
Then I found the status strip. Which seems convenient too and simpler to program although I have to manually remove the message
or should I go for the old MessageBox as I have been doing so far.
what are the pros or cons on using those methods of communication with the user?
Depending on your usecase and the importance of your message to the user you'll have to consider the following points:
Is the message important enough to stop the users current workflow immediately, like a messagebox does?
Is it okay, if the users misses a message, because it disappears automatically after a certain amount of time?
A messagebox is clearly the most intruding way of communicating with the user. The status strip on the other hand can easily be missed. Notification Icons including a balloon tooltip are somewhere inbetween. The ballon will most certainly close after a few seconds. But you could also add a timer to remove the notification icon itself after a certain amount of time, too.

What is the best approach for the purpose to save the value of the variables and to get them passed between the WinForms? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am currently working on a C# project in which I got a couple of WinForms (currently 5 windows).
From these windows, I need to save all the information that has been filled(all the text from textBoxes, comboBoxes, dataGridViews, checkBoxes). In each window, there is control containing data I will need later to generate a script.
So my question is: What is the best approach for the purpose to save the value of the variables and to get them passed between the WinForms?
For now, I am storing the data from the controls in variables, but I believe there is much better and efficient way of doing this. (And also the variables are passing between the screens. So basically if I have in screen1 variable A, I need to access it from screen2 where there is another variable B, screen 3 needs A and B and variable C appears there, and so on ....)
I've been thinking about:
Saving the data in a text file(which I would like to NOT do it.)
User Settings (but I am pretty sure I cannot store the data from the grid in it. If I am mistaken I will appreciate letting me know!)
And the last one I mentioned I am using - passing variables between the WinForms.
You can create dto-class for each window, put data from window's control to corresponding dto and then serialize it.

How can I undo changes and retrieve previous form state in winform? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am programming a game, in which i sometimes need to undo some steps, is there a direct way to do this?
I tried putting the controls in data structures, stacks and lists and so, but things are too complicated in my game.
thanks
No, there is not a built-in way to do this; you have to code it yourself. I would suggest creating a class FormState which has members to represent the values of each control on the form whose state you want to save. Then add methods to copy the form values to and from the form. Finally, make a stack data structure in your program. Whenever the user changes something on the form, create a new instance of the FormState, call the method to transfer the current form state to the FormState object, and push it on the stack. If the user presses undo, pop the last state off the stack and call the method to restore the form controls from the FormState class. That's really all there is to it.

Can Page.IsPostBack property be used in Windows forms?? c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hi guys I am trying to use the "Page.IsPostBack" in my windows form project. I am aware that this can be used on web pages but can it be used in windows forms as well?
if so will I need to import anything?
No, those are two completely different paradigms. IsPostBack is meant for stateless programming, whereas windows forms is stateful.
Nope. Postbacks are used in web forms. .IsPostBack is not a member of windows forms so there is no way to use it.
Simplified summary:
WebForms needs the IsPostBack property because the form is loaded every time it posts back (traditionally this was anytime a button was pressed, though now AJAX changes that a bit). Because it stored a serialised version of all data in ViewState, you didn't want to reload the data in a lot of cases (this proved to be a huge issue as ViewState massively increased the page data, something for another topic).
WinForms only needs the OnLoad() handler, as the form is loaded once and stays on screen, no matter how many times a button is clicked. You can close and re-open the form, but it is valid to reload the data in that scenario. In your OnClick handler you can decide if/when to reload any data as required.

Categories

Resources