none
label和textbox文字偏上显示问题 RRS feed

  • 问题

  • 我在做的一个窗体,使用了TableLayoutPanel做布局,然后在其中布置了label和textbox等控件,然后发现这些控件的中文文字显示都偏上,以致于部分文字的上沿已经消失,请问这是什么问题?

    这些控件文字显示的时候可以上下居中吗?

    2019年4月19日 17:02

全部回复

  • 我在做的一个窗体,使用了TableLayoutPanel做布局,然后在其中布置了label和textbox等控件,然后发现这些控件的中文文字显示都偏上,以致于部分文字的上沿已经消失,请问这是什么问题?

    这些控件文字显示的时候可以上下居中吗?

    Hi    yzjjhk,

    请给出相关的代码,让我们能快速的还原你的问题。这样有助于分析问题。

    我下面的代码并没有发现你所描述的问题。

        TableLayoutPanel dynamicTableLayoutPanel = new TableLayoutPanel();
                dynamicTableLayoutPanel.Location = new System.Drawing.Point(26, 12);
                dynamicTableLayoutPanel.Name = "TableLayoutPanel1";
                dynamicTableLayoutPanel.Size = new System.Drawing.Size(228, 200);
                dynamicTableLayoutPanel.BackColor = Color.LightBlue;
                // Add rows and columns  
                dynamicTableLayoutPanel.ColumnCount = 3;
                dynamicTableLayoutPanel.RowCount = 5;
                dynamicTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
                dynamicTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F));
                dynamicTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F));
                dynamicTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 52F));
                dynamicTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 44F));
                dynamicTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 44F));
                dynamicTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 38F));
                dynamicTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 8F));
                TextBox textBox1 = new TextBox();
                textBox1.Location = new Point(10, 10);
                textBox1.Text = "I am a TextBox5";
                textBox1.Size = new Size(200, 30);
                Label cLabel1 = new Label();
                cLabel1.Location = new Point(10, 50);
                cLabel1.Text = "Check Me test  a a a a a";
                cLabel1.Size = new Size(200, 30);
                // Add child controls to TableLayoutPanel and specify rows and column  
                dynamicTableLayoutPanel.Controls.Add(textBox1, 0, 0);
                dynamicTableLayoutPanel.Controls.Add(cLabel1, 0, 1);
                Controls.Add(dynamicTableLayoutPanel);


    Best Regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2019年4月22日 5:39
    版主
  • 能看到箭头所指,字体都往上偏移了。

    /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.panel = new System.Windows.Forms.Panel();
                this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
                this.textBox = new System.Windows.Forms.TextBox();
                this.dataGridView = new System.Windows.Forms.DataGridView();
                this.tableLayoutPanelSetting = new System.Windows.Forms.TableLayoutPanel();
                this.labelSheetSN = new System.Windows.Forms.Label();
                this.labelIndicateSN = new System.Windows.Forms.Label();
                this.buttonSave = new System.Windows.Forms.Button();
                this.buttonFileDirection = new System.Windows.Forms.Button();
                this.labelFileDirection = new System.Windows.Forms.Label();
                this.textBoxIndicateSn = new System.Windows.Forms.TextBox();
                this.comboBoxSheetSn = new System.Windows.Forms.ComboBox();
                this.buttonReadExcel = new System.Windows.Forms.Button();
                this.labelDirecting = new System.Windows.Forms.Label();
                this.textBoxDirecting = new System.Windows.Forms.TextBox();
                this.panel.SuspendLayout();
                this.tableLayoutPanel.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
                this.tableLayoutPanelSetting.SuspendLayout();
                this.SuspendLayout();
                // 
                // panel
                // 
                this.panel.Controls.Add(this.tableLayoutPanel);
                this.panel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.panel.Location = new System.Drawing.Point(0, 0);
                this.panel.Name = "panel";
                this.panel.Size = new System.Drawing.Size(1384, 562);
                this.panel.TabIndex = 0;
                // 
                // tableLayoutPanel
                // 
                this.tableLayoutPanel.ColumnCount = 1;
                this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
                this.tableLayoutPanel.Controls.Add(this.textBox, 0, 0);
                this.tableLayoutPanel.Controls.Add(this.dataGridView, 0, 1);
                this.tableLayoutPanel.Controls.Add(this.tableLayoutPanelSetting, 0, 2);
                this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0);
                this.tableLayoutPanel.Name = "tableLayoutPanel";
                this.tableLayoutPanel.RowCount = 3;
                this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F));
                this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 75F));
                this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 15F));
                this.tableLayoutPanel.Size = new System.Drawing.Size(1384, 562);
                this.tableLayoutPanel.TabIndex = 0;
                // 
                // textBox
                // 
                this.textBox.Dock = System.Windows.Forms.DockStyle.Fill;
                this.textBox.Location = new System.Drawing.Point(3, 3);
                this.textBox.Multiline = true;
                this.textBox.Name = "textBox";
                this.textBox.Size = new System.Drawing.Size(1378, 50);
                this.textBox.TabIndex = 0;
                this.textBox.TextChanged += new System.EventHandler(this.textBox_TextChanged);
                // 
                // dataGridView
                // 
                this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
                this.dataGridView.Location = new System.Drawing.Point(3, 59);
                this.dataGridView.Name = "dataGridView";
                this.dataGridView.RowTemplate.Height = 23;
                this.dataGridView.Size = new System.Drawing.Size(1378, 415);
                this.dataGridView.TabIndex = 1;
                this.dataGridView.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellDoubleClick);
                this.dataGridView.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(this.dataGridView_DataBindingComplete);
                // 
                // tableLayoutPanelSetting
                // 
                this.tableLayoutPanelSetting.ColumnCount = 6;
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F));
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F));
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F));
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F));
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 16F));
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 20F));
                this.tableLayoutPanelSetting.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
                this.tableLayoutPanelSetting.Controls.Add(this.textBoxDirecting, 3, 1);
                this.tableLayoutPanelSetting.Controls.Add(this.labelDirecting, 2, 1);
                this.tableLayoutPanelSetting.Controls.Add(this.buttonReadExcel, 5, 0);
                this.tableLayoutPanelSetting.Controls.Add(this.labelSheetSN, 4, 1);
                this.tableLayoutPanelSetting.Controls.Add(this.labelIndicateSN, 0, 1);
                this.tableLayoutPanelSetting.Controls.Add(this.buttonSave, 4, 0);
                this.tableLayoutPanelSetting.Controls.Add(this.buttonFileDirection, 0, 0);
                this.tableLayoutPanelSetting.Controls.Add(this.labelFileDirection, 1, 0);
                this.tableLayoutPanelSetting.Controls.Add(this.textBoxIndicateSn, 1, 1);
                this.tableLayoutPanelSetting.Controls.Add(this.comboBoxSheetSn, 5, 1);
                this.tableLayoutPanelSetting.Dock = System.Windows.Forms.DockStyle.Fill;
                this.tableLayoutPanelSetting.Location = new System.Drawing.Point(3, 480);
                this.tableLayoutPanelSetting.Name = "tableLayoutPanelSetting";
                this.tableLayoutPanelSetting.RowCount = 2;
                this.tableLayoutPanelSetting.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
                this.tableLayoutPanelSetting.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
                this.tableLayoutPanelSetting.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
                this.tableLayoutPanelSetting.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
                this.tableLayoutPanelSetting.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
                this.tableLayoutPanelSetting.Size = new System.Drawing.Size(1378, 79);
                this.tableLayoutPanelSetting.TabIndex = 2;
                // 
                // labelSheetSN
                // 
                this.labelSheetSN.AutoSize = true;
                this.labelSheetSN.Dock = System.Windows.Forms.DockStyle.Fill;
                this.labelSheetSN.Location = new System.Drawing.Point(890, 49);
                this.labelSheetSN.Margin = new System.Windows.Forms.Padding(10);
                this.labelSheetSN.Name = "labelSheetSN";
                this.labelSheetSN.Size = new System.Drawing.Size(200, 20);
                this.labelSheetSN.TabIndex = 5;
                this.labelSheetSN.Text = "表格Sheet";
                this.labelSheetSN.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                // 
                // labelIndicateSN
                // 
                this.labelIndicateSN.AutoSize = true;
                this.labelIndicateSN.Dock = System.Windows.Forms.DockStyle.Fill;
                this.labelIndicateSN.Location = new System.Drawing.Point(10, 49);
                this.labelIndicateSN.Margin = new System.Windows.Forms.Padding(10);
                this.labelIndicateSN.Name = "labelIndicateSN";
                this.labelIndicateSN.Size = new System.Drawing.Size(200, 20);
                this.labelIndicateSN.TabIndex = 3;
                this.labelIndicateSN.Text = "表格列号";
                this.labelIndicateSN.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                // 
                // buttonSave
                // 
                this.buttonSave.Dock = System.Windows.Forms.DockStyle.Fill;
                this.buttonSave.Location = new System.Drawing.Point(883, 3);
                this.buttonSave.Name = "buttonSave";
                this.buttonSave.Size = new System.Drawing.Size(214, 33);
                this.buttonSave.TabIndex = 1;
                this.buttonSave.Text = "保存配置";
                this.buttonSave.UseVisualStyleBackColor = true;
                this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
                // 
                // buttonFileDirection
                // 
                this.buttonFileDirection.Dock = System.Windows.Forms.DockStyle.Fill;
                this.buttonFileDirection.Location = new System.Drawing.Point(3, 3);
                this.buttonFileDirection.Name = "buttonFileDirection";
                this.buttonFileDirection.Size = new System.Drawing.Size(214, 33);
                this.buttonFileDirection.TabIndex = 0;
                this.buttonFileDirection.Text = "指定文件路径";
                this.buttonFileDirection.UseVisualStyleBackColor = true;
                this.buttonFileDirection.Click += new System.EventHandler(this.buttonFileDirection_Click);
                // 
                // labelFileDirection
                // 
                this.labelFileDirection.AutoSize = true;
                this.tableLayoutPanelSetting.SetColumnSpan(this.labelFileDirection, 3);
                this.labelFileDirection.Dock = System.Windows.Forms.DockStyle.Fill;
                this.labelFileDirection.Location = new System.Drawing.Point(230, 10);
                this.labelFileDirection.Margin = new System.Windows.Forms.Padding(10);
                this.labelFileDirection.Name = "labelFileDirection";
                this.labelFileDirection.Size = new System.Drawing.Size(640, 19);
                this.labelFileDirection.TabIndex = 2;
                this.labelFileDirection.Text = "文件路径";
                this.labelFileDirection.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
                // 
                // textBoxIndicateSn
                // 
                this.textBoxIndicateSn.Dock = System.Windows.Forms.DockStyle.Fill;
                this.textBoxIndicateSn.Location = new System.Drawing.Point(225, 44);
                this.textBoxIndicateSn.Margin = new System.Windows.Forms.Padding(5);
                this.textBoxIndicateSn.Name = "textBoxIndicateSn";
                this.textBoxIndicateSn.Size = new System.Drawing.Size(210, 29);
                this.textBoxIndicateSn.TabIndex = 4;
                this.textBoxIndicateSn.Text = "请输入列号,以,分隔";
                // 
                // comboBoxSheetSn
                // 
                this.comboBoxSheetSn.Dock = System.Windows.Forms.DockStyle.Fill;
                this.comboBoxSheetSn.FormattingEnabled = true;
                this.comboBoxSheetSn.Location = new System.Drawing.Point(1105, 44);
                this.comboBoxSheetSn.Margin = new System.Windows.Forms.Padding(5);
                this.comboBoxSheetSn.Name = "comboBoxSheetSn";
                this.comboBoxSheetSn.Size = new System.Drawing.Size(268, 27);
                this.comboBoxSheetSn.TabIndex = 8;
                // 
                // buttonReadExcel
                // 
                this.buttonReadExcel.Dock = System.Windows.Forms.DockStyle.Fill;
                this.buttonReadExcel.Location = new System.Drawing.Point(1103, 3);
                this.buttonReadExcel.Name = "buttonReadExcel";
                this.buttonReadExcel.Size = new System.Drawing.Size(272, 33);
                this.buttonReadExcel.TabIndex = 7;
                this.buttonReadExcel.Text = "读取Excel内容";
                this.buttonReadExcel.UseVisualStyleBackColor = true;
                this.buttonReadExcel.Click += new System.EventHandler(this.buttonReadExcel_Click);
                // 
                // labelDirecting
                // 
                this.labelDirecting.AutoSize = true;
                this.labelDirecting.Dock = System.Windows.Forms.DockStyle.Fill;
                this.labelDirecting.Location = new System.Drawing.Point(450, 49);
                this.labelDirecting.Margin = new System.Windows.Forms.Padding(10);
                this.labelDirecting.Name = "labelDirecting";
                this.labelDirecting.Size = new System.Drawing.Size(200, 20);
                this.labelDirecting.TabIndex = 9;
                this.labelDirecting.Text = "指定列号";
                this.labelDirecting.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                // 
                // textBoxDirecting
                // 
                this.textBoxDirecting.Dock = System.Windows.Forms.DockStyle.Fill;
                this.textBoxDirecting.Location = new System.Drawing.Point(665, 44);
                this.textBoxDirecting.Margin = new System.Windows.Forms.Padding(5);
                this.textBoxDirecting.Name = "textBoxDirecting";
                this.textBoxDirecting.Size = new System.Drawing.Size(210, 29);
                this.textBoxDirecting.TabIndex = 10;
                this.textBoxDirecting.Text = "请输入列号";
                // 
                // WordForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 19F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(1384, 562);
                this.Controls.Add(this.panel);
                this.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
                this.Margin = new System.Windows.Forms.Padding(5);
                this.Name = "WordForm";
                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                this.Text = "WordForm";
                this.Load += new System.EventHandler(this.WordForm_Load);
                this.panel.ResumeLayout(false);
                this.tableLayoutPanel.ResumeLayout(false);
                this.tableLayoutPanel.PerformLayout();
                ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
                this.tableLayoutPanelSetting.ResumeLayout(false);
                this.tableLayoutPanelSetting.PerformLayout();
                this.ResumeLayout(false);
    
            }

    2019年6月3日 13:16