Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Mi control de usuario solo debe agregarse a un cierto tipo de control

¿Cómo puedo hacer que mi control de usuario solo se pueda agregar en un cierto tipo de control (aquí en mi caso, específicamente SplitContainer )?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Necesitas cuidar algunas cosas:

  1. Comportamiento del elemento de la caja de herramientas del control
  2. Comportamiento del diseñador de control
  3. Comportamiento de tiempo de ejecución en tiempo de ejecución del control (opcional)

Cuando suelta el control de la caja de herramientas en una superficie de diseño, debe evitar que se suelte en un control no deseado; es responsabilidad del método CreateComponents de la clase ToolBoxItem asignada al control.

Después de agregar el control a la superficie de diseño (por ejemplo, en el padre deseado), debe evitar arrastrarlo sobre los controles no deseados; es responsabilidad del método CanBeParentedTo de la clase ControlDesigner asignada al control.

Finalmente, es posible que desee incluso evitar agregarlo a controles no deseados mediante programación en tiempo de ejecución; que en este caso, es responsabilidad del método OnParentChanged del control.

Ejemplo: limitar un control para que se aloje solo en un SplitterContainer

 using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing.Design; using System.Windows.Forms; using System.Windows.Forms.Design;
 [ToolboxItem(typeof(MyControlToolBoxItem))] [Designer(typeof(MyControlDesigner))] public class MyControl : Control { protected override void OnParentChanged(EventArgs e) { if (Parent != null && !(Parent is SplitterPanel)) throw new Exception("You can add this control only to a SplitterContainer."); base.OnParentChanged(e); } }
 public class MyControlDesigner : ControlDesigner { public override bool CanBeParentedTo(IDesigner parentDesigner) { if (parentDesigner.Component is SplitterPanel) return true; else return false; } }
 public class MyControlToolBoxItem : ToolboxItem { protected override IComponent[] CreateComponentsCore(IDesignerHost host, System.Collections.IDictionary defaultValues) { if (defaultValues.Contains("Parent")) { var parent = defaultValues["Parent"]; if (parent != null && parent is SplitterPanel) return base.CreateComponentsCore(host, defaultValues); } var svc = (IUIService)host.GetService(typeof(IUIService)); if (svc != null) svc.ShowError("You can drop this control only over a SplitterContainer."); return null; } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!