Question How to refresh Form1 from inside a class?

te777

New member
Joined
May 8, 2015
Messages
2
Programming Experience
5-10
I have a class that uses a dialog for user input. After the input, and before the following procedure to use the input, Form1 should refresh, but it doesn't. I have a garbled display for Form1. How can I refresh Form1 just after closing the dialog object?

 
There is no inherent function of a form that refreshes it, unless you're talking about redrawing it on-screen, which you're not. If you want the form to get new data and display it then you have to write code in the form to get the data and display it. There's nothing magic about it. However you displayed the data in the first place is the very same way you you display new data a second time.

If you want to initiate that in the form then you do it exactly the same way you always initiate something in an object, i.e. you handle an event of another object or another object calls a method. Does your other object have a reference to this form? If so then you can use the second option, otherwise you would use the first option.

If you're still confused, maybe you should show us some relevant code, mainly how each of these inter-related objects is created and uses the others.
 
I fixed it. I passed the form object to the class in the constructor, assigned a class Form variable to that passed parameter in the constructor body, and then did a classFormVariable.Refresh() in the class where I needed to. Thanks for the reply.
 
Oh, it seems that you actually did mean redrawing the form on-screen. I'm so used to people using the term "refresh" to mean reload data or the like that I assumed that you did too.

I would tend to look at why this is happening in the first place and try to avoid that rather than fixing it after the fact. It may be that calling Refresh on the form is the best option but that's usually not the case. My guess is that you're doing something on the UI thread that you shouldn't be, so I'd look at that first. Prevention is almost always better than cure.
 
I fixed it. I passed the form object to the class in the constructor, assigned a class Form variable to that passed parameter in the constructor body, and then did a classFormVariable.Refresh() in the class where I needed to. Thanks for the reply.
Hi te777,
could you Show us your fixed code?
Many thanks
EccoBravo
 
Hi te777,
could you Show us your fixed code?
Many thanks
EccoBravo
The OP's only two posts are in this thread and were made over six years ago. What chance do you think there is that they are going to answer you? Maybe you should start your own thread and detail your own problem and then we can deal with that specifically. I have little doubt that the solution implemented by the OP in this case was suboptimal anyway.
 
Back
Top Bottom