Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you prevent dragging controls out of a custom control at design time?
    primarykey
    data
    text
    <p>In this user control the designer adds items to this control on the form and it dynamically places them on the form. Unfortunately once these controls are shown on the form in designer I can then grab one and pull it right outside of the custom control.</p> <p>How do I prevent this?</p> <p><em>EDIT</em> </p> <p>Please note that I am not looking for a solution or alternative to handling radio buttons, that is just the control of choice in this scenario. If it helps insert any type of control you want here (Button, Label, TextBox, CustomControl1), this problem is about handling a property with a collection/array type. The bottom line is that the user shouldn't be able to grab any of these controls in designer where an instance of this control has been defined and move it elsewhere. Just like a DataGridView or ListView albeit different types of objects, the user must use properties to change the contents of these controls. That is the beharior I am looking for.</p> <p>RBLTest.cs</p> <pre><code>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; namespace WFCL_Library { public partial class RBLTest : UserControl { private RadioButton[] _items; private int leftSpacing = 100; private int topSpacing = 25; public RBLTest() { InitializeComponent(); } private void RadioButtonList_Load(object sender, EventArgs e) { int curLeftPos = 0; int curTopPos = 0; foreach (RadioButton rb in _items) { rb.Location = new Point(curLeftPos, curTopPos); rb.Size = new Size(85, 17); curLeftPos += leftSpacing; if (curLeftPos &gt; this.Width) { curLeftPos = 0; curTopPos += topSpacing; } this.Controls.Add(rb); } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public RadioButton[] Items { get { return _items; } set { _items = value; } } } } </code></pre> <p>RBLTest.Designer.cs</p> <pre><code>namespace WFCL_Library { partial class RBLTest { /// &lt;summary&gt; /// Required designer variable. /// &lt;/summary&gt; private System.ComponentModel.IContainer components = null; /// &lt;summary&gt; /// Clean up any resources being used. /// &lt;/summary&gt; /// &lt;param name="disposing"&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt; protected override void Dispose(bool disposing) { if (disposing &amp;&amp; (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Component Designer generated code /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; private void InitializeComponent() { this.SuspendLayout(); // // RBLTest // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Name = "RBLTest"; this.Size = new System.Drawing.Size(407, 44); this.Load += new System.EventHandler(this.RadioButtonList_Load); this.ResumeLayout(false); } #endregion } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload