All pastes #80309 Raw Copy code Copy link Edit

Carlos Alberto

public unlisted text v1 · immutable
#80309 ·published 2006-07-06 09:01 UTC
rendered paste body
// Sample
using System;
using System.Windows.Forms;
using System.Drawing;

public class TestForm : Form
{
        TextBox text_box;
        Button clear_button;

        static void Main ()
        {
                Application.Run (new TestForm ());
        }

        public TestForm ()
        {
                text_box = new TextBox ();
                text_box.TextChanged += OnTextChanged;
                text_box.Location = new Point (5, 5);
                text_box.Size = new Size (120, 40);
                text_box.Parent = this;

                clear_button = new Button ();
                clear_button.Text = "Clear";
                clear_button.Click += OnClearButtonClick;
                clear_button.Location = new Point (5, text_box.Bottom + 10);
                clear_button.Size = new Size (120, 40);
                clear_button.Parent = this;
        }

        void OnClearButtonClick (object o, EventArgs args)
        {
                text_box.Text = String.Empty; // This should trigger TextChanged event
        }

        void OnTextChanged (object o, EventArgs args)
        {
                Console.WriteLine ("TEXT CHANGED to " + text_box.Text); // This is not reached when TextBox.Text is set to String.Empty
        }
}