【问题标题】:winforms tab does not fit the window sizewinforms 选项卡不适合窗口大小
【发布时间】:2018-11-22 16:40:39
【问题描述】:

我创建了一个 .NET Framework 4.0 winforms 项目并添加了一个“选项卡”,如下图所示:

在视图设计器中,两个选项卡(配置文件和功能)看起来都适合矩形窗口,但是当我运行程序时,“配置文件”选项卡看起来相同,但“功能”选项卡突然不再适合矩形窗口看起来像这样:

我不想让用户选择放大窗口。

我想知道为什么它看起来适合矩形窗口,但当我运行应用程序时,它却不适合。

这是 MainForm 中的“功能”选项卡:

        this.TabPage2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
        this.TabPage2.Controls.Add(this.listBoxShowFriendsBirthday);
        this.TabPage2.Controls.Add(this.buttonShowFriendsBirthday);
        this.TabPage2.Controls.Add(this.label1);
        this.TabPage2.Controls.Add(this.monthCalendar1);
        this.TabPage2.Controls.Add(this.postTextBox);
        this.TabPage2.Controls.Add(this.pictureBoxEvent);
        this.TabPage2.Controls.Add(this.listBoxFetchEvents);
        this.TabPage2.Controls.Add(this.buttonFetchEvents);
        this.TabPage2.Controls.Add(this.postButton);
        this.TabPage2.Location = new System.Drawing.Point(8, 39);
        this.TabPage2.Name = "tabPage2";
        this.TabPage2.Padding = new System.Windows.Forms.Padding(3);
        this.TabPage2.Size = new System.Drawing.Size(1976, 806);
        this.TabPage2.TabIndex = 1;
        this.TabPage2.Text = "Features";
        this.TabPage2.UseVisualStyleBackColor = true; 

【问题讨论】:

标签: c# .net winforms


【解决方案1】:

我建议你使用控件的DockAnchor属性。这样您还可以允许用户调整窗口大小。

码头:

锚点:

见 - How to: Anchor and Dock Child Controls in a FlowLayoutPanel Control

【讨论】:

  • 我想保持窗口大小不变,不要让用户玩弄它
  • 无论如何,如果你使用 Dock 和 Anchor 属性,你会得到你需要的。试一试
【解决方案2】:

为了防止用户重新缩放他们的窗口: c# how to prevent user from resizing my application window?

但除此之外,我建议(就像 ikram 所说)使用停靠,这样您就可以确定您的布局将保持不变,无论用户的分辨率/屏幕尺寸如何。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多