PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
Go Back  Xtreme Visual Basic Talk > > > PPC - Dynamic Object question (newby)


Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2011, 02:14 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Question PPC - Dynamic Object question (newby)


All,

I am working on creating an application (game) for a PocketPC with Visual Studio2005 in VB/.NET. I try to dynamically create a (new)button upon clicking a label and assigning certain properties to this button. For this I used below displayed code, but this button does not appear on 'Form1' -which is big enough to display it- but creates an error: A NullReferenceException. Such occurs when you try to reference an object in your code that does not exist, but I think I just did by using'..New..'

Who can tell me what is wrong and how to fix this?


Public Class Form1

Public Class NewBtn
Inherits Button
End Class

Private Sub Label1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Dim Btn As New Button
With Btn
.Text = "Button88"
.Name = "Button88"
.Location = New Point(100, 100)
.Size = New Point(20, 20)
.Visible = True
End With
End Sub

End Class
Reply With Quote
  #2  
Old 04-15-2011, 05:32 PM
Qua's Avatar
QuaPPC - Dynamic Object question (newby) Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

First of all, the NewBtn class isn't being reference anywhere in the code you've posted. To your actual problem: You're forgetting to add the newly created button to the form:
Code:
Me.Controls.Add(Btn)
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #3  
Old 04-18-2011, 03:55 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Default

Qua,

Yuo are correct regarding that reference.... I should/could have used:

Dim Btn As NewBtn...

Anyway, from others I got similar reply and this issue has been solved..
Next I have to add / catch the action and follow up on this when such 'dynamic button' has been clicked. Any idea how to do that? From the clicked button I need to learn the name and text properties. These properties are being used later in the final application.
Reply With Quote
  #4  
Old 04-20-2011, 05:26 PM
Qua's Avatar
QuaPPC - Dynamic Object question (newby) Qua is offline
Impetuous & volatile

* Expert *
 
Join Date: Apr 2005
Posts: 2,177
Default

Look into the Addhandler statement. It will allow you to hook up events for dynamically created objects.
__________________
Reading is the foundation for all knowledge - Unknown.
Reply With Quote
  #5  
Old 04-21-2011, 12:49 PM
Adri17's Avatar
Adri17 Adri17 is offline
Newcomer
 
Join Date: Apr 2009
Posts: 17
Default Thanks

Qua,

Many thanks, it does work now.
Reply With Quote
Reply

Tags
dynamic object, newby, pocket


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby) PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
 
PPC - Dynamic Object question (newby)
PPC - Dynamic Object question (newby)
 
-->