namespace ch
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//这里我是让textbox与自己的form保持一定的距离和大小关系
int[] changetextboxsize(Form f, int left, int top)
{
int[] r = new int[2];
int width = f.Width;
int height = f.Height;
int newwidth = width - left - 50;
int newheight = height - top - 100;
r[0] = newwidth;
r[1] = newheight;
return r;
}
public void GOGOGO()
{
int left = textBox1.Left;
int top = textBox1.Top;
int[] r = changetextboxsize(this, left, top);
textBox1.Width = r[0];
textBox1.Height = r[1];
textBox1.Refresh();
}
private void Form1_Load(object sender, EventArgs e)
{
GOGOGO();
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
GOGOGO();
}
}
}
这里我只是举例说明,让textbox适应窗体,你也可以让父容器是一个panel什么的,效果可以自己定。