1 Replies - 395 Views - Last Post: 10 August 2012 - 05:23 PM Rate Topic: -----

#1 Mallaboro  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 26-April 10

Events accessing

Posted 10 August 2012 - 05:17 PM

Been following this guide on Events, Delegates and Lambdas.
http://www.dreaminco...das-and-events/

In the class Main, how can I get the Mouse_LeftClick event method to access other methods/properties of the main class?
I'm guessing it's the protected virtual void.


MyDelegates events = new MyDelegates();
 
class Main
{
public Game1()
{
//...
events.Mouse_LeftClick += new EventHandler<EventArgs>(Mouse_LeftClick);
}

        public static void Mouse_LeftClick(object sender, EventArgs e)
        {
            //event
        }

        public void Update()
        {
MouseState mouseState = Mouse.GetState();
events.LeftClick(mouseState);
        }
}



    
    class MyDelegates
    {
        #region LeftClick
        public event EventHandler<EventArgs> Mouse_LeftClick;
        public void LeftClick(MouseState mouseState)
        {
            if (mouseState.LeftButton == ButtonState.Pressed)
                this.OnMouse_LeftClick(EventArgs.Empty);
        }
        protected virtual void OnMouse_LeftClick(EventArgs e)
        {
            EventHandler<EventArgs> tempHandler = this.Mouse_LeftClick;

            if (tempHandler != null)
                tempHandler(this, EventArgs.Empty);
        }
    }



Is This A Good Question/Topic? 0
  • +

Replies To: Events accessing

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5535
  • View blog
  • Posts: 11,857
  • Joined: 02-June 10

Re: Events accessing

Posted 10 August 2012 - 05:23 PM

Quick and easy custom events

Bulding an application - Part 1
Building an application - Part 2
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1