|
|||||||
| Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
DriverHeaven Senior Member
Join Date: May 2002
Posts: 662
Rep Power: 0 ![]() |
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 |
|
|
|
|
|
#2 |
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 70 ![]() |
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)
Code:
Dim pLabel As VB.Label
Set pLabel = Me.Controls.Add("VB.Label", "lblLabel", pContainer)
pLabel.Visible = True
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
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)
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
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 |
|
|
|
|
|
|
|
DriverHeaven Senior Member
Join Date: May 2002
Posts: 662
Rep Power: 0 ![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|