Go Back   DriverHeaven.net > Forums > Software / Tools > Programming, Coding, (Web)Design

Notices

Reply
 
LinkBack Thread Tools Display Modes
Old Jul 17, 2002, 10:26 AM   #1 (permalink)
Yeti
DriverHeaven Senior Member
 
Join Date: May 2002
Posts: 662
Yeti is on a distinguished road

Default Post C++/ VB question.

First off i'm using VB/VC because they are the most available and (?)easiest gui design apps. I write most of my backend code in C++ and run it through system calls.

I am trying to design a control that would have the ability to spawn controls within itself. I am about to embark on a gigantic hunt for information regarding the creation of controls during runtime. I was, however, hoping that someone on my beloved dh.net forum might give me a heads up as to how to spawn a control while running an app.

I really don't care which compiler/interface/library/language you use as long as i can get a hold of it (and i'm not too unfarmiliar with it).

I'm sure there is a perfectly logical and valid way of spawning controls... or perhaps there is even a control of the type i am looking for... i just haven't found it yet.

Thanks for any info in advance... will be watching this thread actively.

-------------------------------
In case you are wondering the specific use i have for this is a logical diagram. (close to, but not entirely a tree).

Thank you. <bow>
__________________
--Oh lord not again
Yeti is offline   Reply With Quote
Old Jul 17, 2002, 06:41 PM   #2 (permalink)
UberLord
A Legend in Underwear
 
UberLord's Avatar
 
Join Date: May 2002
Location: Unknown
Posts: 5,256
UberLord is on a distinguished road

Default Post

Its quite easy in VB.

Step one - add a container control like a PictureBox
Code:
Dim pContainer As VB.PictureBox
Set pContainer = Me.Controls.Add("VB.PictureBox", "picContainer" , Me)
Step two add the control
Code:
Dim pLabel As VB.Label
Set pLabel = Me.Controls.Add("VB.Label", "lblLabel", pContainer)
pLabel.Visible = True
The last parameter on the Add method for Controls is a reference to the container control you're adding this to. If its an OCX you're making then replace "Me" with "UserControl" in the adding container code. Also, all added controls are invisible by default so make then visible

The hard part is VB has no easy way of catching events from these controls, so we need a few extra steps.

Step three - add a class module to control each type of control you add - in this case Labels. The gControls bit will be explained later
Code:
Option Explicit

Private WithEvents mControl As VB.Label

Public Property Get Control() As Control
    Set Control = mControl
End Property
Public Property Set Control(ByRef Value As Control)
    Set mControl = Value
End Property

Private Sub mControl_Click()
    Call gControls.lblLabel_Click(mControl)
End Sub
Step Four - create a new instance of this class for each object you wish to control and add it to a collection.

Code:
Private mControls As Collection

Private Sub ControlLabel(ByRef Control As VB.Label)
Dim pControl As lblLabel
    
    Set pControl = New lblLabel
    Set pControl.Control = Control
    mControls.Add pControl, Control.Name
    Set pControl = Nothing

End Sub

Call ControlLabel(pLabel)
Step Five - create a global reference to a form/object/whatever that handles the control events. In this case a form
Code:
' Global module somewhere
Public gControls as frmControls

Set gControls = new frmControls
Code:
'frmControls

Public Sub lblLabel_Click(ByRef Label As VB.Label)
       Debug.Print "You clicked label " & Label.Name
End Sub
IMPORTANT!!!!!
If you remove the controls its easiet to just remove the container - saves having to remove each control itself
If you remove any control, you MUST remove its control class from the collection as well otherwise VB will explode

HTH

__________________
Gentoo Linux - Developer (baselayout)
Read my blog

"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours."
Stephen Roberts
UberLord is offline   Reply With Quote
Old Jul 17, 2002, 08:40 PM   #3 (permalink)
Yeti
DriverHeaven Senior Member
 
Join Date: May 2002
Posts: 662
Yeti is on a distinguished road

Default Post

Hmm, i think i'm going to have to mess around with that a little. (Basic is not my forte but this is as good an opportunity as any to learn) . Thanks for all the help... i'm gonna bookmark this thread.

__________________
--Oh lord not again
Yeti is offline   Reply With Quote
Reply

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump




 

 
Powered by: vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Artwork by Allan 'Zardon' Campbell, vBulletin implementation by Craig '5320' Humphreys based on original artwork by Ratchet.

All times are GMT -5. The time now is 11:16 PM. Copyright ©2008 DriverHeaven.net