|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Help reading simple text fileI have this simple code below that writes my forms buttons name and location to a text file. What I am really struggling with is the code to read the information back in form the text file and create and position a new button based on the information. Any Ideas? Dim TW As System.IO.TextWriter TW = System.IO.File.CreateText("C:\MyTextFile.txt") Dim C As Control For Each C In Me.Controls If TypeOf C Is Button Then TW.WriteLine(C.Text) TW.WriteLine(C.Location) End If Next Here's the solution:
Imports System.io ' I clicked button 1 & put the following code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sw As New StreamWriter("C:\MyControlName.txt", False) Dim c As Control For Each c In Me.Controls If TypeOf c Is Button Then sw.WriteLine(c.Text) sw.WriteLine(c.Location.ToString) End If Next sw.Flush() sw.Close() End Sub ' Exit the application Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click Application.Exit() End Sub ================= Sample application attached I hope this helps, Newbie Coder Show quoteHide quote "Marc" <marc_cro***@hotmail.com> wrote in message [attached file: Control Names (Text File).zip]news:1164390428.365453.313110@f16g2000cwb.googlegroups.com... > HI, > > I have this simple code below that writes my forms buttons name and > location to a text file. > > What I am really struggling with is the code to read the information > back in form the text file and create and position a new button based > on the information. > > Any Ideas? > > Dim TW As System.IO.TextWriter > TW = System.IO.File.CreateText("C:\MyTextFile.txt") > Dim C As Control > For Each C In Me.Controls > If TypeOf C Is Button Then > TW.WriteLine(C.Text) > TW.WriteLine(C.Location) > End If > Next > Marc,
Try to serialize your buttons, I have read this in past as original from Tom Shelton in this newsgroup. http://www.vb-tips.com/dbPages.aspx?ID=7ffd296f-9e81-47e6-88dc-61641f5c8d9d And don't forget to do this first with your buttons as he write here. http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/e236fbe04dc0d2aa?hl=en& :-) CorShow quoteHide quote "Marc" <marc_cro***@hotmail.com> schreef in bericht news:1164390428.365453.313110@f16g2000cwb.googlegroups.com... > HI, > > I have this simple code below that writes my forms buttons name and > location to a text file. > > What I am really struggling with is the code to read the information > back in form the text file and create and position a new button based > on the information. > > Any Ideas? > > Dim TW As System.IO.TextWriter > TW = System.IO.File.CreateText("C:\MyTextFile.txt") > Dim C As Control > For Each C In Me.Controls > If TypeOf C Is Button Then > TW.WriteLine(C.Text) > TW.WriteLine(C.Location) > End If > Next >
Need Help on String.Format() method
Books for learning VB.NET Serialization Help!!!!!!!!!! VB 2005 Initialising Toobar upload file to web-browser Need help to marshall Win32 DLL call to VB.net Beginners needs some help in Writing to text file Needto grab the name and position of all buttons on a form -is this possible? Want multiple copies of a DLL to run... Ribbon Bar |
|||||||||||||||||||||||