2012-10-02 35 views
3

所有的,我已經authoured了大量的WinForms,這個錯誤很奇怪,因爲我還沒有來過它。這個表格是這個項目的30+中的一個,也是唯一一個縮放在不同的屏幕分辨率和字體縮放下表現奇怪的人。特定WInForm縮放的錯誤

我知道AutoScaleMode屬性,大部分時間我已將它設置爲Font以準確地防止我在這裏出現的錯誤。當我啓動我的1920×1080顯示屏上這種形式是好的

No Problem

但推出1920x1200的顯示器上顯示的形式組框似乎調整

Error

強制從按鈕屏幕並導致一般的醜陋。如果我將默認的操作系統字體從125%更改爲100%,我也可以在我的1980x1080顯示器上看到此情況。

頂部組框被錨定(左,右,頂部),底部組框被錨定(左,右,頂部,底部)。表格設置爲FontAutoScaleMode。其他控件是而不是AutoSized

問題是什麼,如何解決?

謝謝你的時間。

編輯:設計器文件如下。

namespace IPACost 
{ 
    partial class CreateNationalDbForm 
    { 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     private System.ComponentModel.IContainer components = null; 

     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
     protected override void Dispose(bool disposing) 
     { 
      if (disposing && (components != null)) 
      { 
       components.Dispose(); 
      } 
      base.Dispose(disposing); 
     } 

