View Full Version : How would I add a textbox?
-KEN-
11-13-2001, 12:48 PM
I have...
using System;
using System.Windows.Forms;
class MainForm : Form
{
public MainForm()
{
Text = "First WinApp";
}
public static void Main(string[] args)
{
Form form1 = new MainForm();
TextBox text = new TextBox();
Application.Run(form1);
}
}
but from there, how do I had a TextBox to form1?
thanks,
Ken
nvoigt
11-13-2001, 01:39 PM
The Textbox should be a private member of your class.
Create a new Textbox in the constructor. Then set the
size and location. Example:
textBox1.Location = new System.Drawing.Point(104, 80);
-KEN-
11-13-2001, 02:02 PM
Yeah, I figured it out, thanks. But you forgot one thing:
this.Controls.Add(textbox1);
Ok, well now I have a whole lot sorted out there's one thing bugging me. Why won't this work:
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
class MainForm : Form
{
public TextBox tbox = new TextBox();
public MainForm()
{
TextBox tbox = new TextBox();
Button butt = new Button();
tbox.Location = new Point(10,10);
this.Controls.Add(tbox);
butt.Location=new Point(tbox.Left+tbox.Width+20,10);
butt.Size=new Size(150,24);
butt.Text="Ok";
butt.Click += new System.EventHandler(this.ButtClick);
this.Controls.Add(butt);
Text = "Cool Stuff";
}
protected void ButtClick(object sender, System.EventArgs e)
{
MessageBox.Show(tbox.Text,"You typed",MessageBoxButtons.OK);
}
public static void Main()
{
Application.Run(new MainForm());
}
}
Why doesn't it show up the text?
nevermind, I figured it out.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.