Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - VB.NET -- Dynamically created controls
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

VB.NET -- Dynamically created controls

 Post Reply Post Reply Page  123 4>
Author
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Topic: VB.NET -- Dynamically created controls
    Posted: 24 May 2004 at 7:36pm
is there any way to a function to a dynamically created button on a Win Form for VB.NET? Even if it could inherit the functions and attributes from another button it would be fine.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 2004 at 2:53am

Dim YourButton As New System.Web.UI.Button

YourButton.Text = "Your text"

YourButton.OnClick = New EventHandler(AddressOf YourButton_OnClick)

Then put a place holder where you want the button to go and use

[PlaceHolder].Controls.Add(YourButton)

Or add it straight to the page without a placeholder like this:

Me.Controls.Add(YourButton)

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 25 May 2004 at 3:48pm

win forms... it gives me an error

C:\Documents and Settings\Administrator\Desktop\Programming Development\dotNET\Comnk\Form1.vb(88): 'System.Windows.Forms.Control.Protected Overridable Overloads Sub OnClick(e As System.EventArgs)' is not accessible in this context because it is 'Protected'.

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 2:50am
Just remove the 'Protected' and change it to 'Public'
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 3:26pm
the protected where? i never declared it protected
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 3:29pm

the code i'm trying to use this with is...

Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter

Dim location As System.Drawing.Point

Dim x As Integer

Dim y As Integer

x = CInt(Int((1024 * Rnd()) + 1))

y = CInt(Int((768 * Rnd()) + 1))

location.X = x

location.Y = y

Button1.Location = location

Dim buttonarray As Collection

Dim btn(1) As Button

Dim i As Integer = 0

For i = 0 To 1

btn(i) = New Button()

x = CInt(Int((1024 * Rnd()) + 1))

y = CInt(Int((768 * Rnd()) + 1))

btn(i).Location = New System.Drawing.Point(x, y)

btn(i).Name = "btn(" & i & ")"

btn(i).Size = New System.Drawing.Size(120, 40)

btn(i).Text = "CLICK ME!"

Me.Controls.Add(btn(i))

Next

End Sub

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 3:30pm
wait... does it need to be in a different method that doesn't handle button1.mouseenter?
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 26 May 2004 at 3:33pm
nope... same problem
Back to Top
 Post Reply Post Reply Page  123 4>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.