C# 控件在Panel里的布局
2010-03-14 21:38
260 查看
例:在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.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
此时对于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.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
相关文章推荐
- c# winForm TableLayoutPanel学习 合并行的布局及动态增加删除内部控件
- c# winForm TableLayoutPanel学习 合并行的布局及动态增加删除内部控件
- Windows8 Metro应用开发之C#(2)- 布局控件Grid,Canvas,StackPanel(延续Silverlight)
- c#学习笔记之使用 TableLayoutPanel 控件设置窗体布局
- C#三级省市区ajax联动控件,利用UpdatePanel,以及页面取值
- 使用 Ext.Net TreePanel,TabPanel控件 布局
- 使用 TableLayoutPanel 控件设置窗体布局
- Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件
- C# WinForm窗体控件Panel修改边框颜色以及边框宽度方法
- Dotnet_c#循环学习笔记_01_Panel控件
- silverlight布局和式样中的常用三大控件 Canvas Grid StackPanel
- 在C#中使用Panel控件实现在一个窗体中嵌套另一个窗体
- C#如何在Panel或者GroupBox控件中自由地切换其他窗体
- C#学习日记2016-12-26 TableLayoutPanel控件以及页面布局
- C#中解决Panel等控件闪烁的方法
- Expression Blend实例中文教程(5) - 布局控件快速入门StackPanel,ScrollViewer和Border
- C# winform 布局,最大化之后再还原,内部其他控件大小怎么随着变化。
- Panel 控件概述(Windows 窗体)c#
- ASP.Net(C#)中基于ScriptManager-UpdatePanel的无刷新上传(用户控件)的实现
- winform布局 FlowLayoutPanel的控件