     #region Windows Form Designer generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InitializeComponent() 
     { 
      this.splitContainer1 = new System.Windows.Forms.SplitContainer(); 
      this.customTreeViewSql = new IPACost.CustomTreeView(); 
      this.panelBottom = new System.Windows.Forms.Panel(); 
      this.buttonRefresh = new System.Windows.Forms.Button(); 
      this.groupBoxBottom = new System.Windows.Forms.GroupBox(); 
      this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
      this.customRichTextBox1 = new IPACost.CustomRichTextBox(); 
      this.labelInfo = new System.Windows.Forms.Label(); 
      this.groupBoxTop = new System.Windows.Forms.GroupBox(); 
      this.checkBoxInclSNAP = new System.Windows.Forms.CheckBox(); 
      this.label2 = new System.Windows.Forms.Label(); 
      this.comboBoxUnits = new System.Windows.Forms.ComboBox(); 
      this.label1 = new System.Windows.Forms.Label(); 
      this.textBoxIniSize = new System.Windows.Forms.TextBox(); 
      this.labelName = new System.Windows.Forms.Label(); 
      this.textBoxDbName = new System.Windows.Forms.TextBox(); 
      this.buttonNoFilter = new System.Windows.Forms.Button(); 
      this.buttonCancel = new System.Windows.Forms.Button(); 
      this.buttonAppend = new System.Windows.Forms.Button(); 
      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); 
      this.splitContainer1.Panel1.SuspendLayout(); 
      this.splitContainer1.Panel2.SuspendLayout(); 
      this.splitContainer1.SuspendLayout(); 
      this.panelBottom.SuspendLayout(); 
      this.groupBoxBottom.SuspendLayout(); 
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 
      this.groupBoxTop.SuspendLayout(); 
      this.SuspendLayout(); 
      // 
      // splitContainer1 
      // 
      this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; 
      this.splitContainer1.Location = new System.Drawing.Point(0, 0); 
      this.splitContainer1.Margin = new System.Windows.Forms.Padding(2); 
      this.splitContainer1.Name = "splitContainer1"; 
      // 
      // splitContainer1.Panel1 
      // 
      this.splitContainer1.Panel1.Controls.Add(this.customTreeViewSql); 
      this.splitContainer1.Panel1.Controls.Add(this.panelBottom); 
      // 
      // splitContainer1.Panel2 
      // 
      this.splitContainer1.Panel2.Controls.Add(this.groupBoxBottom); 
      this.splitContainer1.Panel2.Controls.Add(this.groupBoxTop); 
      this.splitContainer1.Panel2.Controls.Add(this.buttonNoFilter); 
      this.splitContainer1.Panel2.Controls.Add(this.buttonCancel); 
      this.splitContainer1.Panel2.Controls.Add(this.buttonAppend); 
      this.splitContainer1.Size = new System.Drawing.Size(705, 357); 
      this.splitContainer1.SplitterDistance = 199; 
      this.splitContainer1.SplitterWidth = 6; 
      this.splitContainer1.TabIndex = 0; 
      // 
      // customTreeViewSql 
      // 
      this.customTreeViewSql.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 
      this.customTreeViewSql.Dock = System.Windows.Forms.DockStyle.Fill; 
      this.customTreeViewSql.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawText; 
      this.customTreeViewSql.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
      this.customTreeViewSql.HotTrackFont = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
      this.customTreeViewSql.HotTracking = true; 
      this.customTreeViewSql.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); 
      this.customTreeViewSql.Location = new System.Drawing.Point(0, 0); 
      this.customTreeViewSql.Margin = new System.Windows.Forms.Padding(2); 
      this.customTreeViewSql.Name = "customTreeViewSql"; 
      this.customTreeViewSql.ShowNodeToolTips = true; 
      this.customTreeViewSql.Size = new System.Drawing.Size(199, 320); 
      this.customTreeViewSql.TabIndex = 7; 
      this.customTreeViewSql.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.customTreeViewSql_NodeMouseClick); 
      // 
      // panelBottom 
      // 
      this.panelBottom.Controls.Add(this.buttonRefresh); 
      this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom; 
      this.panelBottom.Location = new System.Drawing.Point(0, 320); 
      this.panelBottom.Margin = new System.Windows.Forms.Padding(2); 
      this.panelBottom.Name = "panelBottom"; 
      this.panelBottom.Size = new System.Drawing.Size(199, 37); 
      this.panelBottom.TabIndex = 7; 
      // 
      // buttonRefresh 
      // 
      this.buttonRefresh.Anchor = System.Windows.Forms.AnchorStyles.Bottom; 
      this.buttonRefresh.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 
      this.buttonRefresh.Location = new System.Drawing.Point(2, 2); 
      this.buttonRefresh.Margin = new System.Windows.Forms.Padding(2); 
      this.buttonRefresh.Name = "buttonRefresh"; 
      this.buttonRefresh.Size = new System.Drawing.Size(195, 33); 
      this.buttonRefresh.TabIndex = 8; 
      this.buttonRefresh.Text = "Show Database Structure"; 
      this.buttonRefresh.UseVisualStyleBackColor = true; 
      this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); 
      // 
      // groupBoxBottom 
      // 
      this.groupBoxBottom.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.groupBoxBottom.Controls.Add(this.pictureBox1); 
      this.groupBoxBottom.Controls.Add(this.customRichTextBox1); 
      this.groupBoxBottom.Controls.Add(this.labelInfo); 
      this.groupBoxBottom.Location = new System.Drawing.Point(4, 120); 
      this.groupBoxBottom.Name = "groupBoxBottom"; 
      this.groupBoxBottom.Size = new System.Drawing.Size(480, 188); 
      this.groupBoxBottom.TabIndex = 12; 
      this.groupBoxBottom.TabStop = false; 
      this.groupBoxBottom.Text = "Additional SQL Filtering [WHERE:]"; 
      // 
      // pictureBox1 
      // 
      this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 
      this.pictureBox1.Image = global::IPACost.Properties.Resources.Info; 
      this.pictureBox1.Location = new System.Drawing.Point(5, 122); 
      this.pictureBox1.Margin = new System.Windows.Forms.Padding(2); 
      this.pictureBox1.Name = "pictureBox1"; 
      this.pictureBox1.Size = new System.Drawing.Size(38, 38); 
      this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 
      this.pictureBox1.TabIndex = 2; 
      this.pictureBox1.TabStop = false; 
      // 
      // customRichTextBox1 
      // 
      this.customRichTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
      | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.customRichTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 
      this.customRichTextBox1.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 
      this.customRichTextBox1.Location = new System.Drawing.Point(5, 20); 
      this.customRichTextBox1.Margin = new System.Windows.Forms.Padding(2); 
      this.customRichTextBox1.Name = "customRichTextBox1"; 
      this.customRichTextBox1.Size = new System.Drawing.Size(472, 86); 
      this.customRichTextBox1.TabIndex = 3; 
      this.customRichTextBox1.Text = "e.g. [B1A].[ProdType] IN (\'AC\', \'NB\', \'AE\')"; 
      // 
      // labelInfo 
      // 
      this.labelInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.labelInfo.Location = new System.Drawing.Point(47, 108); 
      this.labelInfo.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); 
      this.labelInfo.Name = "labelInfo"; 
      this.labelInfo.Size = new System.Drawing.Size(428, 77); 
      this.labelInfo.TabIndex = 1; 
      this.labelInfo.Text = "This filters the create database result sets for the National Databases. The filt" + 
    "ering SQL should only contain a valid WHERE clause on the core data table [B1A]." + 
    " The \'WHERE\' Keyword is not required.\r\n"; 
      // 
      // groupBoxTop 
      // 
      this.groupBoxTop.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.groupBoxTop.Controls.Add(this.checkBoxInclSNAP); 
      this.groupBoxTop.Controls.Add(this.label2); 
      this.groupBoxTop.Controls.Add(this.comboBoxUnits); 
      this.groupBoxTop.Controls.Add(this.label1); 
      this.groupBoxTop.Controls.Add(this.textBoxIniSize); 
      this.groupBoxTop.Controls.Add(this.labelName); 
      this.groupBoxTop.Controls.Add(this.textBoxDbName); 
      this.groupBoxTop.Location = new System.Drawing.Point(2, 10); 
      this.groupBoxTop.Margin = new System.Windows.Forms.Padding(2); 
      this.groupBoxTop.Name = "groupBoxTop"; 
      this.groupBoxTop.Padding = new System.Windows.Forms.Padding(2); 
      this.groupBoxTop.Size = new System.Drawing.Size(479, 105); 
      this.groupBoxTop.TabIndex = 11; 
      this.groupBoxTop.TabStop = false; 
      this.groupBoxTop.Text = "National Database Details:"; 
      // 
      // checkBoxInclSNAP 
      // 
      this.checkBoxInclSNAP.AutoSize = true; 
      this.checkBoxInclSNAP.Location = new System.Drawing.Point(155, 76); 
      this.checkBoxInclSNAP.Margin = new System.Windows.Forms.Padding(2); 
      this.checkBoxInclSNAP.Name = "checkBoxInclSNAP"; 
      this.checkBoxInclSNAP.Size = new System.Drawing.Size(148, 21); 
      this.checkBoxInclSNAP.TabIndex = 14; 
      this.checkBoxInclSNAP.Text = "Include SNAP data"; 
      this.checkBoxInclSNAP.UseVisualStyleBackColor = true; 
      // 
      // label2 
      // 
      this.label2.AutoSize = true; 
      this.label2.Location = new System.Drawing.Point(290, 51); 
      this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); 
      this.label2.Name = "label2"; 
      this.label2.Size = new System.Drawing.Size(160, 17); 
      this.label2.TabIndex = 13; 
      this.label2.Text = "Default growth rate 20%"; 
      // 
      // comboBoxUnits 
      // 
      this.comboBoxUnits.FormattingEnabled = true; 
      this.comboBoxUnits.Items.AddRange(new object[] { 
      "B", 
      "KB", 
      "MB", 
      "GB", 
      "TB", 
      "PB"}); 
      this.comboBoxUnits.Location = new System.Drawing.Point(232, 48); 
      this.comboBoxUnits.Margin = new System.Windows.Forms.Padding(2); 
      this.comboBoxUnits.Name = "comboBoxUnits"; 
      this.comboBoxUnits.Size = new System.Drawing.Size(53, 24); 
      this.comboBoxUnits.TabIndex = 12; 
      this.comboBoxUnits.Text = "MB"; 
      // 
      // label1 
      // 
      this.label1.AutoSize = true; 
      this.label1.Location = new System.Drawing.Point(12, 51); 
      this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); 
      this.label1.Name = "label1"; 
      this.label1.Size = new System.Drawing.Size(139, 17); 
      this.label1.TabIndex = 11; 
      this.label1.Text = "Estimated initial size:"; 
      // 
      // textBoxIniSize 
      // 
      this.textBoxIniSize.Location = new System.Drawing.Point(155, 48); 
      this.textBoxIniSize.Margin = new System.Windows.Forms.Padding(2); 
      this.textBoxIniSize.Name = "textBoxIniSize"; 
      this.textBoxIniSize.Size = new System.Drawing.Size(74, 22); 
      this.textBoxIniSize.TabIndex = 10; 
      this.textBoxIniSize.Text = "100"; 
      this.textBoxIniSize.Leave += new System.EventHandler(this.textBoxIniSize_Leave); 
      // 
      // labelName 
      // 
      this.labelName.AutoSize = true; 
      this.labelName.Location = new System.Drawing.Point(39, 24); 
      this.labelName.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); 
      this.labelName.Name = "labelName"; 
      this.labelName.Size = new System.Drawing.Size(112, 17); 
      this.labelName.TabIndex = 9; 
      this.labelName.Text = "Database name:"; 
      // 
      // textBoxDbName 
      // 
      this.textBoxDbName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
      | System.Windows.Forms.AnchorStyles.Right))); 
      this.textBoxDbName.Location = new System.Drawing.Point(155, 21); 
      this.textBoxDbName.Margin = new System.Windows.Forms.Padding(2); 
      this.textBoxDbName.Name = "textBoxDbName"; 
      this.textBoxDbName.Size = new System.Drawing.Size(287, 22); 
      this.textBoxDbName.TabIndex = 1; 
      // 
      // buttonNoFilter 
      // 
      this.buttonNoFilter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 
      this.buttonNoFilter.Location = new System.Drawing.Point(258, 313); 
      this.buttonNoFilter.Margin = new System.Windows.Forms.Padding(2); 
      this.buttonNoFilter.Name = "buttonNoFilter"; 
      this.buttonNoFilter.Size = new System.Drawing.Size(104, 33); 
      this.buttonNoFilter.TabIndex = 5; 
      this.buttonNoFilter.Text = "Run No Filter"; 
      this.buttonNoFilter.UseVisualStyleBackColor = true; 
      this.buttonNoFilter.Click += new System.EventHandler(this.buttonNoFilter_Click); 
      // 
      // buttonCancel 
      // 
      this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 
      this.buttonCancel.Location = new System.Drawing.Point(162, 313); 
      this.buttonCancel.Margin = new System.Windows.Forms.Padding(2); 
      this.buttonCancel.Name = "buttonCancel"; 
      this.buttonCancel.Size = new System.Drawing.Size(92, 33); 
      this.buttonCancel.TabIndex = 4; 
      this.buttonCancel.Text = "Cancel"; 
      this.buttonCancel.UseVisualStyleBackColor = true; 
      this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); 
      // 
      // buttonAppend 
      // 
      this.buttonAppend.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 
      this.buttonAppend.Location = new System.Drawing.Point(366, 313); 
      this.buttonAppend.Margin = new System.Windows.Forms.Padding(2); 
      this.buttonAppend.Name = "buttonAppend"; 
      this.buttonAppend.Size = new System.Drawing.Size(117, 33); 
      this.buttonAppend.TabIndex = 6; 
      this.buttonAppend.Text = "Run Use Filter"; 
      this.buttonAppend.UseVisualStyleBackColor = true; 
      this.buttonAppend.Click += new System.EventHandler(this.buttonAppend_Click); 
      // 
      // CreateNationalDbForm 
      // 
      this.AcceptButton = this.buttonNoFilter; 
      this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
      this.ClientSize = new System.Drawing.Size(705, 357); 
      this.Controls.Add(this.splitContainer1); 
      this.Margin = new System.Windows.Forms.Padding(2); 
      this.MaximizeBox = false; 
      this.MinimizeBox = false; 
      this.MinimumSize = new System.Drawing.Size(523, 303); 
      this.Name = "CreateNationalDbForm"; 
      this.ShowIcon = false; 
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 
      this.Text = "Special Processes Options"; 
      this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpecialSqlForm_FormClosing); 
      this.Load += new System.EventHandler(this.SpecialSqlForm_Load); 
      this.splitContainer1.Panel1.ResumeLayout(false); 
      this.splitContainer1.Panel2.ResumeLayout(false); 
      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); 
      this.splitContainer1.ResumeLayout(false); 
      this.panelBottom.ResumeLayout(false); 
      this.groupBoxBottom.ResumeLayout(false); 
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 
      this.groupBoxTop.ResumeLayout(false); 
      this.groupBoxTop.PerformLayout(); 
      this.ResumeLayout(false); 

     } 

     #endregion 

     private System.Windows.Forms.SplitContainer splitContainer1; 
     private CustomTreeView customTreeViewSql; 
     private System.Windows.Forms.Panel panelBottom; 
     private System.Windows.Forms.Button buttonRefresh; 
     private System.Windows.Forms.Label labelInfo; 
     private System.Windows.Forms.Button buttonCancel; 
     private System.Windows.Forms.Button buttonAppend; 
     private CustomRichTextBox customRichTextBox1; 
     private System.Windows.Forms.Button buttonNoFilter; 
     private System.Windows.Forms.Label labelName; 
     private System.Windows.Forms.TextBox textBoxDbName; 
     private System.Windows.Forms.GroupBox groupBoxTop; 
     private System.Windows.Forms.PictureBox pictureBox1; 
     private System.Windows.Forms.Label label1; 
     private System.Windows.Forms.TextBox textBoxIniSize; 
     private System.Windows.Forms.ComboBox comboBoxUnits; 
     private System.Windows.Forms.Label label2; 
     private System.Windows.Forms.CheckBox checkBoxInclSNAP; 
     private System.Windows.Forms.GroupBox groupBoxBottom; 
    } 
} 
+0

