vbkann
asked on
easy!! loading a control
Is there any way of loading a control at run time....or putting some piece of code in an application saying...
"load this control if it exists"
Thanks
"load this control if it exists"
Thanks
I'm sorry, that was meant as a comment, not an answer.
Though, if you will accept is as an answer, that would be nice.
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
Though, if you will accept is as an answer, that would be nice.
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
ASKER
What i want to do is load a control to a form that isnt part of a control array...a control that i havent added on at design time.
Because i am using an outlook express .ocx...not every computer has outlook express installed..so if they dont have outlook installed, my program wont run because if performs an error on startup saying that it cant load that control because it is not there.
So i want to somehow say in code, load this control...if it exists.
If you understand what im saying...
Because i am using an outlook express .ocx...not every computer has outlook express installed..so if they dont have outlook installed, my program wont run because if performs an error on startup saying that it cant load that control because it is not there.
So i want to somehow say in code, load this control...if it exists.
If you understand what im saying...
I Think you cannnot load a control on a form, if you don't use an array of controls as mannen explained.
What you could probably do, is to write an Activex.Exe with a form, that is not visible - this active.exe should own the .ocx-control and it should have a fine ErrorHandling for the case, that the server cannot load because the ocx does not exist on the computer where your programm runs.
So, if the .ocx does not exist, you receive an error in your main application, because the activeX-server was not able to instantiate himself correctly or the call to instantiate the server failed - this error you can catch in your main programm.
If the .ocx exists you can use it within the activeX.exe, but not within your main form.
I think my comment is somehow unclear, but your question is NOT easy.
domib
What you could probably do, is to write an Activex.Exe with a form, that is not visible - this active.exe should own the .ocx-control and it should have a fine ErrorHandling for the case, that the server cannot load because the ocx does not exist on the computer where your programm runs.
So, if the .ocx does not exist, you receive an error in your main application, because the activeX-server was not able to instantiate himself correctly or the call to instantiate the server failed - this error you can catch in your main programm.
If the .ocx exists you can use it within the activeX.exe, but not within your main form.
I think my comment is somehow unclear, but your question is NOT easy.
domib
ASKER
hmmmm i think you know what i want...but i dont have a clue how to do it
' paste this code to EMPTY form, VB6 only!
Option Explicit
' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton
Private Sub ctlCommand_Click()
ctlText.Text = "You Clicked the Command button"
End Sub
Private Sub ctlDynamic_ObjectEvent(Inf o As EventInfo)
' test for the click event of the TreeView
If Info.Name = "Click" Then
ctlText.Text = "You clicked " _
& ctlDynamic.object.selected item.Text
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
' Add the license for the treeview to the license collection.
' If the license is already in the collection you will get
' the run-time error number 732.
Licenses.Add "MSComctlLib.TreeCtrl"
' Dynamically add a TreeView control to the form.
' If you want the control to be added to a different
' container such as a Frame or PictureBox, you use the third
' parameter of the Controls.Add to specify the container.
Set ctlDynamic = Controls.Add("MSComctlLib. TreeCtrl", _
"myctl", Form1)
' set the location and size of the control.
ctlDynamic.Move 1, 1, 2500, 3500
' Add some nodes to the control.
For i = 1 To 10
ctlDynamic.object.nodes.Ad d Key:="Test" & Str(i), Text:="Test" _
& Str(i)
ctlDynamic.object.nodes.Ad d Relative:="Test" & Str(i), _
Relationship:=4, Text:="TestChild" & Str(i)
Next i
' Make the control visible.
ctlDynamic.Visible = True
' add a textbox
Set ctlText = Controls.Add("VB.TextBox", "ctlText1", Form1)
' Set the location and size of the textbox
ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
1, 2500, 100
' Change the backcolor.
ctlText.BackColor = vbYellow
' Make it visible
ctlText.Visible = True
' Add a CommandButton.
Set ctlCommand = Controls.Add("VB.CommandBu tton", _
"ctlCommand1", Form1)
' Set the location and size of the CommandButton.
ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
ctlText.Height + 50, 1500, 500
' Set the caption
ctlCommand.Caption = "Click Me"
' Make it visible
ctlCommand.Visible = True
End Sub
Option Explicit
' If you are adding an ActiveX control at run-time that is
' not referenced in your project, you need to declare it
' as VBControlExtender.
Dim WithEvents ctlDynamic As VBControlExtender
Dim WithEvents ctlText As VB.TextBox
Dim WithEvents ctlCommand As VB.CommandButton
Private Sub ctlCommand_Click()
ctlText.Text = "You Clicked the Command button"
End Sub
Private Sub ctlDynamic_ObjectEvent(Inf
' test for the click event of the TreeView
If Info.Name = "Click" Then
ctlText.Text = "You clicked " _
& ctlDynamic.object.selected
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
' Add the license for the treeview to the license collection.
' If the license is already in the collection you will get
' the run-time error number 732.
Licenses.Add "MSComctlLib.TreeCtrl"
' Dynamically add a TreeView control to the form.
' If you want the control to be added to a different
' container such as a Frame or PictureBox, you use the third
' parameter of the Controls.Add to specify the container.
Set ctlDynamic = Controls.Add("MSComctlLib.
"myctl", Form1)
' set the location and size of the control.
ctlDynamic.Move 1, 1, 2500, 3500
' Add some nodes to the control.
For i = 1 To 10
ctlDynamic.object.nodes.Ad
& Str(i)
ctlDynamic.object.nodes.Ad
Relationship:=4, Text:="TestChild" & Str(i)
Next i
' Make the control visible.
ctlDynamic.Visible = True
' add a textbox
Set ctlText = Controls.Add("VB.TextBox",
' Set the location and size of the textbox
ctlText.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
1, 2500, 100
' Change the backcolor.
ctlText.BackColor = vbYellow
' Make it visible
ctlText.Visible = True
' Add a CommandButton.
Set ctlCommand = Controls.Add("VB.CommandBu
"ctlCommand1", Form1)
' Set the location and size of the CommandButton.
ctlCommand.Move (ctlDynamic.Left + ctlDynamic.Width + 50), _
ctlText.Height + 50, 1500, 500
' Set the caption
ctlCommand.Caption = "Click Me"
' Make it visible
ctlCommand.Visible = True
End Sub
Respect ameba, if that works, I will take the code although.
I agree with db_tiger! You cant load a control without an array...
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
Why not just load the control with the .Enabled and .Visible properties set to "False". Then, if ya need 'em, set those properties to "True", and there they are! Seems to take a lot less code......
-kf
-kf
kfrick, I think you should read the question before answering...
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com
ASKER
ameba...do you know anyway of me doing this in visual basic 5 sp3? as i dont have vb6.
Create Exception Handler
It raises an error so that it can
be trapped with an ON ERROR statement
in the procedure that caused the exception.
You will be able to continue with your program. This should also work for missing OCX-es.
This has been described in VBPJ May 99, but I don't have that article at a moment.
http://www.vbpj.com/ (requires premier membership at http://www.windx.com/)
It raises an error so that it can
be trapped with an ON ERROR statement
in the procedure that caused the exception.
You will be able to continue with your program. This should also work for missing OCX-es.
This has been described in VBPJ May 99, but I don't have that article at a moment.
http://www.vbpj.com/ (requires premier membership at http://www.windx.com/)
Ameba,
I never got the exception handler from the may VBPJ to work. I dled the source and it still does not work. Did you have to change the code to get it to work
I never got the exception handler from the may VBPJ to work. I dled the source and it still does not work. Did you have to change the code to get it to work
I didn't try - I just saw this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question was awarded, but never cleared due to the JSP-500 errors of that time. It was "stuck" against userID -1 versus the intended expert whom you awarded. This corrects that and the expert will now receive these points, all verified.
Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
Thanks,
Moondancer
Moderator @ Experts Exchange
Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
Thanks,
Moondancer
Moderator @ Experts Exchange
I don't understand the "load this control if if exists", what do you mean exists? The control or the program, if it is the program, you have to use subclassing, if not, which type of control is it?
- Vidar Braut Haarr
AmigoSoft Productions
folk@popmail.com