我是WinForms的新手,我非常习惯在CSS中设置样式,所以也许我没有正确地看WinForm的Bottom Margin属性,但是,无论我设置了一个任意大的底边距数字的哪个元素,它似乎没有任何影响。
我想要的是将表单的设计扩展到初始可视窗口下方(垂直滚动条显示得很好),并为这些元素设置一个下边距,以便元素的最底部不是'与窗户的底部齐平(一点空间会很好)。
我在几个元素上尝试了这个,只是为了看看它是否只是一个元素(或者它是在窗口的初始可见部分之外的事实)给了我问题,但我似乎无法从边缘财产中获得任何影响。
在这里看:http://msdn.microsoft.com/en-us/library/ms229627.aspx看来这确实是保证金属性应该做的事情。另外,我在GUI控件中找不到任何元素的填充。
就目前而言,我主要只为事件处理程序编写C#,直到我更好地掌握Visual Studio将所有内容放在两个部分类(以及其他.cs文件)中的位置。
如果有帮助,这里是设计器文件的代码:
namespace WindowsFormsApplication1
{
partial class IntroForm
{
/// <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.WelcomeHeader = new System.Windows.Forms.Label();
this.ActionSelect = new System.Windows.Forms.ComboBox();
this.ProceedBtn = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// WelcomeHeader
//
this.WelcomeHeader.AutoSize = true;
this.WelcomeHeader.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.WelcomeHeader.Location = new System.Drawing.Point(84, 30);
this.WelcomeHeader.Name = "WelcomeHeader";
this.WelcomeHeader.Size = new System.Drawing.Size(367, 25);
this.WelcomeHeader.TabIndex = 0;
this.WelcomeHeader.Text = "Please Select Which Content You";
//
// ActionSelect
//
this.ActionSelect.ForeColor = System.Drawing.SystemColors.WindowFrame;
this.ActionSelect.FormattingEnabled = true;
this.ActionSelect.Items.AddRange(new object[] {
"Events",
"Headline News",
"Images For Slideshow",
"Agendas",
"Job Opportunities",
"Schedule Of Meetings",
"Legal Notices",
"Main Street (Main Link)",
"Tourism (Main Link)",
"Rental Properties",
"Concert In The Park",
"Main Street News Letters"});
this.ActionSelect.Location = new System.Drawing.Point(126, 116);
this.ActionSelect.Name = "ActionSelect";
this.ActionSelect.Size = new System.Drawing.Size(283, 28);
this.ActionSelect.TabIndex = 1;
this.ActionSelect.Text = "Please Select";
//
// ProceedBtn
//
this.ProceedBtn.BackColor = System.Drawing.SystemColors.ButtonFace;
this.ProceedBtn.Cursor = System.Windows.Forms.Cursors.Hand;
this.ProceedBtn.ForeColor = System.Drawing.Color.DimGray;
this.ProceedBtn.Location = new System.Drawing.Point(221, 192);
this.ProceedBtn.Name = "ProceedBtn";
this.ProceedBtn.Size = new System.Drawing.Size(93, 34);
this.ProceedBtn.TabIndex = 2;
this.ProceedBtn.Text = "Proceed";
this.ProceedBtn.UseVisualStyleBackColor = false;
this.ProceedBtn.Click += new System.EventHandler(this.ProceedBtn_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(142, 55);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(251, 25);
this.label1.TabIndex = 3;
this.label1.Text = "Would Like To Change";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(147, 268);
this.richTextBox1.Margin = new System.Windows.Forms.Padding(3, 3, 3, 30);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(246, 269);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "";
//
// IntroForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(102)))), ((int)(((byte)(0)))));
this.ClientSize = new System.Drawing.Size(535, 306);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.ProceedBtn);
this.Controls.Add(this.ActionSelect);
this.Controls.Add(this.WelcomeHeader);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(204)))), ((int)(((byte)(153)))), ((int)(((byte)(0)))));
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "IntroForm";
this.Text = "Okmulgee Online Web File Generator";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label WelcomeHeader;
private System.Windows.Forms.ComboBox ActionSelect;
private System.Windows.Forms.Button ProceedBtn;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
------------------------------------------ UPDATE ---- ---------------------------------------
我在上面的代码中设置了下边距属性的元素就是richTextBox1。
另外,我确实在主要表单元素中找到了一个Padding元素,但遗憾的是,这并没有将其他元素从其边缘推开:(
这些属性有什么作用(边距,填充)?
答案 0 :(得分:5)
Margin属性由Winforms中内置的自动布局功能使用。但它确实要求您允许容器增长,以便它可以提供所需的边距。因此,您必须将表单的AutoSize属性设置为True。
可以组合AutoSize和AutoScroll,您可以设置MaximumSize属性以防止它增长太多。当布局计算生成超过MaximumSize的布局时,滚动条会自动出现。默认的最大大小是显示表单的Screen.WorkingArea,通常足够好。