By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,654 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

Question about inherit form

P: n/a
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.Tex tBox_Integer_KeyPress);

But HOW to specify the event in IDE("Properties Toolbar")?
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You have to switch in the event menu (the yellow lightning on top of the
property toolbar)

"afatdog" <af********@yeah.net> schrieb im Newsbeitrag
news:uP**************@tk2msftngp13.phx.gbl...
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.Tex tBox_Integer_KeyPress);

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

Nov 16 '05 #2

P: n/a
I know the "yellow lighting", but I CAN NOT find the even in KeyPress's drop
down list :)
You have to switch in the event menu (the yellow lightning on top of the
property toolbar)

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.