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 3622780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:18:07+00:00 2026-05-18T23:18:07+00:00

I have a userControl11 (either in winform or wpf) which has a ValueChanged custom

  • 0

I have a userControl11 (either in winform or wpf) which has a ValueChanged custom event. If I put it in client form and in form_load set its value to 100, it will trigger the ValueChanged event. But if I set this value inside the constructor of UserControl1 the custom event won’t trigger. How can I force it to do so ?

whatever the technical reason, functionally it does make sense. If the object is initializing its value from some sources unknown to the client form and the client form has a textbox bound to this usercontrol value, it is sure convenient that it could refresh its textbox at any time including when the form loads just using one single event handler. Without this the client form has to create another initializer for this bound textbox at form load.

Below the source code of my trials in winform:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void userControl11_ValueChanged()
        {
            MessageBox.Show(userControl11.Value.ToString());
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           // This will trigger ValueChanged Event
            userControl11.Value = 100;
        }
    }
}



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace customevent
{
    [DefaultEvent("ValueChanged")]
    public partial class UserControl1 : UserControl
    {
        private int m_value;

        public delegate void ValueChangedHandler();
        [Category("Action")]
        [Description("Value changed.")]
        public event ValueChangedHandler ValueChanged;

        public int Value
        {
            get { return m_value; }
            set { 
                m_value = value;
                if (ValueChanged != null)
                {
                    ValueChanged();
                }
            }
        }

        public UserControl1()
        {
            InitializeComponent();
            // this won't trigger ValueChanged Event
            this.Value = 100;
        }
        public UserControl1(int iValue)
        {
            this.Value = iValue;
            InitializeComponent();
        }

    }
}
  • 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-18T23:18:08+00:00Added an answer on May 18, 2026 at 11:18 pm

    From within the class you can use the On Events.

    On events are protected, so you can’t trigger them from the hosting form, but from within the class you can call them. (if you want to trigger them manually from outside the calss, you’ll need to expose them with a custom method.)

    public UserControl1(IEnumerable<Action> subscribers)   {
    
       this.OnValueChanged(new EventArgs());
       this.Value = 100;
    }
    

    Read about the specific event you are calling, and send the proper EventArgs to the event.
    The On events are the methods that call the events.
    The On events are protected, you can overload them, just remember to use the base function at the end.

    Edit:

    According to the Event Design in MSDN, each event has a matching method called OnEvent (the same name with the On prefix).
    These methods are used to raise the base events.

    The EventArgs that are passed are the same as the event of the same name, so if you want to see the passing arguments, then read the MSDN description of the actual event.

    I would suggest to just subscribe to the event, and use breakpoints to see what the EventArgs look like.

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

Sidebar

Related Questions

I have UserControl which contains a TextBox and a Button control. The Button opens
I have a usercontrol that has several public properties. These properties automatically show up
I have a UserControl that consists of three TextBoxes. On a form I can
I have a UserControl in my Asp.net project that has a public property. I
I have some UserControls that I created in ProjectA. I have ProjectB that has
I have a usercontrol that is meant to take up the entire form. I
I have a UserControl with some predefined controls (groupbox,button,datagridview) on it, these controls are
I have a UserControl called CustomerFinder for searhing customers. And there is "ADD" button
If I have a usercontrol (in Silverlight) that I've written, that uses XAML to
So I have a UserControl with some cascading DropDownList s on it. Selecting from

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.