任何人都可以将此vb.net代码转换为c#,这是带有语音留言的Lan聊天 [英] Anybody can convert this vb.net code in to c# this is a Lan Chat with Spoken Message

查看:64
本文介绍了任何人都可以将此vb.net代码转换为c#,这是带有语音留言的Lan聊天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些在线转换器,但是当我将其放在C#上时,一些代码出错了.

I find some online converter but when I put it on a C# some codes got an error.

Imports System.IO
Imports System.Net.Sockets

Public Class Form1


    Dim listener As New TcpListener(44444)
    Dim client As TcpClient
    Dim message As String = ""
    Dim tts

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        listener.Stop()

    End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        listener.Start()
        Timer1.Enabled = True
        Timer1.Start()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            If listener.Pending = True Then
                message = ""
                client = listener.AcceptTcpClient()
                Dim Reader As New StreamReader(client.GetStream())


                While Reader.Peek > -1

                    message = message + Convert.ToChar(Reader.Read()).ToString()

                End While
                Me.Focus()
                TextBox4.Text = (TextBox4.Text + message + vbCrLf)
                tts = CreateObject("sapi.spvoice")
                tts.speak(message)


            End If
        Catch ex As Exception
            MsgBox(ex.Message)



        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
                MsgBox("Enter a user name, enter user IP", MsgBoxStyle.Information)


            Else

                client = New TcpClient(TextBox2.Text, 44444)
                Dim writer As New StreamWriter(client.GetStream())
                writer.Write(TextBox1.Text + " Says! " + TextBox3.Text)
                writer.Flush()
                TextBox3.Text = ""


            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)



        End Try
    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub
End Class

推荐答案

使用 http://www.carlosag.net/tools/codetranslator/ [
Use http://www.carlosag.net/tools/codetranslator/[^] and then ask if you have further issues.


这篇关于任何人都可以将此vb.net代码转换为c#,这是带有语音留言的Lan聊天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