Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For Each c In Me.Controls c.Left = 10 Next End Sub这样就可以遍历了
这语言没什么区别的吧,c#好像不能动态数据类型,Control 用下就可以了namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { foreach (Control c in this.Controls) { c.Left = 10; } } } }
WindowState=Maximized;
其他什么控件的,用个容器装起来在设置Dock=fill;什么的。可以吖
Top:说明控件距父容器的顶部距离不变...其他的类似dock属性:
Top:说明控件除了底部以外,其他边都靠边,大小只有下边框可以拉动。你可以试试看
tableLayoutPanel控件
比如“我的电脑”,当窗口变小的时候,旁边的边栏就没有了。还可以看一下Media Play,当窗口大小变化的时候它会有一些变化。程序适应不同的窗口尺寸是一个比较复杂的问题,从最开始设计的时候就要考滤,大的时候怎么排版?小的时候又怎么排版?想清楚以后,编程就容易了。还有一个要注意的。有人可能改变屏幕的DPI,通俗的话就是文字的大小,这样的话排版也会发生变化。
c.Left = 10
Next
End Sub这样就可以遍历了
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in this.Controls)
{
c.Left = 10;
}
}
}
}
{
foreach (Control con in cons.Controls)
{
con.Tag = con.Width +":" + con.Height + ":" + con.Left + ":" + con.Top + ":" + con.Font.Size;
if (con.Controls.Count > 0)
setTag(con);
}
}
private void setControls(float newx, float newy, Control cons)
{
foreach (Control con in cons .Controls )
{ string[] mytag = con.Tag.ToString().Split(new char[] { ':' });
float a = Convert.ToSingle(mytag[0]) * newx;
con.Width = (int)a;
a=Convert.ToSingle(mytag[1]) * newy;
con.Height = (int)(a);
a=Convert.ToSingle(mytag[2]) * newx;
con.Left = (int)(a);
a=Convert.ToSingle(mytag[3]) * newy;
con.Top = (int)(a);
Single currentSize = Convert.ToSingle (mytag[4]) * newy;
con .Font =new Font (con.Font .Name ,currentSize,con.Font .Style ,con.Font .Unit );
if(con.Controls .Count >0)
{
setControls (newx ,newy ,con );
}
} } void Form1_Resize(object sender, EventArgs e)
{
// throw new Exception("The method or operation is not implemented.");
float newx = (this.Width )/ X;
// float newy = (this.Height - this.statusStrip1.Height) / (Y - y);
float newy = this.Height / Y;
setControls(newx, newy, this);
this.Text = this.Width.ToString() +" "+ this.Height.ToString(); }***重要***在Form_Load里面添加: this.Resize += new EventHandler(Form1_Resize); X = this.Width;
Y = this.Height;
// y = this.statusStrip1.Height; setTag (this);当然定义了两个全局变量,private float X; private float Y;