Question about inherit form

A

afatdog

Form1:
//-----------------------------------------------------------------
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.IContainer components = null;

public Form1()
{
// This call is required by the Windows Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitializeComponent call
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion

protected void TextBox_Integer_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
e.Handled=!Char.IsDigit(e.KeyChar);
}
}

Form2:
//-----------------------------------------------------------------
public class Form2 : Form1
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.IContainer components = null;

public Form2()
{
// This call is required by the Windows Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitializeComponent call
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.textBox1.Location = new System.Drawing.Point(64, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(280, 20);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
this.ResumeLayout(false);
}
#endregion
}


//-----------------------------------------------------------------
I want to let Form2.TextBox1 assign the KeyPress event to
Form1.TextBox_Integer_KeyPress, I can do that like this:
this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.TextBox_Integer_KeyPress);

But HOW to specify the event in IDE("Properties Toolbar")?
 
Z

Zürcher See

You have to switch in the event menu (the yellow lightning on top of the
property toolbar)
 
A

afatdog

I know the "yellow lighting", but I CAN NOT find the even in KeyPress's drop
down list :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top