Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 26th, 2005, 05: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
Reply With Quote
  #2 (permalink)  
Old January 27th, 2005, 08: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
Reply With Quote
  #3 (permalink)  
Old January 29th, 2005, 06:04 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks

Reply With Quote
  #4 (permalink)  
Old February 4th, 2005, 02: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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Runtime Controls dpkbahuguna Beginning VB 6 2 December 7th, 2006 07: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 09:53 AM



All times are GMT -4. The time now is 04:23 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.