1
我試圖開發具有三個小組當屏幕分辨率更改小組及其在WinForm
面板1(FileBrowsePanel)的Windows窗體應用程序中的子控件顯示: - contrains文本框,瀏覽按鈕
面板2(SearchCriteriaPanel): - LABLE起始日期,TODATE DateTimePicker控件開始日期和結束日期複選框每個DateTimePicker控件也有兩個文本框和列表框兩個按鈕搜索和復位
面板3(DisplayDataPanel): -的ListView到從瀏覽文件路徑顯示數據
面板4(DeleteCriteriaPanel): -具有DateTimePicker控件從列表視圖刪除數據和刪除按鈕
實際問題文件是,當i改變該面板在屏幕上的所有的板和控制的分辨率熄滅的形式寬度和高度的代碼是
void LoadWindowsSetting()
{
this.SuspendLayout();
int i_StandardHeight = 768;//Developer Desktop Height Where the Form is Designed
int i_StandardWidth = 1024; ;//Developer Desktop Width Where the Form is Designed
int i_PresentHeight = Screen.PrimaryScreen.WorkingArea.Height- SystemInformation.CaptionHeight;
int i_PresentWidth = Screen.PrimaryScreen.Bounds.Width;
float f_HeightRatio = new float();
float f_WidthRatio = new float();
f_HeightRatio = (float)((float)i_PresentHeight/(float)i_StandardHeight);
f_WidthRatio = (float)((float)i_PresentWidth/(float)i_StandardWidth);
foreach (Control c in this.Controls)
{
if (c.GetType().ToString() == "System.Windows.Forms.Panel")
{
// c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio));
}
if (c.HasChildren)
{
foreach (Control cChildren in c.Controls)
{
cChildren.SetBounds(Convert.ToInt32(cChildren.Bounds.X * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Y * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Width * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Height * f_HeightRatio));
}
c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio));
}
else
{
c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio));
}
}
btnBrowse.Height = txtBrowseFilePath.Height + 1;
btnSubmit.Height = btnBrowse.Height;
btnReset.Height = btnBrowse.Height;
panelSearch.Height += listBoxLogType.Height;
int leftSpacePanelBrowse = (this.Width - panelBrowse.Width)/2;
int leftSpacePanelSearch = (this.Width - panelSearch.Width)/2;
int leftSpacePanelLogList = (this.Width - panelLogList.Width)/2;
int leftSpacePanelDeleteLog = (this.Width - panelDeleteLog.Width)/2;
panelBrowse.Location = new System.Drawing.Point(leftSpacePanelBrowse - 8, 25);
panelSearch.Location = new System.Drawing.Point(leftSpacePanelSearch - 8, panelBrowse.Height + 40);
panelLogList.Location = new System.Drawing.Point(leftSpacePanelLogList - 8, panelSearch.Height + 140);
progressBarFileLoad.Location = new System.Drawing.Point((this.Width/2) - 100, panelLogList.Bounds.Y + panelLogList.Height + 5);
panelDeleteLog.Location = new System.Drawing.Point(leftSpacePanelDeleteLog - 8, panelLogList.Bounds.Y + panelLogList.Height + progressBarFileLoad.Height + 20);
this.ResumeLayout(false);
Invalidate();
Focus();
}
所以能夠防止控制中,當屏幕分辨率改變是