R
Raj Chudasama
I have a client server app. On the client i have buttons (derived from user
contol) that let user perform actions when they are connected to the server.
so when they connect (using a menuitem) i add event handlers to the buttons
and when they disconnect i remove them. Now, everything works fine when
they connnect for the first time. All of the msgs are sent propoerly by the
client. To figure out what button is click by the client i used the "Tag"
property rather than having a on click event for each of the buttons ( see
click event code).
However, if the following scenario occurs it goes through both msgs(like
kind of having two event handlers for button click being executed)
connect -> disconnect->connect.
can someone please tell me what could be worng? only think i can think
about is something to do with event handlers thats it
------------------------------------------
i am only adding handlers once with every connect msg as follows:
private void SetupFunctionButtons()
{
foreach(WACButton btn in Names)
{
btn.MouseHover +=new EventHandler(btn_MouseHover);
btn.MouseLeave +=new EventHandler(btn_MouseLeave);
btn.MouseEnter +=new EventHandler(btn_MouseEnter);
btn.MouseUp +=new MouseEventHandler(btn_MouseUp);
btn.MouseDown +=new MouseEventHandler(btn_MouseDown);
btn.Click +=new EventHandler(btn_Click);
}
btnEmpty1.ImageIndex = 1;
btnEmpty2.ImageIndex = 1;
}
------------------------------------------
I know i am removing all handlers every time they disconnect (b/c u can t
click or do anyting with the button)
private void RemoveFunctionButtons()
{
foreach(WACButton btn in Names)
{
btn.MouseHover -=new EventHandler(btn_MouseHover);
btn.MouseLeave -=new EventHandler(btn_MouseLeave);
btn.MouseEnter -=new EventHandler(btn_MouseEnter);
btn.MouseUp -=new MouseEventHandler(btn_MouseUp);
btn.MouseDown -=new MouseEventHandler(btn_MouseDown);
btn.Click -=new EventHandler(btn_Click);
}
}
------------------------------------------
private void btn_Click(object sender, EventArgs e)
{
Carets.HideCaret(this.Handle);
WACButton btn = (WACButton)sender;
btn.ImageIndex = 3;
Thread.Sleep(200);
string tag = ((WACButton)sender).Tag.ToString();
try
{
switch(tag)
{
case "dnd":
{
s.IRCConnection.SendMessage(string.Format("PRIVMSG {0} NDON
UN|{1}^",mIRCRoom,mMyInfo.Name));
btn.ButtonText = "Disable DND";
btn.Tag = "disablednd";
break;
}
case "disablednd":
{
s.IRCConnection.SendMessage(string.Format("PRIVMSG {0} NDOFF
UN|{1}^",mIRCRoom,mMyInfo.Name));
btn.ButtonText = "DND";
btn.Tag = "dnd";
break;
}
}//end case//
}
catch
{
return;
}
Carets.ShowCaret(this.Handle);
}
contol) that let user perform actions when they are connected to the server.
so when they connect (using a menuitem) i add event handlers to the buttons
and when they disconnect i remove them. Now, everything works fine when
they connnect for the first time. All of the msgs are sent propoerly by the
client. To figure out what button is click by the client i used the "Tag"
property rather than having a on click event for each of the buttons ( see
click event code).
However, if the following scenario occurs it goes through both msgs(like
kind of having two event handlers for button click being executed)
connect -> disconnect->connect.
can someone please tell me what could be worng? only think i can think
about is something to do with event handlers thats it
------------------------------------------
i am only adding handlers once with every connect msg as follows:
private void SetupFunctionButtons()
{
foreach(WACButton btn in Names)
{
btn.MouseHover +=new EventHandler(btn_MouseHover);
btn.MouseLeave +=new EventHandler(btn_MouseLeave);
btn.MouseEnter +=new EventHandler(btn_MouseEnter);
btn.MouseUp +=new MouseEventHandler(btn_MouseUp);
btn.MouseDown +=new MouseEventHandler(btn_MouseDown);
btn.Click +=new EventHandler(btn_Click);
}
btnEmpty1.ImageIndex = 1;
btnEmpty2.ImageIndex = 1;
}
------------------------------------------
I know i am removing all handlers every time they disconnect (b/c u can t
click or do anyting with the button)
private void RemoveFunctionButtons()
{
foreach(WACButton btn in Names)
{
btn.MouseHover -=new EventHandler(btn_MouseHover);
btn.MouseLeave -=new EventHandler(btn_MouseLeave);
btn.MouseEnter -=new EventHandler(btn_MouseEnter);
btn.MouseUp -=new MouseEventHandler(btn_MouseUp);
btn.MouseDown -=new MouseEventHandler(btn_MouseDown);
btn.Click -=new EventHandler(btn_Click);
}
}
------------------------------------------
private void btn_Click(object sender, EventArgs e)
{
Carets.HideCaret(this.Handle);
WACButton btn = (WACButton)sender;
btn.ImageIndex = 3;
Thread.Sleep(200);
string tag = ((WACButton)sender).Tag.ToString();
try
{
switch(tag)
{
case "dnd":
{
s.IRCConnection.SendMessage(string.Format("PRIVMSG {0} NDON
UN|{1}^",mIRCRoom,mMyInfo.Name));
btn.ButtonText = "Disable DND";
btn.Tag = "disablednd";
break;
}
case "disablednd":
{
s.IRCConnection.SendMessage(string.Format("PRIVMSG {0} NDOFF
UN|{1}^",mIRCRoom,mMyInfo.Name));
btn.ButtonText = "DND";
btn.Tag = "dnd";
break;
}
}//end case//
}
catch
{
return;
}
Carets.ShowCaret(this.Handle);
}