how to call event after load | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how to call event after load

My english isn't very good. In Windows Forms we have Form_Load(...), how can I do it in my class?

13th Sep 2017, 9:48 PM
Kacper Piotrowski
Kacper Piotrowski - avatar
16 Answers
+ 6
you can find sample in link below https://code.sololearn.com/Wkl3IriRYcK1/?ref=app
13th Sep 2017, 11:02 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 6
window.onload = function() { // your code here }
13th Sep 2017, 11:06 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
Ok, but if we have... I don't know C#... Is constructor in Windows Forms and we can make Form_Load. How make this? It can be JS C# etc.
14th Sep 2017, 4:30 AM
Kacper Piotrowski
Kacper Piotrowski - avatar
+ 1
Where do you start, what do you want to do ? What is your development environment? if you start in visual atudio, and you have a winforms project. You can go to the project explorer, choose add and add a empty form. If you have the empty form you can go to the proporties window and add event from the events tab.
14th Sep 2017, 6:14 AM
sneeze
sneeze - avatar
+ 1
Sorry C# VISUAL STUDIO 2017 community I want to make an event in my class that will be working as event Load in Windows Forms
14th Sep 2017, 10:36 AM
Kacper Piotrowski
Kacper Piotrowski - avatar
+ 1
Good answer Is your class a class or a form ?
14th Sep 2017, 12:44 PM
sneeze
sneeze - avatar
+ 1
This was a lot harder than expected. I haven't solved the problem yet but I like to hear from you, what you already know about events. Here is some code, I have written for you. https://code.sololearn.com/c3Ua61bw096U My simple thought was 1) make a delegate public delegate void Reached5EventHandler(); 2) create the event public event Reached5EventHandler OnReached5; 3) write the code that fires the event if( animalcount == 5 && OnReached5 != null) { OnReached5();//Raise the event } 4) create a method that does something when the event fires static private void DoReach5() { Console.WriteLine("This is the point where you can react on the event"); } 5) assign the event handler to a method in the main myFarm.OnReached5 += new AnimalFarm.Reached5EventHandler(DoReach5); This works for Reached5 event but not for OnLoaded event Why not because The event is raised before it is assigned I do not know you what your current knowledge is Hope this helps ? Did you already make a event like Reached5 ? I Need to think further about how to created a real OnLoaded event Some links I used https://www.intertech.com/Blog/c-sharp-tutorial-understanding-c-events/ https://www.codeproject.com/Articles/11541/The-Simplest-C-Events-Example-Imaginable
15th Sep 2017, 9:15 PM
sneeze
sneeze - avatar
+ 1
Your welcome, please ask your questions here in the Q&A (use tag c#)
16th Sep 2017, 8:24 AM
sneeze
sneeze - avatar
+ 1
Ok :)
16th Sep 2017, 8:49 AM
Kacper Piotrowski
Kacper Piotrowski - avatar
0
Are you looking for a constructor ? myclass (){} or a public method you can call public method1 (){} or a real event ?
13th Sep 2017, 10:06 PM
sneeze
sneeze - avatar
0
Class a class
14th Sep 2017, 12:59 PM
Kacper Piotrowski
Kacper Piotrowski - avatar
0
Do you want method when you create the object or just a method that you can call or a real event ?
14th Sep 2017, 1:44 PM
sneeze
sneeze - avatar
0
event public Window() private void Window_Load(object sender, EventArgs e) this Window_Load calling after Window() but I don't call anywhere Window_Load how make this event in my class
14th Sep 2017, 3:58 PM
Kacper Piotrowski
Kacper Piotrowski - avatar
0
so?
15th Sep 2017, 6:14 PM
Kacper Piotrowski
Kacper Piotrowski - avatar
0
Please wait a sec. The answer is in my head already. I did not have the time to write it down.
15th Sep 2017, 6:29 PM
sneeze
sneeze - avatar
0
Thanks for your time and help, I'd like to know if its possible to continue our cooperation, and If you could support me with some advices next time. I will try doing my best. Thanks in advance.
16th Sep 2017, 8:13 AM
Kacper Piotrowski
Kacper Piotrowski - avatar