C# 控件在Panel里的布局
例:在Panel中添加一个Form 此时对于Form来说,Panel的左上角坐标为(0,0),所以要改变Form在Panel中的位置,那么就要相对于Panel来设置Form的Location,而不能相对于整个屏幕来设置Form的Location。 这是,改变Form的位置,只需改变Form的左上角坐标,而无需考虑Panel的位置(左上角坐标)。 form在Panel中居中显示的代码: game_1 game1 = new game_1(); // form int panel_left = panel1.Left; int panel_top = panel1.Top; int panel_width = panel1.Width; int panel_height = panel1.Height; // game1在Panel里居中显示 int frm_left = panel_width / 2 - game1.Width / 2; int frm_top = panel_height / 2 - game1.Height / 2; game1.Location = new System.Drawing.Point(frm_left, frm_top); // 窗体的位置由 System.Windows.Forms.Control.Location 属性确定 game1