对话框.显示方法'show'接受1个参数

本文关键字:1个 参数 接受 show 对话框 显示 方法 | 更新日期: 2023-09-27 17:53:05

我试图显示一个消息框,但我得到的错误:没有重载方法'show'接受1个参数。我似乎找不到一个解决方案在任何论坛(stackoverflow,msdn…),我已经尝试了所有的建议。我错过了什么?如有任何帮助,不胜感激。

顺便说一句。我是windows窗体和c#的新手,但我已经从教程中编写了这个,它应该可以工作。

完整的代码:

   using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NetworksApi.TCP.CLIENT;
using System.IO;
namespace AdvancedClientChat
{
    public partial class Form1 : Form
    {
        Client client;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (textBoxIP.Text !="" &&  textBoxName.Text !="" && textBoxPort.Text !="")
            {
                client = new Client();
                client.ClientName = textBoxName.Text;
                client.ServerIp = textBoxIP.Text;
                client.ServerPort = textBoxPort.Text;
            }
            else
            {
              MessageBox.Show("You must fill all the boxes");
            }
        }
        private void btnSend_Click(object sender, EventArgs e)
        {
        }
        private void MessageBox_KeyDown(object sender, KeyEventArgs e)
        {
        }

    }
}

对话框.显示方法'show'接受1个参数

看起来你有一个名为MessageBox的控件导致了你的问题。要么重命名控件,要么必须指定MessageBox类及其完整的名称空间System.Windows.Forms.MessageBox.Show("myMessage");

        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (textBoxIP.Text !="" &&  textBoxName.Text !="" && textBoxPort.Text !="")
            {
                client = new Client();
                client.ClientName = textBoxName.Text;
                client.ServerIp = textBoxIP.Text;
                client.ServerPort = textBoxPort.Text;
            }
            else
            {
              System.Windows.Forms.MessageBox.Show("You must fill all the boxes");
            }
        }