[英]Create DesignMode for inner Panel With c# WinForm
I have 2 panel in my Control. 我的控件中有2个面板。
panel 3 added to panel 1 for Title , panel 2 added to panel 1 For Content & panel 1 is My Control 将第3面板添加到“标题”的面板1中,将第2面板添加到第1面板的“内容”中,第1面板是“我的控件”
I do create this Control For my Project . 我确实为我的项目创建了此控件。 this Control Code: 此控制代码:
public class ControWithTitle : Panel // Panel 1
{
public Panel Title = new Panel { Dock = DockStyle.Top, Height = 20, BackColor = Color.Black }; // Panel 2
public Panel Content = new Panel { Dock = DockStyle.Fill, BackColor = Color.White }; // Panel 3
public ControWithTitle ()
: base()
{
this.Controls.Add(Title);
this.Controls.Add(Content);
}
}
I do When Add This control in Form > Create Design Mode For Content . 在“表单”>“为内容创建设计模式”中添加此控件时,我会做。 not panel 1 Or Title Panel.... 不是面板1或标题面板...。
this Code not Work ... All Panel is Lock . 此代码无效...所有面板均处于锁定状态。 after Build Project , every Changed was reset... 在构建项目后,所有已更改的项都将重置...
is work this true? 这是真的吗? How to create this? 如何创建呢?
╔═══════════╗ < Paenl 1
║╔═════════╗║
║║ Panel 2 ║║
║╚═════════╝║
║╔═════════╗║
║║ ║║
║║ ║║
║║ ║║
║║ Panel 3 ║║ < Design Mode For This Paenl
║║ ║║
║║ ║║
║║ ║║
║╚═════════╝║
╚═══════════╝
after pasted Dear @King's Code My Problem Not Solved... This Error has in my project: 粘贴亲爱的@King的代码后我的问题没有解决...此错误在我的项目中:
this is my Code for a Other Sample After (@Hans Passant & @King King) Answer: 这是我之后的其他示例的代码(@Hans Passant和@King King)答案:
[Designer(typeof(CustomDesigner))]
public partial class ControlWithTitle : UserControl // Panel 1
{
private System.ComponentModel.IContainer components = null;
private ListView listView1 = new ListView();
protected override void Dispose (bool disposing)
{
if (disposing && (components != null)) { components.Dispose(); }
base.Dispose(disposing);
}
private void InitializeComponent ()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(listView1);
}
public Panel Title = new Panel { };
public Panel Content = new Panel { };
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ListView Employees { get { return listView1; } }
public ControlWithTitle ()
{
InitializeComponent();
}
}
public class CustomDesigner : ParentControlDesigner
{
public override void Initialize (IComponent component)
{
ControlWithTitle control = Control as ControlWithTitle;
if (control != null)
{
EnableDesignMode(control.Employees, "Employees");
}
}
}
You can try this code, you have to add reference to the System.Design.dll
and using System.Windows.Forms.Design;
您可以尝试使用此代码,必须添加对System.Design.dll
引用并using System.Windows.Forms.Design;
: :
[Desiner(typeof(CustomDesigner))]
public class ControWithTitle : Panel // Panel 1
{
//....
}
public class CustomDesigner : ParentControlDesigner {
public override void Initialize(IComponent component){
ControWithTitle control = Control as ControWithTitle;
if(control != null){
//Enable designmode for Panel3
EnableDesignMode(control.Content, "Content");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.