Connecting Tech Pros Worldwide Forums | Help | Site Map

Custom public events problem

Tamir Khason
Guest
 
Posts: n/a
#1: Nov 15 '05
I have a control with custom events, fired by events occured from inside the
control.
But I can not see those events in design time from Properties window.
What's wrong???
Following the code:

public class test: System.Windows.Forms.UserControl

{

public event TSClickEventHandler TSClick;



//regular implementation

private void tsPlay_Click(object sender, System.EventArgs e)

{

TSButton btn = (TSButton)sender;

// do something

TSClickArgs btn_arg = new TSClickArgs(btn);

TSClick(this,btn_arg);

}

}

public class TSClickArgs : EventArgs

{

private TSButton m_button;

public TSClickArgs(TSButton button)

{

m_button = button;

}


}



public delegate void TSClickEventHandler(object sender, TSClickArgs e);





Miha Markic
Guest
 
Posts: n/a
#2: Nov 15 '05

re: Custom public events problem


Hi Tamir,

It seems ok to me.
Are you sure that your are using the right assembly (in case the control is
not the part of target assembly)?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Tamir Khason" <tamir-NOSPAM@tcon-NOSPAM.co.il> wrote in message
news:eDxi7SmwDHA.2408@tk2msftngp13.phx.gbl...[color=blue]
> I have a control with custom events, fired by events occured from inside[/color]
the[color=blue]
> control.
> But I can not see those events in design time from Properties window.
> What's wrong???
> Following the code:[/color]


Tamir Khason
Guest
 
Posts: n/a
#3: Nov 15 '05

re: Custom public events problem


Yes, but it does not work...
Sometimes I recieve the error:
TSClick(this,btn_arg); // Object reference not set to an instance of an
object.

What can be a problem???





"Miha Markic" <miha at rthand com> wrote in message
news:eLdi6enwDHA.3428@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi Tamir,
>
> It seems ok to me.
> Are you sure that your are using the right assembly (in case the control[/color]
is[color=blue]
> not the part of target assembly)?
>
> --
> Miha Markic - RightHand .NET consulting & development
> miha at rthand com
>
> "Tamir Khason" <tamir-NOSPAM@tcon-NOSPAM.co.il> wrote in message
> news:eDxi7SmwDHA.2408@tk2msftngp13.phx.gbl...[color=green]
> > I have a control with custom events, fired by events occured from inside[/color]
> the[color=green]
> > control.
> > But I can not see those events in design time from Properties window.
> > What's wrong???
> > Following the code:[/color]
>
>[/color]


Miha Markic
Guest
 
Posts: n/a
#4: Nov 15 '05

re: Custom public events problem


Hi Tamir,

Before calling TSClick you have to check if there is any handler associated:
if (TSClick != null)
TSClick(this,btn_arg);

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Tamir Khason" <tamir-NOSPAM@tcon-NOSPAM.co.il> wrote in message
news:%23tzchknwDHA.1740@TK2MSFTNGP09.phx.gbl...[color=blue]
> Yes, but it does not work...
> Sometimes I recieve the error:
> TSClick(this,btn_arg); // Object reference not set to an instance of an
> object.
>
> What can be a problem???
>
>
>
>
>
> "Miha Markic" <miha at rthand com> wrote in message
> news:eLdi6enwDHA.3428@TK2MSFTNGP11.phx.gbl...[color=green]
> > Hi Tamir,
> >
> > It seems ok to me.
> > Are you sure that your are using the right assembly (in case the control[/color]
> is[color=green]
> > not the part of target assembly)?
> >
> > --
> > Miha Markic - RightHand .NET consulting & development
> > miha at rthand com
> >
> > "Tamir Khason" <tamir-NOSPAM@tcon-NOSPAM.co.il> wrote in message
> > news:eDxi7SmwDHA.2408@tk2msftngp13.phx.gbl...[color=darkred]
> > > I have a control with custom events, fired by events occured from[/color][/color][/color]
inside[color=blue][color=green]
> > the[color=darkred]
> > > control.
> > > But I can not see those events in design time from Properties window.
> > > What's wrong???
> > > Following the code:[/color]
> >
> >[/color]
>
>[/color]


Jeffrey Tan[MSFT]
Guest
 
Posts: n/a
#5: Nov 15 '05

re: Custom public events problem



Hi Tamir,

To fire your TSClick event, you should first add an event handler to your
event chain, then you can fire it. Also, to avoid exception, you should
check if the event chain is empty before firing the event.
For more information about how to use event in C#, please refer to:
http://msdn.microsoft.com/library/de...us/csspec/html
/vclrfcsharpspec_10_7.asp

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Closed Thread