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

  • Home
  • SEARCH
  • 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 6108377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:17:25+00:00 2026-05-23T14:17:25+00:00

Scenario – Program opens a winForm. User enters info, clicks Start button. Action transfers

  • 0

Scenario –

Program opens a winForm. User enters info, clicks Start button. Action transfers to code in App_Code.Model. When that code finishes, code behind the winForm needs to display updated information. App_Code.Model shouldn’t know about the winForm. The winForm in this case has a button btnStart and a textbox tbInput.

But when the event is raised, it is null, so I am doing something wrong. Note, this is not about events raised from winForms userControls, I am aware there is a lot of information online about that.

App_Code.Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EventsTest.App_Code.Model
{
    public delegate void TableViewChangeHandler(object sender, HandChangedEventArgs e);

    public class HandChangedEventArgs : EventArgs{
        public int HandNum { get; set; }
        public int PlayerNum { get; set; }
        public HandChangedEventArgs(int handNum, int playerNum){
            HandNum = handNum;
            PlayerNum = playerNum;
        }
    }
    public class Game{
        public event TableViewChangeHandler TableViewChanged;
        public void PrepareGame(){
            int value = -1;
            if (TableViewChanged != null)
                TableViewChanged(this, new HandChangedEventArgs(value, 0));
            else
                value = 2;//used to set toggle to catch debugger
        }
    }
}

code behind form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EventsTest.App_Code.Model;

namespace EventsTest
{
    public partial class testForm : Form{
        public testForm(){
            InitializeComponent();
            Game myGame = new Game();
            myGame.TableViewChanged += this.HandleTableViewChange;
        }
        private void btnStart_Click(object sender, EventArgs e) {
            Game myGame = new Game();
            myGame.PrepareGame();
        }
        public void HandleTableViewChange(object sender, HandChangedEventArgs e){
            this.tbInput.Text = "Raised";
        }
    }
}
  • 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-05-23T14:17:25+00:00Added an answer on May 23, 2026 at 2:17 pm

    May be I understand. You have two instances of Game class:

    1. Is in ctor of the form and subscribes to the event.

    2. Is in btnStart_Click method which doesn’t subscribe to event and call PrepareGame(), so you don’t recieve event notification.

    MOve your event subaceiption code to button click handler and you done.

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

Sidebar

Related Questions

Scenario: A stored procedure receives from code a DateTime with, let's say DateTime.Now value,
Scenario: 1. Show navigation controller based view 2. User select option 3.   Show modal
Scenario: UserControl that has a read-only TextBox and a Button. TextBox.Text is modified and
Scenario: I run the find code issues function in resharper. I go one by
Scenario: I am having a dropdown, a button and html table which displays data
Scenario Consider the following code snippet. string s = S; string s1 = S;
Scenario: I start out in my app's main page. I navigate to sub-page A,
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario: Attempting to import many (>100), large(>1M recs) flat-files (csv). Problem: Many records are
Scenario: I'm currently writing a layer to abstract 3 similar webservices into one useable

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.