qq_45368996 2021-06-22 16:02 采纳率: 100%
浏览 260
已采纳

c# label.text的显示

想请教一下这是什么问题,班级能显示出来,别的显示不出来

 private void 申请调宿ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //清除原有控件
            splitContainer.Panel1.Controls.Clear();
            //splitContainer.Panel2.Controls.Clear();

            try
            {
                //打开数据库
                string constr = "data source=192.168.1.197; " +
                                "Database=Dormitory;" +
                                "user id=sa; " +
                                "password=HandQuite229";
                conn = new SqlConnection(constr);
                conn.Open();

                //创建命令
                cmd = new SqlCommand();
                cmd.Connection = conn;
                string cmdStr = string.Format("select * from student where sNumber = '{0}'", sNumber);
                cmd.CommandText = cmdStr;
                Console.WriteLine(cmdStr);

                //查询
                sdAdapetr = new SqlDataAdapter();
                sdAdapetr.SelectCommand = cmd;

                DataSet dataSet = new DataSet();
                sdAdapetr.Fill(dataSet);

                sMajorClass = dataSet.Tables[0].Rows[0]["sMajorClass"].ToString();
                sPhone = dataSet.Tables[0].Rows[0]["sPhone"].ToString();
                sBed = dataSet.Tables[0].Rows[0]["sBed"].ToString();

                conn.Close();
                Console.WriteLine(sMajorClass + "--" + sBed + "--" + sPhone);
            }
            catch (Exception error)
            {
                if (conn.State.ToString() == "Open")
                    conn.Close();
                MessageBox.Show(error.Message.ToString());
            }
            Point p1 = new Point(splitContainer.Panel1.Left,
                                 splitContainer.Panel1.Top);
            Label name_label = new Label();
            name_label.Text = string.Format("姓名:{0}", sName);
            name_label.Location = new Point(p1.X + 10, p1.Y + 20);

            Label class_label = new Label();
            class_label.Text = string.Format("班级:{0}", sMajorClass);
            class_label.Location = new Point(p1.X + 10, name_label.Location.Y + 40);
          

            Label sNumber_label = new Label();
            sNumber_label.Text = string.Format("学号:{0}", sNumber);
            sNumber_label.Location = new Point(p1.X + 10, class_label.Location.Y + 40);

            Label sPhone_label = new Label();
            sPhone_label.Text = string.Format("联系方式:{0}", sPhone);
            sPhone_label.Size = new Size(100, 20);
            sPhone_label.Location = new Point(p1.X + 10, sNumber_label.Location.Y + 40);
          

            Label sBed_label = new Label();
            sBed_label.Text = string.Format("原床位:{0}", sBed);
            sBed_label.Location = new Point(p1.X + 10, sPhone_label.Location.Y + 40);

            Label sTargetBed_label = new Label();
            sTargetBed_label.Text = string.Format("目标床位:");
            sTargetBed_label.Location = new Point(p1.X + 10, sBed_label.Location.Y + 40);
            sTargetBed_label.Size = new Size(70, 20);

            TextBox sTargetBed_tbox = new TextBox();
            sTargetBed_tbox.Location = new Point(p1.X + 10 + 70,
                                                 sBed_label.Location.Y + 40);
            sTargetBed_tbox.Size = new Size(splitContainer.Panel1.Width - 100, 20);

            label23.Text = string.Format("联系方式:{0}", sPhone);


            splitContainer.Panel1.Controls.Add(name_label);
            splitContainer.Panel1.Controls.Add(class_label);
            splitContainer.Panel1.Controls.Add(sNumber_label);
            splitContainer.Panel1.Controls.Add(sPhone_label);
            splitContainer.Panel1.Controls.Add(sBed_label);
            splitContainer.Panel1.Controls.Add(sTargetBed_label);
            splitContainer.Panel1.Controls.Add(sTargetBed_tbox);


        }
  • 写回答

4条回答 默认 最新

  • CSDN专家-showbo 2021-06-22 16:27
    关注

    给label添加width属性应该就行了,目测是长度不够隐藏了,width默认是100。帮助到你能点个采纳吗,谢谢~

    Label sPhone_label = new Label();
    sPhone_label.Width = 200;
    sPhone_label.Text = string.Format("联系方式:{0}", sPhone);
    sPhone_label.Size = new Size(100, 20);
    sPhone_label.Location = new Point(p1.X + 10, sNumber_label.Location.Y + 40);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 数学建模数学建模需要
  • ¥20 Java Sound Api 调用Mixer.getLine偶现Line unsupported错误。
  • ¥15 使用cuda加速opencv运算但是报错AttributeError: module 'cv2.cuda' has no attribute 'getCudaEnabledDeviceCount'
  • ¥15 java输入输出异常
  • ¥15 三子连珠对弈小游戏制作
  • ¥15 C++扑克牌游戏的编程
  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格