那些是不一樣的。一個具有「groupBox2」,另一個具有「附加SQL過濾[WHERE:]」。否則,請確保控件的錨定設置正確。隨着顯示器的不同字體縮放,WinForms永遠不會看起來100%正確。另一個要查找的是可見控件下的任何容器控件 - 它們可能沒有正確的停靠欄或錨定設置。 – LarsTech

+0

Hi @LarsTech,爲響應而歡呼。名字上的文字是不同的,因爲我在刪除舊的組合框並添加一個新組合的過程中希望舊的組合已經變得腐敗,這是根本原因。我明白,這些表格永遠不會一模一樣,其他人也不會;然而,組合框在第二個示例中調整大小的方式很奇怪,我檢查了父控件(這是一個拆分容器),並將其設置爲Dock Fill。我已經用一把有着精細牙齒的梳子來做這件事。任何其他的預感? – MoonKnight

+1

這些按鈕可能位於正確的位置,但組合框都不在表單中 - 在右側,組合框2在其下方延伸。嘗試使用「查看」 - 「其他窗口」 - 「文檔大綱」來檢查控制過程。最有可能的是,其中一個控件沒有正確設置其錨或浮動屬性。 – LarsTech

回答

5

我無法確定此問題的確切原因。但是,在經過大約一百萬次形式和控制設置的迭代之後,我確實想出了一個解決方案。這是插入另一個Panel對接的控件的Panel2Fill。這看似現在可以防止任何奇怪的縮放問題,可能是從底層的SplitContainer繼承。

這不是的答案爲什麼這是在進行,但它是一個修復,希望希望它可以幫助別人。

謝謝你的時間。

+0

您的解決方案工作。這裏的博客解釋了這個bug:http://blog.davidegrayson.com/2013/04/unusable-ui-caused-by-windows-forms.html – tunafish24