【问题标题】:Chatbox not working c#,Visual Studio ,Winforms,Bunifu UI聊天框不工作 c#,Visual Studio,Winforms,Bunifu UI
【发布时间】:2020-10-17 16:29:22
【问题描述】:

我有一个我完全不明白的问题,我需要你的帮助... 我正在聊天,我会用套接字来做,但问题不在于这个, 我为我的聊天框创建了一个控制用户......我在我的气泡中创建了另一个我正在尝试从我的主窗体中使用这个控制用户

private void button1_Click_1(object sender, EventArgs e)
        {
            chatbox a = new bunifchat.chatbox();
            
            a.send2message("ABC");

        }

chatbox 是我的 controlUser 的名称,我正在尝试使用他的方法 send2message,我知道它有效但不正确。

public void send2message(String message)
        {
            bubble bbl = new bunifchat.bubble(message);
            bbl.Location = bubble1.Location; bbl.Left += 100; //add intent
            bbl.Size = bubble1.Size;
            bbl.Anchor = bubble1.Anchor;
            bbl.Top = bbl_old.Bottom + 20;
            panel2.Controls.Add(bbl);
            
            //bottom.Top = bbl.Bottom + 50;

            bbl_old = bbl;  //safe the last added object
            
        }

此方法接收字符串并创建进入其他 controlUser 的气泡,当我使用下一个代码从 ControlUser 聊天框运行它时,它会起作用:

private void buttonx_Click(object sender, EventArgs e)
        {
            //panel1.VerticalScroll.Value = panel1.VerticalScroll.Maximum;
            String respuesta = txtbox.Text;
            sendmessage("hola mundo");
            send2message(respuesta);
            panel2.VerticalScroll.Value = panel2.VerticalScroll.Maximum;
        }

但是如果我从我的主窗体运行它,什么都不会发生,我的气泡代码是这样的:

public bubble(String message)
        {
            InitializeComponent();
            
            label1.Text = message;
            Setheight();

        }

如果我不明确,请询问,我需要帮助 enter image description here

当我按下绿色按钮时,它会创建更多气泡(蓝色矩形),但我想从我的主窗体而不是我的聊天框发送内容。

【问题讨论】:

    标签: c# visual-studio chat bunifu


    【解决方案1】:

    我会用套接字来做的

    这是否意味着您使用套接字在与 UI 线程不同的线程上接收数据? 如果是这样,您需要检查 oyu 是否需要在访问/创建新对象之前调用。

    private bool AddMessage(string msg)
    {
        if (this.InvokeRequired)
                return (bool)this.Invoke((Func<string,bool>)AddMessage, msg);
        
        //DO stuff here
        send2message(msg);
    
        return false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-03
      • 2017-06-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多