Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Form custom control as template
Message
De
10/03/2006 00:43:39
 
 
À
09/03/2006 22:23:02
Rene Lovino
Bigfoot Global Solutions, Inc
Cebu, Philippines
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01102969
Message ID:
01102987
Vues:
16
This message has been marked as the solution to the initial question of the thread.
Rene,

Once you create a base class Form, all you need to do to use it is:

1)Right-click on your Project
2)Choose Add | Add Inherited Form
3)Name the Form when the Dialog appears & Click the Open button
4)Another Dialog appears, the Inheritance Picker, for you to choose a Form to inherit from.

That's it ... except for one small detail. What I just outlined above is for VS 1.1. It looks like it's a little different in 2.0. In 2.0, you'd do this:

1)Right-click on your Project
2)Choose Add | Add Windows Form
3)Name the Form, and Pick "Inherited Form" from the list of templates
4)Another Dialog appears, the Inheritance Picker, for you to choose a Form to inherit from.

For sub-classing other controls (like TextBoxes, etc.), you'll want to do something like this.
Basically, you'll want a class library that contains your sub-classed UI controls, like textbox, button, etc. Something like this:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MyCompany.WinUI.MyClasses
{
	public class MyComboBox : System.Windows.Forms.ComboBox
	{
		// code here
	}

	public class MyTextBox : System.Windows.Forms.TextBox
	{
		// code here
	}

	public class MyButton : System.Windows.Forms.Button
	{
		// code here
	}
}
That's it. These controls can't be sub-classed visually, but as you can see, it's easy enough to do it in code. I have all the basic controls sub-classed in one class library file. Once they're added to the ToolBox, then can be dragged onto any design surface in the IDE.

To add to the ToolBox, When you have the IDE open in the designer view (not the code view), go to the ToolBox, right-click anywhere and choose the Add/Remove Items (in 2.0, it's "Choose Items..."), click on Browse and find the .DLL where your sub-classed controls are (you obviously needed to have compiled the class library after you created it). That's it ... they'll then be added to your ToolBox.

~~Bonnie





>Hi All,
>
>Is there a way to create Windows Form as a user template using custom control?
>What I want to do is similar to Visual FoxPro Visual Class.
>In Visual FoxPro we can create a VCX using Form class and add some methods and property.
>All developer that have experience in VFP visual class may understand what I mean.
>In VFP we can set the form template in the Tools menu -> Options -> Forms Tab -> Template Classes -> Formset or Form.
>The advantage of this is everytime you create a new form, all define properties and methods are already there.
>And just in case I want to change the color of my form I will only change the form class and no need to change other forms.
>
>Anybody have an idea?
>
>
>TIA,
>
>Rene
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform