|
-
Oct 10th, 2006, 03:58 PM
#1
[RESOLVED] Dynamically adding and removing RTB control
Hello,
I think the subject said it all. So, is it possible??
Thank you.
-
Oct 10th, 2006, 04:17 PM
#2
Re: Dynamically adding and removing RTB control
make sure that RichTextBox is in the components list.
uncheck "Remove information about unused activeX controls" in the 'Make' tab of the project properties.
then it's just a case of doing:
VB Code:
Private WithEvents rtb As RichTextLib.RichTextBox
Private Sub Form_Load()
Set rtb = Me.Controls.Add("RICHTEXT.RichTextCtrl.1", "RichTextBox1")
rtb.Visible = True
End Sub
-
Oct 10th, 2006, 04:26 PM
#3
Re: Dynamically adding and removing RTB control
Thank you so much!!
BTW, what is the significance of .1 in the Add function??
-
Oct 10th, 2006, 04:30 PM
#4
Re: Dynamically adding and removing RTB control
 Originally Posted by Harsh Gupta
Thank you so much!!
BTW, what is the significance of .1 in the Add function??
no probs 
i don't think there's any significance, it's just the ProgId.
do:
VB Code:
Set rtb = Me.Controls.Add("RichTextLib.RichTextBox", "rtb")
and you'll see what I mean.
-
Oct 10th, 2006, 05:25 PM
#5
Re: Dynamically adding and removing RTB control
Ok, did a bit of RnD on ProgID. Searched the Reg Editor and noticed that almost all controls we use, the Reg Edit. has 2 ProgIDs, one with .1 and another without .1 but both having same CLSID, and further digging into the CLSID revealed that the ID with .1 has a Key [VersionIndependentProgID], its value being the ProgID without .1.
From ProgID on VBAccelerator
When you request an instance of the cFlatControl class, COM looks up the ProgID "vbalFCtl.cFlatControl" which gives it the GUID of the object. COM can then locate the GUID and therefore the path to the object. This is where the problem arises with two objects with the same ProgID. If you create a new version of the Flat Control DLL, say it either has with different methods or it is compiled in VB6 instead of VB5, you will automatically generate a new GUID. However, if you don't change either the project name or the class name, you will overwrite the existing ProgID with your own version. Anyone else's code which expects to get an instance of the object suddenly gets routed to the new version, and their code may then fail depending on what you've done to the existing class.
Talking about RichTextLib.RichTextBox, if I make my own version of RTB and name it RichTextLib.RichTextBox.2, then will it:
1) Generate a new progID? or
2) Overwrite the old progID (i.e. overwrite the RichTextLib.RichTextBox.1)? or
3) Rest in harmony with the default two?
Thank you.
-
Oct 10th, 2006, 05:45 PM
#6
Re: Dynamically adding and removing RTB control
-
Oct 10th, 2006, 06:15 PM
#7
Re: Dynamically adding and removing RTB control
 Originally Posted by MartinLiss
Sorry, but the link said nothing about the ProgID concept!!
I have the answer to my original question. There is something related to it that I haven't understood.
-
Oct 10th, 2006, 06:55 PM
#8
New Member
Re: Dynamically adding and removing RTB control
Most times the easiest way to dyanamically create and get rid of controls at run time is to create a control array. You can do this by simple copying as pasting a copy of the control on the form. then you can delete the extra one. This sets up an array of controls that can be created with the load statement. Then you assign properties to the new control.
load some_control(index number)
With some_control(index number)
.Top = 300
.Left = 500
.Text = "Some Text"
End With
Hope this helped
-
Oct 11th, 2006, 01:35 PM
#9
Re: Dynamically adding and removing RTB control
hmmf....I shall mark this thread resolved and ask the second question in GD section.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|