The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > General Programming > Visual Basic


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Tags: ,

Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 07-02-2007, 08:28 PM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
Icon11 VB.NET 2005 Daily Lesson [7.02.07] - Custom Controls Pt.1

Many times we want to stylize our form elements but modifying the properties of each form element can only take us so far. In many cases, their is also a need to make a control act in a certain way, but should only be changed once and reflected application-wide. I'll discuss a few ways you can make your OWN controls or extend the current controls for the features and functionality you actually deserve

User controls can be created with whatever elements you like. They can be added by right-clicking the project, and adding a new user control. At this point you are a blank slate, and you can add whatever elements (including other user controls) to your user control. You can even add your own properties which are then viewed and executed real time when you add the to a form. It's pretty cool when you "compile" and you see your own custom control in the toolbar

For example, Create a user control, add 5 textboxes and add this to the code of the User Control.

Code:
Public Class UserControl1

    Private _TextboxBackgroundColor As Color

    Public Property TextBoxBackgroundColor() As Color
        Get
            Return _TextboxBackgroundColor
        End Get
        Set(ByVal value As Color)
            _TextboxBackgroundColor = value
            TextBox1.BackColor = value
            TextBox2.BackColor = value
            TextBox3.BackColor = value
            TextBox4.BackColor = value
            TextBox5.BackColor = value
        End Set
    End Property

End Class
Then hit the compile button and watch how it now appears in your toolbar. Drag your new user control onto a form and notice in your properties window that you have available "TextBoxBackgroundColor" property now. Modify it and see that all 5 textboxes change for the control... Now, you are probably asking why would we do this (besides being freekin sweet). Because it extracts the control and now you can use this control everywhere. When the client decides that only 4 of the 5 textboxes should have that color... then it is only one change and it occurs application-wide.

The next lessons to come will discuss the ability to override controls using their events and how to inherit the already-built controls to make shnazzy looking form controls
Reply With Quote
  #2 (permalink)  
Old 07-02-2007, 09:25 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,109
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
I personally kind of confused with Visual Basic whether this is the VB.NET or not, I'm not sure but I'm confused to both haha... Can you please describe it what happened on each lines? I think the "As Color" is the Inheritance right? I'm not sure with the followings:
- Get
- Set
are those try catch blocks? no right? What is _TextBackgroundColor for?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 07-03-2007, 05:48 AM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
Yes, in VB, getters/setters and called Properties. The Private variable holds the data for color value, the Get returns the private variable, and the Set actually sets the the private variable. We also hook into setting other control properties in our set... so when you set the Property "TextBoxBackgroundColor" to Color.Red for example, it will set all 5 controls and the internal variable so you could retrieve it again later. This way it is realtime in the VisualStudio GUI and you can use the properties in the properties window to see your changes instantly

_TextBackgroundColor is my own variable... showing you can extend these user controls to anything you want...
Reply With Quote
  #4 (permalink)  
Old 07-03-2007, 09:11 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,109
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Quote:
the Get returns the private variable
why do we need to Get the returns of the private variables? if we want to acccess them, can't we just call it...?

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 07-03-2007, 11:15 AM
ccoonen ccoonen is offline
PT Staff
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 4
Join Date: Jun 2007
Location: Wisconsin
Posts: 308
iTrader: (0)
ccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished roadccoonen is on a distinguished road
This is the hook if you ever wanted to retrieve the value that you've set. Say you wanted all form elements to use the same background color that you set your user control. You could set the color of your user control to red, enumerate over all other controls on the form, and "Set" their background color from the "Get" of your User control.

In all reality, if you wanted to limit it to "Set Only" you could change it the property to WriteOnly but then your loosing the ability to get the value realtime.

Code:
Public Class UserControl1
    Public WriteOnly Property TextBoxBackgroundColor() As Color
        Set(ByVal value As Color)
            TextBox1.BackColor = value
            TextBox2.BackColor = value
            TextBox3.BackColor = value
            TextBox4.BackColor = value
            TextBox5.BackColor = value
        End Set
    End Property
End Class

Last edited by ccoonen : 07-03-2007 at 11:17 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

   Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 04:40 PM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50