Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2007, 05:35 AM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic control events???

How do i make events on my dynamically created controls? etc. LostFocus

THANKS!

Regards.

 
Old June 12th, 2007, 11:37 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Use AddHandler.

<Scratch that... Sorry: that was a .NET solution. I don't know the answer to your question. I think that maybe you can add the events as routines in advance. They would never be called, and so there would be no error. If you then add the controls dynamically, using predefined control names, and using With Events, I think the previously written handlers would get called. Needs to be tested though.>
 
Old June 15th, 2007, 07:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

in vb6???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old June 18th, 2007, 03:05 AM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, in VB6 - Thanks!

 
Old June 18th, 2007, 01:25 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Did you try adding the subs that would normally be there for a control, and seeing if newly created controls utilize those subs once the control has been created?
 
Old June 19th, 2007, 07:00 AM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, tried that but unsuccessful.

 
Old June 19th, 2007, 08:15 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

create a ControlArray and then load controls at run time...i belev it will work..

 
Old June 19th, 2007, 12:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

you can try this easily... put a control of the type you need on the form... put it index=0... Write all the handles you need for it.. try the program and you will see that the handles executes ok for it... now use load to add controls of that specific type (using the one that is on the form), adding 1 to the index.. you can have it invisible (the original one)...



HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old June 19th, 2007, 04:50 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When you create an array of controls like this, the events that handle it have an Index argument. (Either create the array first, or go back and add "Index As Integer" as an argument of the Sub(s).). You can turn a control into a control array by creating one, selecting it, copying it to the clipboard, selecting the [u]form</u> then pasting the control. You will be asked whether you want to create an array or not.

You would use that index to control the behavior within the one event handler if you need distinct behavior for the different controls in the array.
 
Old June 20th, 2007, 09:09 AM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've been trying this but no success.:

'Text1(0) created in design time
Set txtObj = Controls.Add("VB.Textbox", "Text1")
With txtObj
    .Visible = True
    .Top = 120
    .Left = 1000
    .Width = 1000
    .Height = 300
    .Alignment = vbCenter
    .ZOrder 0
    .SelStart = 0
    .SelLength = Len(txtObj.Text)
' .Index = 1
End With

Error:
727 ; There is already a control with the name 'Text1'

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot update control from DLL events sreecareer ASP.NET 2.0 Basics 0 October 27th, 2008 08:01 PM
Need Help with Dynamic Link Label Click Events chobo2 C# 4 November 8th, 2007 03:47 AM
Events for custom control in datarepeater?? lauriedthompson VB How-To 0 June 20th, 2007 05:11 AM
Control that detects events Eyob_the_pro C# 7 February 14th, 2007 11:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.