0
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 GatherLinks
{
    public partial class CrawlLocaly : Form
    {
        public CrawlLocaly()
        {
            InitializeComponent();

        }

        public string getText()
        {
            return textBox1.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBox1.Text))
            {
                DialogResult = DialogResult.OK;

            }
            else
            {

            }
        }




    }
}

在 Form1 中,我显示此表单及其文本框:

private void button6_Click(object sender, EventArgs e)
        {

            using (var w = new StreamWriter(keywords))
            {
                crawlLocaly1 = new CrawlLocaly();
                crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
                DialogResult dr = crawlLocaly1.ShowDialog(this);

我想在 crawlLocaly 新表单中做,当我单击 Form1 并打开/显示新表单上的新表单 button1 将启用 = false 并且一旦用户在新表单 button1 的文本框中键入任何内容,将启用 true只有这样,用户才能点击新表单中的 button1 ,这就是好的(新表单中按钮的文本是好的)。

尝试在新表单中使用 button1 textchanged 事件,但没有成功。只有在我单击它后,该按钮才变为假。

4

3 回答 3

4

您可以尝试使用此代码 - 基于 TextChanged event

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   if(TextBox1.Text.Trim().Length > 0)
   {
      Button.Enabled = true;
   }
}

注意:将 Button.Enabled 初始化为 false;在控制

于 2012-10-12T14:43:14.350 回答
2

If you want to keep it in C# you can do this, don't forget to set AutoPostBack to True and test if the length is 0 to disable the button again:

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Enabled="false" />
    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_OntTextChanged" />

protected void TextBox1_OntTextChanged(object sender, EventArgs e)
{
    if (TextBox1.Text.Length > 0)
    {
        Button1.Enabled = true;
    }
    else
    {
        Button1.Enabled = false;
    }
}
于 2012-10-12T14:49:12.950 回答
0
private void textBox1_TextChanged(object sender, EventArgs e) {
    button1.Enabled = true;
}
于 2012-10-12T14:44:19.033 回答