Is there a concept of session management in Winforms applications? [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 8 months ago.
Improve this question
Today I was asked why we cannot implement state management in Winforms applications like we do in web applications, and I did not know the answer.
Can someone explain why we cannot, or if we can, explain how it works at a high level?

[...] why we cannot implement state management in Winforms [...]
This is an incorrect statement. In fact, we implement session management in every Winforms application, and we are so habitual about doing it that we don't even realise we are doing it.
The very nature of a desktop application is that all the state information you need is available in process memory, and it remains available as long as your application is running.
For example, it you set the value of a string variable to "Hello World", it will retain its value as long as that variable is accessible. Unlike web applications, you don't have to do anything explicitly to retain it. So the correct question might be
Why don't we need to implement session management in a WinForms application?
although I would be stumped by the obviousness of answer.

We can implement state management in Winforms.
Assume you need to access a Winforms control value in another Winforms application by clicking a button on the first form. You can access them by:
declaring public class members and auto implemented properties in the second form.
Set the values of the second form's class members in the first form's button_click event
After step 2, run the code you want to run on button click.
So the class and its members can be used in achieving state management in Winforms application.

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.

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 to override other windows application's elements? [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 8 years ago.
Improve this question
Can you please point me into the right direction?
I want to edit other application textbox or click, programmatically. For example, in a web sites, I can edit elements and invoke button clicks.
I have no idea how to do this, but I can move mouse and use keyboard run time is it possible to edit other application's textbox ?
I have C++, VB.NET, and C# knowledge - any suggestions or sample code?
Thanks.
There is no easy way to do this, but it is possible. You will dig through the Win32 Api to get what you need. There will be a lot code needed for this, too much to put in sample here.
You will need to start with finding the window you want. This could be accomplished with FindWindowEx. When you have the window, you can enumerate the child controls using EnumChildWindows.
When you finally get the handle to the control you need, you can hook up to the windows message subsystem and send a WM_SETTEXT message using the SendMessage function. There is a wrapper function available: SetWindowText but the documentation clearly states that it will NOT work for windows of other applications.
Be prepared for a lot of digging around in the Win Api. You will probably run into issues regarding security in newer windows OS's. When you get it to run the functionality will be highly depending on the OS, UAC settings etc.
I remember doing this once, 15 years ago in Windows 98, even then it was problematic! So good luck!

How to make my C# windows application lightweight? [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 8 years ago.
Improve this question
Guys I have developed a ticket management system in C# windows forms application. Now this is the first time I have developed any application that might be used in real world (my school may implement it).
As my school is not that rich and mostly run by charity, so the technology they use is pretty old (Pentium 4 pcs with windows XP having maximum of 1 gb RAM), so I need to make my application as light-weight as possible i.e. it should not be resource hungry. (I have developed this app on dual core laptop with 4 gb RAM, and I haven't come up with any errors yet regarding to resources but considering the low config of target PC(s) I want to be sure)
I have about 25 forms in my application, in which 7-8 have DataGridViews in them. Others are just filled with labels and textboxes for taking input or display data - nothing fancy.
As this is my first complete application I am not sure how it will perform in the performance department. I read somewhere that in .Net applications you have to call dispose() method whenever the form is closer or else the garbage wont be collected and same goes for DataGridView. Is that true? because throughout the application I haven't used Dispose anywhere. Should I be worried?
If Dispose() is necessary, where and when should I call it? on FormClosed event? If a form has DataGridView should I dispose it first and then dispose form or is directly disposing the form enough? Also if you "experienced programmers" could point out some good practices to make application less resource dependent and less crash-prone then that would be great.
As far as I'm aware C# (and .NET) is managed. So your code and objects will get disposed of.
A good trick, is to look at using Using blocks. These are especially useful around data connections.
The other obvious piece of advise is to actually run it on the machines you will be using it and, and see how it performs.
Hope this helps.

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