Я добавляю содержимое на панель, в данный момент я просто хочу добавить на панель несколько строк, чтобы убедиться, что «AutoSize» работает.
К сожалению, это не единственный элемент. в диалоговом окне отображается строка 1, я проверил в отладчике, что в элемент управления добавлен весь контент, но в форме отображается только первый элемент, и его размер не изменяется автоматически. Если я перетащу диалоговое окно, я не увижу другие элементы управления.
Форма:
Код: Выделить всё
/*##############################################################
# File: clsSetupForm.cs
# Class: clsSetupForm
##############################################################*/
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
#endregion
namespace BMLGUIService {
public partial class clsSetupForm : Form {
///
/// Class constructor
///
public clsSetupForm() {
InitializeComponent();
}
///
/// Get access function for Cancel button
///
public Button Cancel => btnCancel;
///
/// Get access function for OK button
///
public Button OK => btnOK;
///
/// Get access function for Content panel
///
public Panel panel => pnlContent;
}
}
Код: Выделить всё
namespace BMLGUIService
{
partial class clsSetupForm
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
///
true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.pnlContent = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.Location = new System.Drawing.Point(9, 32);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 0;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(90, 32);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 1;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
//
// pnlContent
//
this.pnlContent.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.pnlContent.AutoSize = true;
this.pnlContent.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnlContent.Location = new System.Drawing.Point(12, 12);
this.pnlContent.Name = "pnlContent";
this.pnlContent.Size = new System.Drawing.Size(153, 14);
this.pnlContent.TabIndex = 2;
//
// clsSetupForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(177, 67);
this.Controls.Add(this.pnlContent);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Name = "clsSetupForm";
this.Text = "frmSetup";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Panel pnlContent;
}
}
Код: Выделить всё
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Подробнее здесь: https://stackoverflow.com/questions/798 ... s-to-panel
Мобильная версия