Monday, January 18, 2010

Custom Controls in VB.net?

I am working in Visual Studio 2008 (VB.Net) on a Bingo game for my wife. The game will have 18 faces (individual bingo cards) and I am using individual labels (25 per face) and writing the label value from arrays of random numbers. This is great but, the individual naming of all the labels gets to be a bit tedious after a while. IE f1_bp1, f1_bp2 where f1 means face 1 and bp1 and 2 would be B row Position 1 and 2.


My question is this, is there a way that I can take my first finished card and make it into a custom control and then just add 18 of them onto my form, perhaps loading the labels with a couple arrays? Any help would be great, as I've been promising her this for 6 months now.Custom Controls in VB.net?
Okay. If I understand you correctly your're writing the same code 18 times? You can use a custom control.





In visual studio go to new, and select WebUserControl ( or something like it ). It will have an extension of .ascx.





Create you're entire bingo card within the .ascx page.





Now on the page you want to use the custom bingo card control put this at the top...(my syntax may be wrong)





%26lt;%@ Register TagPrefix=';UC'; TagName=';TestControl'; Src=';test.ascx'; %%26gt;';





now anywhere you want to use this control you'll be able to insert similar to any asp:Label control but you'll have to use you're custom code...like the following





%26lt;UC:TestControl id=';MyBingoControl'; runat=';Server'; /%26gt;





Well I hope that helps....





Check out this page.


http://support.microsoft.com/kb/893667

No comments:

Post a Comment