Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Just to make sure I am doing it right
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00984198
Message ID:
00984222
Vues:
18
Kevin,
Thank you very much for your reply. I can see that there is a lot of extra overhead subclassing the winform controls the way I do. I guess the only benefit is that I can change the properies using the property sheet. Just for a comparison here is the code I use to subclass System.Windows.Forms.Label:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace ALS.Subclass
{
	public class Label : System.Windows.Forms.Label
	{
		private System.ComponentModel.Container components = null;

		public Label()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(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()
		{
			// 
			// Label
			// 
			this.AutoSize = true;
			this.Size = new System.Drawing.Size(0, 16);

		}
		#endregion
	}
}
I think I will switch over to your method of subclassing winform controls this weekend.

Einar



>Einar,
>
>Here's what I did when I created my set of subclassed winform controls. I have a separate project called cgsControls.
>
>1) Create a new project as a class library. I called mine cgsControls
>2) I renamed the new Class1.Cs to cgsControls.Cs
>3) I add a reference in the new project to System.Windows.Forms and System.Drawing
>4) In CgsControls.cs, I use the following to subclass the label and textbox control
>
>
>using System;
>using System.Drawing;
>using System.Drawing.Drawing2D;
>using System.Windows.Forms;
>
>namespace cgsControls
>{
>	public class cgsLabel: System.Windows.Forms.Label
>	{
>		override public Font Font
>		{
>			get { return base.Font; }
>			set { ; }
>		}
>
>		public cgsLabel()
>		{
>			base.Font = new  Font("Verdana",8);
>		}
>	}
>
>	public class cgsTextBox: System.Windows.Forms.TextBox
>	{
>		override public Font Font
>		{
>			get { return base.Font; }
>			set { ; }
>		}
>
>		public cgsLabel()
>		{
>			base.Font = new  Font("Verdana",8);
>		}
>	}
>
>}
>
>
>You may want to add all your subclass definitions in here (datetime picker, command button, combox box, etc.)
>
>5) I build the project DLL.
>
>6) Then, I start a new winform project. In order to see the text and label classes in my toolbox (so that I can drop them on a form), I go to my toolbox, right-click, take "Add/remove items", and then browse for the cgsControls.DLL in the BIN/DEBUG folder of the location where I saved my cgsControls project. (Before you take add/remove items, you may wish to add a brand new tab first, specificallly for your subclassed controls).
>
>Hopefully that should get you started. You only need to use "usercontrol" if what you're actually building is a usercontrol (collection of your subclasseed controls...VFP's equivalent to a container). Let me know if that helps.
>
>Kevin
Semper ubi sub ubi.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform