[英]winform - Create control like Visual Studio's anchor property control
I find the Visual Studio's anchor property control very user friendly. 我发现Visual Studio的anchor属性控件非常用户友好。
If I don't have this control, I need to create 4 check-boxes (or a CheckedlistBox): Top, Bottom, Left, Right. 如果没有此控件,则需要创建4个复选框(或CheckedlistBox):顶部,底部,左侧,右侧。
So this anchor will make the GUI of the software looks neat. 因此,此锚点将使软件的GUI看起来整洁。 How can I create the control like this Visual Studio's anchor property control?
我如何创建像Visual Studio的anchor属性控件这样的控件?
Create your own using a Panel, 1 Button
and 4 Checkbox
, set chkTop.Appearance = System.Windows.Forms.Appearance.Button
使用Panel,1
Button
和4 Checkbox
创建自己的,设置chkTop.Appearance = System.Windows.Forms.Appearance.Button
Normal style 普通风格
Checked style 格纹风格
Code 码
partial class Form2
{
/// <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.panel1 = new System.Windows.Forms.Panel();
this.chkTop = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.chkBottom = new System.Windows.Forms.CheckBox();
this.chkRight = new System.Windows.Forms.CheckBox();
this.chkLeft = new System.Windows.Forms.CheckBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.chkLeft);
this.panel1.Controls.Add(this.chkRight);
this.panel1.Controls.Add(this.chkBottom);
this.panel1.Controls.Add(this.chkTop);
this.panel1.Controls.Add(this.button1);
this.panel1.Location = new System.Drawing.Point(43, 49);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(207, 148);
this.panel1.TabIndex = 0;
//
// chkTop
//
this.chkTop.Appearance = System.Windows.Forms.Appearance.Button;
this.chkTop.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkTop.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkTop.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkTop.Location = new System.Drawing.Point(95, 2);
this.chkTop.Name = "chkTop";
this.chkTop.Size = new System.Drawing.Size(17, 58);
this.chkTop.TabIndex = 1;
this.chkTop.UseVisualStyleBackColor = false;
//
// button1
//
this.button1.BackColor = System.Drawing.Color.Gray;
this.button1.Enabled = false;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(73, 61);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(58, 23);
this.button1.TabIndex = 0;
this.button1.UseVisualStyleBackColor = false;
//
// chkBottom
//
this.chkBottom.Appearance = System.Windows.Forms.Appearance.Button;
this.chkBottom.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkBottom.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkBottom.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkBottom.Location = new System.Drawing.Point(95, 85);
this.chkBottom.Name = "chkBottom";
this.chkBottom.Size = new System.Drawing.Size(17, 59);
this.chkBottom.TabIndex = 2;
this.chkBottom.UseVisualStyleBackColor = false;
//
// chkRight
//
this.chkRight.Appearance = System.Windows.Forms.Appearance.Button;
this.chkRight.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkRight.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkRight.Location = new System.Drawing.Point(132, 64);
this.chkRight.Name = "chkRight";
this.chkRight.Size = new System.Drawing.Size(71, 17);
this.chkRight.TabIndex = 3;
this.chkRight.UseVisualStyleBackColor = false;
//
// chkLeft
//
this.chkLeft.Appearance = System.Windows.Forms.Appearance.Button;
this.chkLeft.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224)))));
this.chkLeft.FlatAppearance.CheckedBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.chkLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.chkLeft.Location = new System.Drawing.Point(1, 63);
this.chkLeft.Name = "chkLeft";
this.chkLeft.Size = new System.Drawing.Size(71, 17);
this.chkLeft.TabIndex = 4;
this.chkLeft.UseVisualStyleBackColor = false;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.CheckBox chkTop;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.CheckBox chkLeft;
private System.Windows.Forms.CheckBox chkRight;
private System.Windows.Forms.CheckBox chkBottom;
}
The AnchorStyles enumeration type has an attribute that determines how this value type configured in the winforms designer. AnchorStyles枚举类型具有一个属性,该属性确定在Winforms设计器中如何配置此值类型。
[Editor("System.Windows.Forms.Design.AnchorEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
So in ordner to do that with your own type, you need to build your type specific UITypeEditor class and tag your type with the Editor attribute. 因此,在ordner中使用您自己的类型执行此操作,您需要构建特定于类型的UITypeEditor类,并使用Editor属性标记您的类型。
Get ILSpy or any other .NET disassembler and see what the the AnchorEditor class does and how its structured. 获取ILSpy或任何其他.NET反汇编程序,并查看AnchorEditor类的功能以及其结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.