Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
| Search | Today's Posts | Mark Forums Read
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 January 26th, 2005, 06:06 PM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default add control at runtime, pls HELP

Re: pro vb.net 2003 "Add Dynamic Control Demo"

this sub does not work as it should: see end of line notation.
the "new" button is displayed on the screen, but thats all.


    Private Sub AddNewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewButton.Click
        Dim NewButton As Button

        'Create the new control.
        NewButton = New Button()

        'Set it up on the form.
        NewButton.Location() = New System.Drawing.Point(500, 500) ' *** Not working
        NewButton.Size() = New System.Drawing.Size(275, 123) ' *** Not working
        NewButton.Text() = "Button3" ' *** Not working

        'Addti to the forms control collection.
        Me.Controls.Add(New Button())

        'Hook up the Event Handler.
        AddHandler NewButton.Click, AddressOf Me.Button_Clicked ' *** Not working

    End Sub


Private Sub Button_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
        Dim ButtonClicked As Button
        ButtonClicked = CType(sender, Button)

        'Tell the world what button was clicked
        MessageBox.Show("You clicked " & ButtonClicked.Text)

    End Sub
 
Old January 27th, 2005, 09:30 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...

you are in the VB6 forum, not vb.net...

anyway... what type of error do you received?? if your button show correctly it has to work... or you have a problem with your handler??

try reposting this on the .net forum...

HTH

Gonzalo
 
Old January 29th, 2005, 07:04 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks

 
Old February 4th, 2005, 03:39 PM
Authorized User
 
Join Date: May 2004
Location: Karachi, Sindh, Pakistan.
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Jimmy,

Here is what's wrong with your code. Frankly nothin' except a spelling mistake!

The control you are trying to add is a Button named "NewButton". You set some of its properties and finally try to add it to the Controls collection of the Form using this line of code:

                Me.Controls.Add(New Button())

Look closely, you should have written it like this:

                Me.Controls.Add(NewButton())

So what's the difference? an EXTRA SPACE between the words "New" and "Button". What this line of code does is create a new Button control and add this newly created button to the controls collection which is then displayed on the form. And none of its properties, such as Text and Size, will be set, of course!

That's the problem. Change the aforementioned line of code to this:

                Me.Controls.Add(NewButton())

and it will work.

Finally, you should have posted this question to the VB.Net forum. Plz take care with such issues coz it helps to keep the forums organized and thus make life easier for us poor mortals.

Hope your problem is solved.

ejan




Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Runtime Controls dpkbahuguna Beginning VB 6 2 December 7th, 2006 08:55 AM
Add a reference on Runtime anandham Pro VB 6 3 September 18th, 2006 09:16 AM
pls help me out..runtime error 20599 archana007 SQL Server 2000 2 April 5th, 2006 06:14 PM
Crystal reports & ASP - Runtime Error - Pls Help Prasad_Tina Classic ASP Basics 0 January 21st, 2005 10:53 AM





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