将控件拖放到自定义用户控件上变得隐藏了
|
我创建了一个自定义UserControl,在设计时我支持在其中拖放控件。我的控件正确地放入了我的用户控件,但是一旦放到用户控件上,它们就被隐藏了。为了使添加的控件变得可见,我必须选择它,然后单击设计时IDE按钮\“ Bring to Front \”以查看添加的控件。当我重建解决方案时,控件再次被隐藏。
我用以下代码重现了该问题。在IDE中,我创建了一个简单的用户控件\“ MyControl \”,向其中添加了一个停靠在\“ Fill \”的面板控件。然后,应将此用户控件\“ MyControl \”放到Windows面板上。然后,将另一个控件(例如Label或Buton控件)拖放到用户控件上,然后将其隐藏。
下面是用户控件的代码。如何在设计时自动将放置在用户控件中的控件置于最前面?
MyControl.Designer.cs:
namespace Test
{
partial class MyControl
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = \"panel1\";
this.panel1.Size = new System.Drawing.Size(150, 150);
this.panel1.TabIndex = 0;
//
// MyControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.panel1);
this.Name = \"MyControl\";
this.ResumeLayout(false);
}
private System.Windows.Forms.Panel panel1;
}
}
MyControl.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace Axiom.Controls
{
[Designer(typeof(ParentControlDesigner))]
public partial class MyControl : UserControl
{
public MyControl()
{
InitializeComponent();
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel ContentPanel
{
get
{
return this.panel1;
}
}
}
internal class MyControlDesigner : ControlDesigner
{
public override void Initialize(IComponent component)
{
base.Initialize(component);
MyControl control = component as MyControl;
EnableDesignMode(control.ContentPanel, \"ContentPanel\");
}
}
}
更新:
我发现了另一个与该问题有关的问题/答案,该问题是在设计时将控件拖放到自定义用户控件内的容器控件上的:
题
参考文章
我遵循了上面的文章,并在设计时成功地将工具箱控件拖放到了自定义用户控件中的容器控件上。
没有找到相关结果
已邀请:
2 个回复
容淑阔九
唤副埂侧壬