Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Question migrating from VFP to .NET environment
Message
Information générale
Forum:
ASP.NET
Catégorie:
Programmation orienté objet
Divers
Thread ID:
00663892
Message ID:
00663900
Vues:
13
>I'm sure there's an easy way to do this, but I haven't quite figured it out.
>
>I'm trying to figure out how, in the .NET development environment using WinForms, I can visually create a class and then access it.
>
>For example, in VFP I could create a textbox class, add a few properties to it, add some method code in the GOTFOCUS, LOSTFOCUS events, etc....and then drop that textbox class right on a business form.
>
>How would I do the same general thing in .NET. I'm sure it's easy, but haven't come across how to do it.
>
>Thanks,
>Kevin

Here is how I do it. There may be an easier or better way.

1. Create your project. I use C#.
2. Click on Class View tab next to Solution Explorer
3. Right click on the project goto Add then Add Class...
4. Enter MyButton as the class name
5. In Base Class, select System.Windows.Forms as the Namespace and select Button as the base class.
6. The wizard will create the MyButton subclass. Add the following to the constructor:
this.Text = "My Button";
This is just an example property that you might want to change. You can add whatever other properties and methods to the subclass. When you're in Class View, just drill down to the MyButton Class, right click, select Add... and you can add properties and methods.

7. Build the solution.
8. You can drag a Button onto the form and change it to instantiate Mybutton instead of Button() or what I do is setup the MyButton subclass in the Toolbox and drop that onto my forms.

9. Right click on Toolbox and Add Tab. Enter a new tab name called MyControls.
10. Select MyControls and right click the blank area below Pointer. Click Customize Toolbox and .NET Framework Components. Browse and select the compiled exe for your project in bin\debug (you could have compiled the subclass into a DLL to reuse in multiple projects). MyButton will be selected for you.
11. Drag and drop MyButton from the Toolbox onto the form. Visual Studio puts a default name in the Text property so remember to clear the Text property if you want to see the value that you set in the constructor of the subclass.
12. Run your form and you're done.

You can also explore Visual Inheritance in Visual Studio help.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform