Cannot make a reference to newly created control

aewarnick

Senior Contributor
Joined
Jan 29, 2003
Messages
1,031
I have text boxes that are small, but when clicked they will resize to large. The button is created and then I need the button to resize them back to where they were but I cannot reference the button anywhere except where I declared it.

ooo.Dispose() does not compile because of that, Help.


Code:
private void richTextBox1_Enter(object sender, System.EventArgs e)
		{
			this.richTextBox1.BringToFront();
			this.richTextBox1.Size = new System.Drawing.Size(496, 300);
			Control r=new Button();
			r.Font = new System.Drawing.Font("Verdana", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			r.Location = new System.Drawing.Point(richTextBox1.Location.X-35, richTextBox1.Location.Y);
			r.Name = "ooo";
			r.Size = new System.Drawing.Size(35, 20);
			r.TabIndex = 1;
			r.Text = "Exit";
			Controls.Add(r);
			r.BringToFront();
			r.Show();
		}
		private void ooo_Click(object sender, System.EventArgs e)
		{
			this.richTextBox1.Size = new System.Drawing.Size(496, 48);
			ooo.Dispose();
		}
 
I'd rather program an extendedRichBox Control, which inherits rich text box and has
(a) the richttextbox
(b) a resizeButton
(c) a boolean property "shrinked"

or so.
 
if you insist on creating a new contol i suggest the following:

Visual Basic:
private BigBox_Clicked(object sender, System.EventArgs e)
{

perform the shrinking here		}

}

and

Visual Basic:
private void richTextBox1_Enter(object sender, System.EventArgs e)
		{
			this.richTextBox1.BringToFront();
			this.richTextBox1.Size = new System.Drawing.Size(496, 300);
			Control r=new Button();
			r.Font = new System.Drawing.Font("Verdana", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			r.Location = new System.Drawing.Point(richTextBox1.Location.X-35, richTextBox1.Location.Y);
			r.Name = "ooo";
			r.Size = new System.Drawing.Size(35, 20);
			r.TabIndex = 1;
			r.Text = "Exit";
			Controls.Add(r);
			r.BringToFront();
			r.Show();
               AddHandler r.Click, AddressOf Me.BigBox_Clicked
		}
 
Are you saying that I can convert my boxes to extended types?

I will try both, but I still cannot reference the button to delete it from the event handler.
 
Back
Top