|
刚学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("请先登录");
}
}
}
}
(原文件名:1.png)
(原文件名:2.png)
(原文件名:33.png) |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|