Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:16:57+00:00 2026-06-05T20:16:57+00:00

I have a windows form app, and a class which is called Game. Let’s

  • 0

I have a windows form app, and a class which is called Game.

Let’s say Game class has an attribute counter, and i do some calculations and change counter in that class. So i want to return a text to the form whenever counter changes, and then assign it to a label on the form.

Can i do it with an event handler that returns type string ? Since i have to listen it and return something whenever something happens.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:16:58+00:00Added an answer on June 5, 2026 at 8:16 pm

    Yes you can :p

    A proper way of doing this is as follow (INotifyPropertyChanged will simply tell you what property has changed and doesn’t return the actual value, but is also a good way to go):

    class CountArgs:EventArgs
    {
       public int Count{get;set;} 
    
        public CountArgs(int c) { 
            Count = c; 
        }
    }
    
    class Game
    {
    
       public event EventHandler<CountArgs> CountChanged; // it is possible to define your own delegate here.
       int count;
       public int Count
       {
          get { return count;}
          set { 
                if (count != value) // Only raise the event if the value changes
                {
                     count = value;
                     RaiseCountChangedEvent(value);
                }
       }  
       void RaiseCountChangedEvent(int c)
       {
          if (CountChanged != null) // Check that at least one object is listening to the event
          {
              CountChanged(this,new CountArgs(c));
          }
       }
    }
    

    Hopefully, I didn’t make any syntax mistake as I coded this by head 🙂 But you get the idea.
    You can register your form with the even and listen to it as you would do with any control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A theoretically question: I have a C# Windows Form app, that sends back some
I have a Windows Form application. Version 1 of my app has been released
I have a c# windows form app in which we did a rapid prototype
I have a windows form app written in C#. the main_form class instantiates an
This is the situation. I have a windows form app that uses an access
I have an In-house windows form app that I would like to use Spell
JI have written a .NET C# Windows Form app in Visual Studio 2008 that
I have a Windows Form application. What this application does, is let the user
I have a class library which is called through COM from a Third Party
I have wrote a frame application, it's a windows form app as parent form.When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.