[c#] Client > Server - textbox

Results 1 to 3 of 3
  1. #1
    pork pork Parker is offline
    Grand MasterRank
    Dec 2007 Join Date
    new holland.Location
    5,869Posts

    [c#] Client > Server - textbox

    Well I'm just messing about with a packet logger and say if I want to inject the 'BK' and use the text from txtAlert
    BK - message box popup

    Code:
            private void cmdAlertCS_Click(object sender, EventArgs e)
            {
                clsSockets.SendToClient("BK" + txtAlertCS);
            }
    But when I have like 'Hey there!' and I send the packet to client, the BK alert comes up fine but it comes out like;

    Code:
    System.Windows.Forms.Textbox, Text: Hey there!
    But I don't want the 'System.Windows.Forms.Textbox, Text:' to come up.

    Does anyone know how to counter this?


  2. #2
    Grand Master King Izu is offline
    Grand MasterRank
    Dec 2006 Join Date
    833Posts

    Re: [c#] Client > Server - textbox

    By using 'txtAlertCS' which is a TextBox object (and not text), the ToString method is implicitly invoked to convert the object to a string, which results in 'System.Windows.Forms.Textbox, Text:'. The solution is to use the 'Text' property of txtAlertCS, which will return the text contained in the text box.

    How it should be:
    Code:
            private void cmdAlertCS_Click(object sender, EventArgs e)
            {
                clsSockets.SendToClient("BK" + txtAlertCS.Text);
            }

  3. #3
    pork pork Parker is offline
    Grand MasterRank
    Dec 2007 Join Date
    new holland.Location
    5,869Posts

    Re: [c#] Client > Server - textbox

    Quote Originally Posted by King Izu View Post
    By using 'txtAlertCS' which is a TextBox object (and not text), the ToString method is implicitly invoked to convert the object to a string, which results in 'System.Windows.Forms.Textbox, Text:'. The solution is to use the 'Text' property of txtAlertCS, which will return the text contained in the text box.

    How it should be:
    Code:
            private void cmdAlertCS_Click(object sender, EventArgs e)
            {
                clsSockets.SendToClient("BK" + txtAlertCS.Text);
            }
    Thanks, I knew there was a simpler way to do it.



Advertisement