Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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, 05:23 PM
Registered User
 
Join Date: Jan 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Create Control, Runtime

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 29th, 2005, 10:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

You have:

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

Should be:

'Add it to the forms control collection.
 Me.Controls.Add(NewButton)

NewButton is the name of your control. The way you have it set up, you are instantiating a new instance of the button class with no properties (other than defaults) set, and adding that default Button to the Form's controls collection. The event handler should work now too.

- Bob








Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to create button control in runtime. wongsak VS.NET 2002/2003 3 October 20th, 2006 07:10 AM
create query at runtime vipinpaliwal1980 Access 1 April 24th, 2006 06:27 AM
Create Controls at Runtime everthalia Classic ASP Databases 2 July 30th, 2004 10:21 PM
Create Table at RunTime btpoole VB Databases Basics 0 March 2nd, 2004 11:13 AM
How to create controls at runtime ? kishore_peddi C# 1 November 3rd, 2003 09:22 PM





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