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. StreamReader to RichTextBox problems

StreamReader to RichTextBox problems

Scheduled Pinned Locked Moved Visual Basic
help
4 Posts 2 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

    Ok so I have TabControl and dynamically created TabPage with dynamically created RichTextBox. I am trying to use a OpenFileDialog to open a .rtf in a new TabPage in a new RichTextBox and read the selected rtf file into it. Here is the code that I am using. Somewhat new so feel free to show me better ways of doing what I am trying to do. Dim sr As StreamReader Try With OpenFileDialog1 If .ShowDialog = Windows.Forms.DialogResult.OK Then If .FileName.EndsWith(".rtf") Then 'Declare new object variables Dim rtbTextArea As New RichTextBox Dim newTab As New TabPage TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control With newTab .Text = OpenFileDialog1.FileName .Controls.Add(rtbTextArea) 'Add the rich text Box to the new tab control rtbTextArea.Dock = DockStyle.Fill 'Set Rich Text box area to fill tab page .Focus() End With For Each ctl As Control In TabControl1.SelectedTab.Controls 'Find RichTextBox control If TypeOf ctl Is RichTextBox Then sr = New StreamReader("" & .FileName & "") ctl.Text = sr.ReadToEnd End If Next Else MessageBox.Show("Please choose a Rich Text File (.rtf)") End If End If End With Catch ex As Exception MessageBox.Show(MessageBoxIcon.Exclamation, "An error has occured. Please make your selections again") Finally If Not (sr Is Nothing) Then sr.Close() End If End Try Thanks, Taen Karth -- modified at 21:47 Friday 2nd September, 2005

    R 1 Reply Last reply
    0
    • T Taen_Karth

      Ok so I have TabControl and dynamically created TabPage with dynamically created RichTextBox. I am trying to use a OpenFileDialog to open a .rtf in a new TabPage in a new RichTextBox and read the selected rtf file into it. Here is the code that I am using. Somewhat new so feel free to show me better ways of doing what I am trying to do. Dim sr As StreamReader Try With OpenFileDialog1 If .ShowDialog = Windows.Forms.DialogResult.OK Then If .FileName.EndsWith(".rtf") Then 'Declare new object variables Dim rtbTextArea As New RichTextBox Dim newTab As New TabPage TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control With newTab .Text = OpenFileDialog1.FileName .Controls.Add(rtbTextArea) 'Add the rich text Box to the new tab control rtbTextArea.Dock = DockStyle.Fill 'Set Rich Text box area to fill tab page .Focus() End With For Each ctl As Control In TabControl1.SelectedTab.Controls 'Find RichTextBox control If TypeOf ctl Is RichTextBox Then sr = New StreamReader("" & .FileName & "") ctl.Text = sr.ReadToEnd End If Next Else MessageBox.Show("Please choose a Rich Text File (.rtf)") End If End If End With Catch ex As Exception MessageBox.Show(MessageBoxIcon.Exclamation, "An error has occured. Please make your selections again") Finally If Not (sr Is Nothing) Then sr.Close() End If End Try Thanks, Taen Karth -- modified at 21:47 Friday 2nd September, 2005

      R Offline
      R Offline
      rudy net
      wrote on last edited by
      #2

      What is your question?

      T 1 Reply Last reply
      0
      • R rudy net

        What is your question?

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

        Ha, I forgot to add the question didn't I. Here goes...When I use the code above the text that was read is displayed in the wrong tab. Not sure why... Thanks, Taen Karth -- modified at 4:38 Saturday 3rd September, 2005

        T 1 Reply Last reply
        0
        • T Taen_Karth

          Ha, I forgot to add the question didn't I. Here goes...When I use the code above the text that was read is displayed in the wrong tab. Not sure why... Thanks, Taen Karth -- modified at 4:38 Saturday 3rd September, 2005

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

          Nevermind I figured it out. I added

          TabControl1.SelectedTab = newTab

          Right after

          TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control

          Thanks, Taen Karth

          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