读书人

初学者求教C#程序有关问题(哪错了呢)

发布时间: 2012-01-05 22:36:54 作者: rapoo

菜鸟求教C#程序问题(哪错了呢)
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
private void Validate(object sender1, object sender2)
{
TextBox tb = (TextBox)sender1;
Label lb1 = (Label)sender2;
if (tb.Text.Length == 0)
{
lb1.Visible = true;
lb1.Text = "此项不能为空!";
lb1.BackColor = Color.Red;
}
}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void textBox1_Validating(object sender, CancelEventArgs e)
{
Form f = new Form1();
f.Validate(textBox1,label1);
}
}
}


[解决办法]
Form f = new Form1();
f.Validate(textBox1,label1);

=>

Validate(textBox1,label1);

读书人网 >VC

热点推荐