I am creating a custom control that produces radio buttons (No, it should not be radio buttons. I'm just trying to learn how to do this so that I can do some more complex things along the way, it may contain several lists of controls) that are added via the Items property ( similar to some other controls).
I can build a project, drag it onto the form from the component panel and add switches through the Items property. Unfortunately, this is not updated in the designer unless you do:
- Restore a project 2-3 times
- Close and reopen the form in the designer
At first, I had logic that put them in the form contained in the constructor after initialization, but this does not work, so I switched to Form_Load.
What am I missing? The above options are just short-term workarounds, not solutions.
RBLTest.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; namespace WFCL_Library { public partial class RBLTest : UserControl { private List<RadioButton> _items; private int leftSpacing = 100; private int topSpacing = 25; public RBLTest() { _items = new List<RadioButton>(); 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 > this.Width) { curLeftPos = 0; curTopPos += topSpacing; } this.Controls.Add(rb); } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public List<RadioButton> Items { get { return _items; } set { _items = value; } } } }
RBLTest.Designer.cs
namespace WFCL_Library { partial class RBLTest {
source share