6

में कस्टम कंट्रोल अपडेट नहीं है मैं एक कस्टम नियंत्रण बना रहा हूं जो रेडियो बटन देता है (नहीं, यह रेडियो बटन नहीं होना चाहिए। मैं बस यह सीखने की कोशिश कर रहा हूं कि ऐसा कैसे करें I सड़क के नीचे कुछ और जटिल चीजें बना सकते हैं जिनमें नियंत्रण की कई सूचियां हो सकती हैं) जो आइटम प्रॉपर्टी के माध्यम से जोड़े जाते हैं (कुछ अन्य नियंत्रणों के समान)।कस्टम स्टूडियो डिज़ाइनर

मैं प्रोजेक्ट का निर्माण कर सकता हूं, इसे घटक पैनल से एक फॉर्म पर खींच सकता हूं और आइटम प्रॉपर्टी के माध्यम से रेडियो बटन जोड़ सकता हूं। दुर्भाग्य से इस डिजाइनर में अपडेट नहीं होता जब तक आप या तो:

  • परियोजना के पुनर्निर्माण 2-3 बार
  • बंद और डिजाइनर में प्रपत्र को फिर से खोलने

पहले तो मुझे तर्क है कि इन पर डालता था प्रारंभ करने के बाद कन्स्ट्रक्टर में निहित फॉर्म लेकिन वह काम नहीं कर रहा था इसलिए मैं फॉर्म_लोड पर गया।

मुझे क्या याद आ रही है? उपर्युक्त विकल्प केवल अल्पकालिक कार्यवाही हैं, समाधान नहीं।

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 
    { 
     /// <summary> 
     /// Required designer variable. 
     /// </summary> 
     private System.ComponentModel.IContainer components = null; 

     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
     protected override void Dispose(bool disposing) 
     { 
      if (disposing && (components != null)) 
      { 
       components.Dispose(); 
      } 
      base.Dispose(disposing); 
     } 

     #region Component Designer generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     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 

    } 
} 

उत्तर

4

आप क्योंकि आप डिजाइनर उपकरण UserControl का एक उदाहरण बन जाता है और साथ नियंत्रण जोड़ते हैं, Load घटना या निर्माता का उपयोग should't: यहाँ WinForms कि मैं googled में कंटेनर नियंत्रण बनाने पर एक ट्यूटोरियल है Load घटना निकाल दी गई है। आपके मामले में जब यह होता है _item अभी भी खाली है। एक और मुद्दा यह है कि वहाँ कुछ एक सूची serializing समस्याएं हैं, तो मैं एक सरणी का उपयोग करना चाहते है:

public partial class RBLTest : UserControl { 
    private RadioButton[] _items; 

    private int leftSpacing = 100; 
    private int topSpacing = 25; 

    public RBLTest() { 
     InitializeComponent(); 
    } 

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] 
    public RadioButton[] Items { 
     get { 
      return _items; 
     } 
     set { 
      _items = value; 

      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); 
      } 
     } 
    } 
} 

प्रपत्र डिज़ाइनर में परिणाम:

enter image description here

+1

Ohhhhhhhhhhhh मैं बस आपको सही गले लगाना चाहता हूँ अब, मैंने इस विषय पर मेरी खराब Google खोजों के साथ इस विषय पर कुछ भी नहीं ढूंढने के साथ इतने लंबे समय तक बिताया है। क्या आपके पास डिज़ाइनर में जेनेरिक सूचियों को क्रमबद्ध करने वाले मुद्दों पर चर्चा करने वाले आलेख का संदर्भ है? – Mohgeroth

+1

हाहा :) मैं आपकी मदद करने में प्रसन्न हूं! –

+2

@Mohgeroth आपको किसी अन्य संग्रह की आवश्यकता नहीं है, आपके पास पहले से ही नियंत्रण संग्रह में एक है, जहां आपके बच्चे के नियंत्रण को किसी भी तरह जीना है। – Tergiver

संबंधित मुद्दे