Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to subclass control?
Message
From
22/04/2008 01:15:23
 
 
To
21/04/2008 10:05:51
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01184867
Message ID:
01312306
Views:
17
This doesn't work. Have you tried dragging that "Component TextBox" from the ToolBox onto a Form? Seems it disappears somewhere ... well, it's not visible anyway. Components are not meant to be used this way.

The preferable way to do this is to create one file that holds most of these simple types of controls (TextBox, ComboBox, ListBox, ListView, CheckBox, etc.), as I have previously mentioned.

As far as the purpose of a Component class, here's what the documentation says about it:

Component is the base class for all components in the common language runtime that marshal by reference. Component is remotable and derives from the MarshalByRefObject class. Component provides an implementation of the IComponent interface. The MarshalByValueComponent provides an implementation of IComponent that marshals by value.

You can host a Component in any object that implements the IContainer interface, and you can query and get services from its container. The container creates an ISite for each Component it contains. The container uses the site to manage the Component and is used by the Component to communicate with its container.


That certainly doesn't sound like something I want to stick a TextBox on. <g>

Your TextBox class would simply look something like this, which seems much simpler to me:
    public class MattsTextBox : OakLeaf.MM.Main.Windows.Forms.mmTextBox
    {
        public MattsTextBox()
        {
            this.BindingSourceMember = null;
            this.ControlID = new System.Guid("00000000-0000-0000-0000-000000000000");
            this.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ForeColor = System.Drawing.Color.Red;
            this.Location = new System.Drawing.Point(0, 0);
            this.Name = "mmTextBox1";
            this.Size = new System.Drawing.Size(100, 22);
            this.TabIndex = 0;
        }
    }
}
~~Bonnie




>In that post, you said you can't do it visually, but I noticed that if I choose "Component Class" when adding a new item to my project, I get a deisnger surface that I can drag a base class onto, then I seem to be off and running visually.
>
>I get custom code in the Component.cs file, and generated code in the Component.Designer.cs that seems to handle all my defaults that I set in the properties window. This is certainly more appealing to me (the properties window).
>
>If this is not the purpose of a Component Class template, please help me understand what it it.
>
>
>Here is the code-behind of the Component.cs file
>
>using System;
>using System.Collections.Generic;
>using System.ComponentModel;
>using System.Diagnostics;
>using System.Linq;
>using System.Text;
>
>namespace lmforms
>{
>    public partial class Component2 : Component
>    {
>        public Component2()
>        {
>            InitializeComponent();
>        }
>
>        public Component2(IContainer container)
>        {
>            container.Add(this);
>
>            InitializeComponent();
>        }
>    }
>}
>
>
>
>And here is the genereted code in the Component.Designer.cs file:
>
>namespace lmforms
>{
>    partial class Component2
>    {
>        /// <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.mmTextBox1 = new OakLeaf.MM.Main.Windows.Forms.mmTextBox();
>            //
>            // mmTextBox1
>            //
>            this.mmTextBox1.BindingSourceMember = null;
>            this.mmTextBox1.ControlID = new System.Guid("00000000-0000-0000-0000-000000000000");
>            this.mmTextBox1.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
>            this.mmTextBox1.ForeColor = System.Drawing.Color.Red;
>            this.mmTextBox1.Location = new System.Drawing.Point(0, 0);
>            this.mmTextBox1.Name = "mmTextBox1";
>            this.mmTextBox1.Size = new System.Drawing.Size(100, 22);
>            this.mmTextBox1.TabIndex = 0;
>
>        }
>
>        #endregion
>
>        private OakLeaf.MM.Main.Windows.Forms.mmTextBox mmTextBox1;
>    }
>}
>
>
>
>>>Can you also go and read my thread# 1311814?
>>
>>I already have ... John pointed you to another post of mine with the same suggestions I would make all over again. Did that not help?
>>
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform