VS2008 Windows Form Designer does not like my control.

Posted by Thedric Walker on Stack Overflow See other posts from Stack Overflow or by Thedric Walker
Published on 2008-12-05T22:14:04Z Indexed on 2010/03/20 21:41 UTC
Read the original article Hit count: 346

I have a control that is created like so:

public partial class MYControl : MyControlBase
{
    public string InnerText {
        get { return textBox1.Text; }
        set { textBox1.Text = value; } 
    }
    public MYControl()
    {
        InitializeComponent();
    }
}

partial class MYControl
{
    /// <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.textBox1 = new System.Windows.Forms.TextBox();
        this.listBox1 = new System.Windows.Forms.ListBox();
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(28, 61);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(100, 20);
        this.textBox1.TabIndex = 0;
        // 
        // listBox1
        // 
        this.listBox1.FormattingEnabled = true;
        this.listBox1.Location = new System.Drawing.Point(7, 106);
        this.listBox1.Name = "listBox1";
        this.listBox1.Size = new System.Drawing.Size(120, 95);
        this.listBox1.TabIndex = 1;
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(91, 42);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(35, 13);
        this.label1.TabIndex = 2;
        this.label1.Text = "label1";
        // 
        // MYControl
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Controls.Add(this.label1);
        this.Controls.Add(this.listBox1);
        this.Controls.Add(this.textBox1);
        this.Name = "MYControl";
        this.Size = new System.Drawing.Size(135, 214);
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion


    private System.Windows.Forms.Label label1;
}

MyControlBase contains the definition for the ListBox and TextBox. Now when I try to view this control in the Form Designer it gives me these errors:

The variable 'listBox1' is either undeclared or was never assigned.

The variable 'textBox1' is either undeclared or was never assigned.

This is obviously wrong as they are defined in MyControlBase with public access. Is there any way to massage Form Designer into allowing me to visually edit my control?

© Stack Overflow or respective owner

Related posts about visual-studio

Related posts about visual-studio-2008