Click here to Skip to main content
15,924,679 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralCustom Menus Pin
Pugman8129-Feb-04 17:12
Pugman8129-Feb-04 17:12 
GeneralRe: Custom Menus Pin
John Kuhn9-Feb-04 17:14
John Kuhn9-Feb-04 17:14 
GeneralRe: Custom Menus Pin
Corinna John9-Feb-04 21:03
Corinna John9-Feb-04 21:03 
GeneralWord VBA, modallity and hiding user form Pin
JasHDahi9-Feb-04 10:14
JasHDahi9-Feb-04 10:14 
GeneralControl Pin
Anonymous9-Feb-04 7:54
Anonymous9-Feb-04 7:54 
GeneralRe: Control Pin
Dave Kreskowiak9-Feb-04 11:15
mveDave Kreskowiak9-Feb-04 11:15 
GeneralRe: Control Pin
Anonymous10-Feb-04 4:04
Anonymous10-Feb-04 4:04 
GeneralRe: Control Pin
Dave Kreskowiak10-Feb-04 5:19
mveDave Kreskowiak10-Feb-04 5:19 
Wait a minute... My mistake, I thought you were using two command buttons. D'Oh! | :doh:

OK. An OCX means your using VB6...

What you have to do is expose (make Public) your own custom Property. What you would normally do is define an global variable used internal to your control, like m_OptionPicked. You use the optYes and optNo click events to set the value of that variable, either a number or some predefined Enumeration, whatever you want your Property to expose. I'll use an Enum to demonstrate:

' Setup our Public enumeration values
' These are the possible values of our controls property.
Public Enum ControlOptions
    Undefined = -1
    Yes = 1
    No = 0
End Enum
 
' Internal variables (visible only inside the control!)
' Declaring as 'ControlOptions' will limit the value to
' the possible values of our Enumeration above.
Private m_OptionPicked as ControlOptions

Now, when an option button is clicked, you handle the Click event just as you have in your previous post, BUT you set the value of m_OptionPicked to one of the predefined values of ControlOptions, like this:
Private Sub UserControl_Initialize()
    m_OptionPicked = ControlOptions.Undefined
End Sub
 
Private Sub optYes_Click()
    m_OptionPicked = ControlOptions.Yes
End Sub
 
Private Sub optNo_Click()
    m_OptionPicked = ControlOptions.No
End Sub

Almost done! Now you have to expose the internal variable as a Property of your control. You can do this using the Property statements. We're going to make a property called OptionPicked that your control exposes to its host. The code in the Property statement will just return the value of the internal variable m_OptionPicked. Once again, we'll declare that the value returned is one of the possible values of ControlOptions above.
Public Property Get OptionPicked() as ControlOptions
    return m_OptionPicked
End Property

Since we have only a Property Get defined for OptionPicked, is automatically becomes a Read-Only property. That is, your application can only read the value of OptionPicked, it can't set a new value for it. If you wanted to do that, you would have to define a block of code for a Property Set statement so your control knows what to do with the new value:
Public Property Set OptionPicked( NewValue as ControlOptions )
    m_OptionPicked = NewValue
    ' Some addition code to alter the status
    ' of the option buttons on screen should go here.
End Property

That's all there is to it! This is a little more code than required to expose the value of an option button, but more complex controls would follow this framework.

Let me know how it goes!



RageInTheMachine9532
GeneralRe: Control Pin
Anonymous10-Feb-04 5:51
Anonymous10-Feb-04 5:51 
GeneralRe: Control Pin
Dave Kreskowiak10-Feb-04 6:09
mveDave Kreskowiak10-Feb-04 6:09 
GeneralRe: Control Pin
Mike Dimmick10-Feb-04 6:20
Mike Dimmick10-Feb-04 6:20 
GeneralRe: Control Pin
Dave Kreskowiak10-Feb-04 6:32
mveDave Kreskowiak10-Feb-04 6:32 
GeneralRe: Control Pin
Anonymous10-Feb-04 6:46
Anonymous10-Feb-04 6:46 
GeneralRe: Control Pin
Dave Kreskowiak10-Feb-04 7:03
mveDave Kreskowiak10-Feb-04 7:03 
GeneralRe: Control Pin
Anonymous10-Feb-04 7:18
Anonymous10-Feb-04 7:18 
GeneralRe: Control Pin
Dave Kreskowiak10-Feb-04 8:12
mveDave Kreskowiak10-Feb-04 8:12 
GeneralRe: Control Pin
Anonymous10-Feb-04 8:20
Anonymous10-Feb-04 8:20 
General[Urgent] Progress Control And ListView Control Pin
The Bees9-Feb-04 0:12
The Bees9-Feb-04 0:12 
GeneralRe: [Urgent] Progress Control And ListView Control Pin
nonGuru9-Feb-04 17:25
sussnonGuru9-Feb-04 17:25 
QuestionUML and implementation mapping in different programming languages? Pin
MelaOS8-Feb-04 22:00
MelaOS8-Feb-04 22:00 
AnswerRe: UML and implementation mapping in different programming languages? Pin
John Kuhn9-Feb-04 12:59
John Kuhn9-Feb-04 12:59 
GeneralRe: UML and implementation mapping in different programming languages? Pin
MelaOS9-Feb-04 13:58
MelaOS9-Feb-04 13:58 
GeneralRe: UML and implementation mapping in different programming languages? Pin
John Kuhn9-Feb-04 15:20
John Kuhn9-Feb-04 15:20 
GeneralCabinet.dll in VB.NET Pin
Eduard Keilholz8-Feb-04 21:08
Eduard Keilholz8-Feb-04 21:08 
GeneralStore an image in Access using ADODB Pin
praveed8-Feb-04 19:05
praveed8-Feb-04 19:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.