yyh1910 发表于 2011-3-17 19:40:03

一个TabControl控件的代码,照书上写的,有问题,求各位帮帮小弟!!!

刚学C#,一个TabControl控件的代码,照书上写的,有问题,求各位看看,帮帮小弟!!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TabControl控件
{
    public partial class Form1 : Form
    {
      public Form1()
      {
            InitializeComponent();
      }

      bool alreadyEnter = false;

      private void tabPage1_Click(object sender, EventArgs e)
      {
            if (alreadyEnter)
            {
                LoadBasicInfo();
                LoadAdvanceInfo();
            }
            else
            {
                if (tabControl1.SelectedIndex != 0)
                {
                  MessageBox.Show("请登录");
                  tabControl1.SelectedIndex = 0;
                }
            }
      }

      private void LoadBasicInfo()
      {
            textBox5.Text= "MJ";
            textBox6.Text = "male";
            textBox7.Text = "24";
      }

      private void LoadAdvanceInfo()
      {
            textBox8.Text = "HZTC";
            textBox9.Text = "学士";
            textBox10.Text = "2 年";
      }

      private void button1_Click(object sender, EventArgs e)
      {
            if (textBox3.Text == "MJ")
            {
                if (textBox4.Text == "111111")
                {
                  alreadyEnter = true;
                  tabControl1.SelectedIndex = 1;
                }
                else
                { MessageBox.Show("密码不正确"); }
            }
            else
            { MessageBox.Show("不存在该用户"); }
      }

      private void button3_Click(object sender, EventArgs e)
      {
            if (alreadyEnter)
            {
                if (textBox2.Text.Trim().Length < 1)
                { MessageBox.Show("请输入需要添加的选项卡的名称"); }
                else
                {
                  TabPage tp = new TabPage();
                  tp.Text = textBox2.Text.Trim();
                  tabControl1.TabPages.Add(tp);
                  tabControl1.SelectedTab = tp;
                }
            }
            else
            {
                MessageBox.Show("请先登录");
            }
      }

      private void button2_Click(object sender, EventArgs e)
      {
            if (alreadyEnter)
            {
               if (tabControl1.SelectedIndex == 0)
               {
                  MessageBox.Show("不能修改登录页面的Text属性");
               }
               else if (tabControl1.SelectedIndex == 1)
               {
                  MessageBox.Show("不能修改基本信息页面的Text属性");
               }
               else if (tabControl1.SelectedIndex == 2)
               {
                   MessageBox.Show("不能修改高级信息页面的Text属性");
               }
               else
               {
                   if (textBox1.Text.Trim().Length > 0)
                   {
                     tabControl1.SelectedTab.Text = textBox1.Text;
                     MessageBox.Show("修改成功");
                   }
                   else
                   {
                      MessageBox.Show("请输出需要修改的名称");
                   }
               }
            }
            else
            {
            MessageBox.Show("请先登录");
            }
      }
    }
}

http://cache.amobbs.com/bbs_upload782111/files_37/ourdev_623407UH087G.png
(原文件名:1.png)

http://cache.amobbs.com/bbs_upload782111/files_37/ourdev_623408AZF398.png
(原文件名:2.png)

http://cache.amobbs.com/bbs_upload782111/files_37/ourdev_623409MHQCPQ.png
(原文件名:33.png)

yyh1910 发表于 2011-3-17 19:41:14

http://cache.amobbs.com/bbs_upload782111/files_37/ourdev_623410YW8GU1.png
(原文件名:11.png)
页: [1]
查看完整版本: 一个TabControl控件的代码,照书上写的,有问题,求各位帮帮小弟!!!