Tôi đang thiết kế một điều khiển giãn nở đơn giản.Kiểm soát người dùng dưới dạng vùng chứa tại thời điểm thiết kế
Tôi đã bắt nguồn từ UserControl, các điều khiển bên trong được vẽ, được xây dựng, chạy; tất cả ok.
Vì Bộ điều khiển bên trong là Bảng điều khiển, tôi muốn sử dụng nó làm vùng chứa tại thời điểm thiết kế. Thực tế tôi đã sử dụng các thuộc tính:
[Designer(typeof(ExpanderControlDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
Tuyệt vời tôi nói. Nhưng nó không phải là ...
Kết quả là tôi có thể sử dụng nó như container tại thời gian thiết kế nhưng:
- Các điều khiển bổ sung trở lại các điều khiển bên trong đã được nhúng trong điều khiển người dùng
- Thậm chí nếu tôi đẩy đầu một điều khiển thêm vào thời gian thiết kế, khi chạy nó là trở lại một lần nữa trên điều khiển nhúng để người dùng điều khiển
- tôi không thể hạn chế khu vực container tại thời gian thiết kế thành một khu vực Bảng điều chỉnh
Tôi đang thiếu gì? Đây là mã để hoàn thành ... tại sao đoạn mã này không hoạt động?
[Designer(typeof(ExpanderControlDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
public partial class ExpanderControl : UserControl
{
public ExpanderControl()
{
InitializeComponent();
....
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
internal class ExpanderControlDesigner : ControlDesigner
{
private ExpanderControl MyControl;
public override void Initialize(IComponent component)
{
base.Initialize(component);
MyControl = (ExpanderControl)component;
// Hook up events
ISelectionService s = (ISelectionService)GetService(typeof(ISelectionService));
IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));
s.SelectionChanged += new EventHandler(OnSelectionChanged);
c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);
}
private void OnSelectionChanged(object sender, System.EventArgs e)
{
}
private void OnComponentRemoving(object sender, ComponentEventArgs e)
{
}
protected override void Dispose(bool disposing)
{
ISelectionService s = (ISelectionService)GetService(typeof(ISelectionService));
IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));
// Unhook events
s.SelectionChanged -= new EventHandler(OnSelectionChanged);
c.ComponentRemoving -= new ComponentEventHandler(OnComponentRemoving);
base.Dispose(disposing);
}
public override System.ComponentModel.Design.DesignerVerbCollection Verbs
{
get
{
DesignerVerbCollection v = new DesignerVerbCollection();
v.Add(new DesignerVerb("&asd", new EventHandler(null)));
return v;
}
}
}
tôi đã tìm thấy nhiều tài nguyên (Interaction, designed, limited area), nhưng không có gì là hữu ích cho việc phẫu ...
Trên thực tế có một trick, vì System.Windows.Forms lớp có thể được thiết kế (như thường lệ) và có một hành vi đúng lúc chạy (ví dụ như TabControl).
Nó hoạt động ! Nhưng thực ra nó không có những khiếm khuyết sau: bạn có thể di chuyển/kích thước "WorkingArea" (sự khác biệt nào có "DropZone"?) nhưng trong thời gian chạy nó không được phản ánh; các điều khiển dopped tại thời gian thiết kế không thể được liên kết trên giới hạn container. – Luca
Tôi đang gặp hai vấn đề tương tự và tự hỏi làm cách nào để sửa lỗi – Telanor
Tắt đầu tôi không chắc chắn cách xử lý các vấn đề đó. Bạn đã xem liên kết chưa? Anh ta có thể đã giải quyết những điều đó bằng phiên bản nâng cao của mình. http://www.codeproject.com/KB/miscctrl/NestedControlDesigner.aspx –