Instantiating Custom events in c# csharp .net

So I have created an inherited object for which I have defined a custom Even and matching delegate. I also defined the custom EventArgs. Finally, I have tied the objects event with a function that will execute when the event is called.

The problem I am having is instantiating the custom event: I want the event to occur outside the object, and the object to react to it.

The reason is this: I will have several objects observing the event, and I want them all to react.

Thank you so much for reading this!
//
// Inherited Object
//
namespace NA_minu
{
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
 
    // Delegate of Event
    public delegate void GridColorChangedEventHandler(
        object sender, GridColorChangeEventArgs e);
 
    class ModifiedDataGridView: DataGridView
    {
        // Public event
        public event GridColorChangedEventHandler ColorChangedEvent;
 
        public ModifiedDataGridView()
        {
            // Empty constructor
        }
    }
    
    // Custom EventArgs
    class GridColorChangeEventArgs : EventArgs
    {
        private Color _gridBack;
        private Color _gridFore;
        private Color _gridSelectedFore;
        private Color _gridSelectedBack;
 
        public GridColorChangeEventArgs(
            Color gridBack,
            Color gridFore,
            Color gridSelectedFore,
            Color gridSelectedBack)
        {
            this._gridBack = gridBack;
            this._gridFore = gridFore;
            this._gridSelectedFore = gridSelectedFore;
            this._gridSelectedBack = gridSelectedBack;
        }
 
        public Color GridBack
        {
            get { return _gridBack; }
        }
        public Color GridFore
        {
            get { return _gridFore; }
        }
        public Color GridSelectedFore
        {
            get { return _gridSelectedFore; }
        }
        public Color GridSelectedBack
        {
            get { return _gridSelectedBack; }
        }
    }
}
 
// In the form, I attach a method to the custom event
dgvFile.ColorChangedEvent += 
                new GridColorChangedEventHandler(dgvFile_ColorChangedEvent);
 
 
// The attached method
void dgvFile_ColorChangedEvent(object sender, GridColorChangeEventArgs e)
{
    // Here I will want to manipulate the object.
}
 
// This button click should fire the event...
private void btnClose_Click(object sender, EventArgs e)
{
    
    //*** What event do I call?
    //*** When I type below the event GridColorChange, it isn't listed
    //*** in the intelli-type thing that comes up.
    if( /* ??? what do I type here??? */ != null)
    {
        /* ??? what do I type here??? */(new GridColorChangeEventArgs(
            pbForeColor.BackColor,
            pbGridForeColor.BackColor,
            pbGridSelectedForeColor.BackColor,
            pbGridSelectedBackColor.BackColor));      
    }
}

Open in new window

yaronusaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RusselRCommented:
dgvFile_ColorChangedEvent(null, new GridColorChangeEventArgs(
            pbForeColor.BackColor,
            pbGridForeColor.BackColor,
            pbGridSelectedForeColor.BackColor,
            pbGridSelectedBackColor.BackColor));      

will run the code that happens when the event fires.

If you want to actually cause the event to fire when the button is clicked you need to create a new method on the dgvFile object that causes the event to fire and run that method from your buttonclick.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yaronusaAuthor Commented:
OK, thank you for your time. I seem to have gotten something backwards in my brain but you straightened it out for me.

Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.