Adding a textbox to a panel in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to put a textbox into a panel in code?

What I want to do is remove the borders from a textbox, and from what i can
tell the easiest way to do this is by placing it in a pannel, however I don't
know how to do this in code (I am trying to make a class MyTextBox that has
an instance of a panel and a textbox within that panel)

Any ideas?

Thanks in advance,
Joe
 
Just a followup question.. Is there anyway to add a class to the Toolbox? I
want to be able to use this class inplace of a textbox when i design forms
 
Check this code,

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Controls
{
public class CtlFloatingForm : Panel
{
/// <summary>
/// Class to create a ProgressBarPanel Control
/// </summary>

# region " Destructor "
/// <summary>
/// Clean up resource memory used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#endregion

#region " Globals "

// Global Variables
private Panel PnlWnd;
private Label LblText;
private TextBox txtBox;
private Button btnOk;

# endregion

# region " Paint Constructor "

/// <summary>
/// Constructor to build control
/// </summary>

public CtlFloatingForm()
{
//Set Form Rectangle Area
this.Bounds = new Rectangle(5,65,230,115);

//Set Form Background Color
this.BackColor = Color.Black;

//Add New Panel and Set Area
PnlWnd = new Panel();
PnlWnd.Bounds = new Rectangle(2, 2, this.Width - 4, this.Height -
4);
PnlWnd.BackColor = Color.White;
this.Controls.Add(PnlWnd);

//Add StatusBar Label
LblText = new Label();
LblText.Bounds = new Rectangle(10, 10, PnlWnd.Width - 20, 14);
LblText.Text = "";
this.LblText.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Bold);
PnlWnd.Controls.Add(LblText);

//Add StatusBar Label
txtBox = new TextBox();
txtBox.Bounds = new Rectangle(10, 30, PnlWnd.Width - 20, 45);
txtBox.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Bold);
txtBox.Multiline = true;
txtBox.MaxLength = 50;
txtBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
txtBox.Text = "";
PnlWnd.Controls.Add(txtBox);

btnOk = new Button();
btnOk.Bounds = new Rectangle(100, 85, 40, 20);
btnOk.Text = "Ok";
btnOk.Click +=new EventHandler(btnOk_Click);
PnlWnd.Controls.Add(btnOk);
}

# endregion
}
}

CtlFloatingForm class instantiates Panel and text box is placed in it.

Hope this helps,
Cheers,
Arun.
www.innasite.com
 
Thanks,
That was a little longer a response than i expected (and it was in c but all
good)..

The bit i was looking for and got was PanelName.Controls.Add(TextBoxName)
 
Also note that placing the class in the panel (i.e. offering design support
for your control) is only supported for C# in v1 of netcf.

Cheers
Daniel
 
What about in vb?

Daniel Moth said:
Also note that placing the class in the panel (i.e. offering design support
for your control) is only supported for C# in v1 of netcf.

Cheers
Daniel
 
That would be the opposite statement:
Designer support for custom controls is not supported in vb in v1.

Cheers
Daniel
 
Back
Top