Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Dynamic Tab pages and Streamwriter

Dynamic Tab pages and Streamwriter

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taen_Karth
    wrote on last edited by
    #1

    The small app that I am developing is a simple form with a tab control on it. The form currently performs the following: On load it dynamically creates a TabPage and dynamically creates a RichTextBox inside that new TabPage. Their is a menu option and a context choivce that will create a new TabPage with a new RichTextBox inside the same TabControl. Here is the problem: When I use the SaveDialog I can save the first Tab that was created but I cannot seem to save the other tabs that I dynamically create. I think that the reason is that I use the same object names each time and I don't know how to differentiate between them. I have tried doing SelectedTab but then I don't know how to address a RichtextBox that is not there before runtime. Any ideas? Thanks, Taen Karth

    I 1 Reply Last reply
    0
    • T Taen_Karth

      The small app that I am developing is a simple form with a tab control on it. The form currently performs the following: On load it dynamically creates a TabPage and dynamically creates a RichTextBox inside that new TabPage. Their is a menu option and a context choivce that will create a new TabPage with a new RichTextBox inside the same TabControl. Here is the problem: When I use the SaveDialog I can save the first Tab that was created but I cannot seem to save the other tabs that I dynamically create. I think that the reason is that I use the same object names each time and I don't know how to differentiate between them. I have tried doing SelectedTab but then I don't know how to address a RichtextBox that is not there before runtime. Any ideas? Thanks, Taen Karth

      I Offline
      I Offline
      Icharus
      wrote on last edited by
      #2

      Try the following: For Each tabCtl As TabPage In TabControl1.TabPages For Each ctl As Control In tabCtl.Controls If TypeOf ctl Is RichTextBox Then ' Code to save the contents.... End If Next Next Hope this helps.

      T T 2 Replies Last reply
      0
      • I Icharus

        Try the following: For Each tabCtl As TabPage In TabControl1.TabPages For Each ctl As Control In tabCtl.Controls If TypeOf ctl Is RichTextBox Then ' Code to save the contents.... End If Next Next Hope this helps.

        T Offline
        T Offline
        taenkarth
        wrote on last edited by
        #3

        That sounds perfect. I have no clue why I did not think of that. I did all variations except that...lol. I will try when I get home and let you know. Thanks!! Taen Karth

        1 Reply Last reply
        0
        • I Icharus

          Try the following: For Each tabCtl As TabPage In TabControl1.TabPages For Each ctl As Control In tabCtl.Controls If TypeOf ctl Is RichTextBox Then ' Code to save the contents.... End If Next Next Hope this helps.

          T Offline
          T Offline
          Taen_Karth
          wrote on last edited by
          #4

          Excellent work. I was not able to use all of it as I did not want to save the text in a textboxes in all tabs rather only the selected tab. I was able to it as follows to save the text in only the selected tab. 'Declare private variables Dim strName As String = "NewNote" Dim sw As StreamWriter Dim FileName As String 'Start Save As event Try For Each ctl As Control In TabControl1.SelectedTab.Controls 'Find all controls on the selected tab page If TypeOf ctl Is RichTextBox Then 'Get the Rich Text Box 'Start the SaveFile Dialog event With sfdSaveAs .FileName = strName If .ShowDialog = Windows.Forms.DialogResult.OK Then 'If user clicks save then... FileName = .FileName sw = New StreamWriter(FileName) 'New stream Writer sw.NewLine = ControlChars.NewLine 'Set StreamWriter's New line to the newline character sw.Write(ctl.Text) 'Write CTL which is RichTextBox in selected tab End If End With End If Next Catch es As Exception 'If there is an error MessageBox.Show("An error has been encountered. Please try again.") Finally If Not (sw Is Nothing) Then 'If there is nothing to write then close the streamwriter sw.Close() End If End Try Thanks again, Taen Karth

          I 1 Reply Last reply
          0
          • T Taen_Karth

            Excellent work. I was not able to use all of it as I did not want to save the text in a textboxes in all tabs rather only the selected tab. I was able to it as follows to save the text in only the selected tab. 'Declare private variables Dim strName As String = "NewNote" Dim sw As StreamWriter Dim FileName As String 'Start Save As event Try For Each ctl As Control In TabControl1.SelectedTab.Controls 'Find all controls on the selected tab page If TypeOf ctl Is RichTextBox Then 'Get the Rich Text Box 'Start the SaveFile Dialog event With sfdSaveAs .FileName = strName If .ShowDialog = Windows.Forms.DialogResult.OK Then 'If user clicks save then... FileName = .FileName sw = New StreamWriter(FileName) 'New stream Writer sw.NewLine = ControlChars.NewLine 'Set StreamWriter's New line to the newline character sw.Write(ctl.Text) 'Write CTL which is RichTextBox in selected tab End If End With End If Next Catch es As Exception 'If there is an error MessageBox.Show("An error has been encountered. Please try again.") Finally If Not (sw Is Nothing) Then 'If there is nothing to write then close the streamwriter sw.Close() End If End Try Thanks again, Taen Karth

            I Offline
            I Offline
            Icharus
            wrote on last edited by
            #5

            Looks good. I'm just glad to have been of some guidance.:) What exactly are you building, if you don't mind my asking? I sounds like a Notepad substitute, if it is, I like the tabbed approach.

            T 1 Reply Last reply
            0
            • I Icharus

              Looks good. I'm just glad to have been of some guidance.:) What exactly are you building, if you don't mind my asking? I sounds like a Notepad substitute, if it is, I like the tabbed approach.

              T Offline
              T Offline
              Taen_Karth
              wrote on last edited by
              #6

              That is exactly what I am building. I work in a firm where I have to take lots of phnoe calls and remember lots of little side notes. I am using this to build a Notepad Substitute. Each new tab will have a time and date stamp on the top of the tab so that I know when I jotted in it. I will also be able to save each tab individually and set the opacity so that I can compare with stuff behind it without having to switch back and forth. I am using VS.NET 2005 Beta to develope it so You have to download the new .NET Framework 2.0.?? beta as well to run the apps. If you are interested I will send you the source so you can peruse it. I will put it up on some free site when I am done as well if you would rather wait. Thanks again for the tips, Taen Karth

              I 1 Reply Last reply
              0
              • T Taen_Karth

                That is exactly what I am building. I work in a firm where I have to take lots of phnoe calls and remember lots of little side notes. I am using this to build a Notepad Substitute. Each new tab will have a time and date stamp on the top of the tab so that I know when I jotted in it. I will also be able to save each tab individually and set the opacity so that I can compare with stuff behind it without having to switch back and forth. I am using VS.NET 2005 Beta to develope it so You have to download the new .NET Framework 2.0.?? beta as well to run the apps. If you are interested I will send you the source so you can peruse it. I will put it up on some free site when I am done as well if you would rather wait. Thanks again for the tips, Taen Karth

                I Offline
                I Offline
                Icharus
                wrote on last edited by
                #7

                Yes I'd love to see what you have so far, and maybe I can be of some assistance. I'm always looking for new challenges. Also, I have been looking for an excuse to use VS.Net 2005, but I have been a bit lazy and out of ideas. (Too many brain cells used at my real job. lol)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups