开发者

Visual Basic Application regarding TexBox and Write (Not mouse) pointer

Here's the deal. I have a textbox that sends various messages in another window, every time you press enter, a message from one window passes on to the next one, only that it makes a new line(thats the whole Enter concept) and i want to make you return to the same line, at the very beggining. kinda like msn when you hit enter and you re sending out a message!

Thats my code:

Private Sub msgSender_keyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles msgContent.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim outStream As Byte() = _
            System.Text.Encoding.ASCII.GetBytes(msg1.Text)
            serverStream.Write(outStream, 0, outStream.Le开发者_JAVA技巧ngth)
            serverStream.Flush()
            msgContent.Text = ""       'It makes the line empty 
                                       'after you ve sent out a message
        End If
    End Sub    

The output if you send out 3 messages like "Good Morning" , "How are you", "Ok?"
will be like that
 >> George says : Good Morning
 >> George says : 
How are you
 >> George says : 
Ok?

while i want it to be

 >> George says : Good Morning
 >> George says : How are you
 >> George says : Ok?

Is there a way? Anyone know? In other words, I want the writing cursor(NOT the mouse one) to return to 1st like every time you re sending out a message.


I've read this a couple of times and I'm still not exactly sure what you're trying to accomplish here. However, one thing sticks out to me: Are you sure that you want to "make the line empty after you've sent out a message"? Specifically, this code:

        msgContent.Text = ""       'It makes the line empty 
                                   'after you ve sent out a message

From what I can tell, you're trying to prevent a line break from being inserted between >> User says: and their comment. If the above code is inserting an empty line, that may very well be your problem.


Otherwise, it would be helpful if you could include more context behind your code. For example, what is msgContent? What is serverStream? Where is it declared? Looking at a small snippet of your code for the first time, I don't know what all of your variables and control names mean. What portion of your code (please post it!) is responsible for writing the >> User says: portion of the line? It's equally likely that the problem lies within that code.


msgContent is the textbox that you re about to write the message to send to another user. ServerStream is the stream that goes from client to Server. (the message) This code in the file server( the previous one was in the client folder ), is responsible for sending the message.

   Private Sub broadcast(ByVal msg As String, _
    ByVal uName As String, ByVal flag As Boolean)
        Dim Item As DictionaryEntry
        For Each Item In clientsList
            Dim broadcastSocket As TcpClient
            broadcastSocket = CType(Item.Value, TcpClient)
            Dim broadcastStream As NetworkStream = _
                    broadcastSocket.GetStream()
            Dim broadcastBytes As [Byte]()

            If flag = True Then
                broadcastBytes = Encoding.ASCII.GetBytes(uName + " says : " + msg)
            Else
                broadcastBytes = Encoding.ASCII.GetBytes(msg)
            End If

            broadcastStream.Write(broadcastBytes, 0, broadcastBytes.Length)
            broadcastStream.Flush()
        Next
End Sub

Now, what I want to do is: I want it to work like msn, where you write something ,you hit Enter and it clears the line and goes to the very beggining of it. Mine goes one line below, and the messages dont look well. PS: I'm sure that I want the line to be empty, cause I dont know any other way, maybe you do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