Is there a way to make a object(text box;..) with a button (new object for the user on MY project)?
VS 2012 - Object
Page 1 of 18 Replies - 212 Views - Last Post: 14 January 2013 - 12:45 PM
Replies To: VS 2012 - Object
#3
Re: VS 2012 - Object
Posted 13 January 2013 - 03:32 AM
For example : A program where you can create your own form - that's my objective of my program and this point.
Thanks
#4
Re: VS 2012 - Object
Posted 13 January 2013 - 04:52 AM
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim tb As TextBox
tb = New TextBox
tb.Text = "Hi new textbox"
tb.Name = "txtNew1"
tb.Location = New Point(10, 10)
Me.Controls.Add(tb)
End Sub
#5
Re: VS 2012 - Object
Posted 14 January 2013 - 05:52 AM
D.I.C Regular!!! Thanks allot 
Is there anyway that you can save it to the project.. when it loads up again the text box still exist?
Please and thank you
Rudi
Is there anyway that you can save it to the project.. when it loads up again the text box still exist?
Please and thank you
Rudi
#6
Re: VS 2012 - Object
Posted 14 January 2013 - 06:06 AM
Quote
Is there anyway that you can save it to the project.. when it loads up again the text box still exist?
Yes. When you create the TextBox, save all the properties you care about in My.Settings, or in a file.
When you run the program, use that data to to configure a New TextBox.
#7
Re: VS 2012 - Object
Posted 14 January 2013 - 06:08 AM
My.Settings.Save(tb)
Error.. how sould i save it?
#8
Re: VS 2012 - Object
Posted 14 January 2013 - 06:16 AM
My.Settings.TB.Contains(tb.Name)TB = string/user?
Dim c As New TextBox c.Name = My.Settings.TB-> load form
#9
Re: VS 2012 - Object
Posted 14 January 2013 - 12:45 PM
Adding on to what andrewsw said, here is a small program to generate a TextBox, save some properties in My.settings, and to recreate it when the form loads. It changes the Text, so you can see that it recreated it from My.Settings.
All that being said, and depending on how many controls you want to add/reload, you might be better off with a file (XML is best).
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim tb As TextBox
tb = New TextBox
tb.Text = "Hi new textbox"
tb.Name = "txtNew1"
tb.Location = New Point(10, 20)
Me.Controls.Add(tb)
My.Settings.tbName = tb.Name
My.Settings.tbX = 10
My.Settings.tbY = 20
My.Settings.tbText = "This text was saved"
End Sub
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If My.Settings.tbName <> "" Then
Dim tb As TextBox
tb = New TextBox
tb.Name = My.Settings.tbName
tb.Location = New Point(My.Settings.tbX, My.Settings.tbY)
tb.Text = My.Settings.tbText
Me.Controls.Add(tb)
End If
End Sub
All that being said, and depending on how many controls you want to add/reload, you might be better off with a file (XML is best).
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|