CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #7
    Join Date
    Oct 2004
    Posts
    17

    Re: Reading A textFile to a LAbel

    I took this code from an application I have been working on, I believe its what your looking for.

    Each chapter/topic will need its own txt file, for instance Computer.txt.

    Create a new folder inside of the solution folder, titled Resoruces, then add all the .txt files there.

    Run the solution, go to Project \ Add Existing Item, choose files, then in properties window add them as Embedded.

    Tell me what you think.

    Chris




    =======================================================
    Public Class Form1
    Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents treeInformation As System.Windows.Forms.TreeView
    Friend WithEvents rtbInformation As System.Windows.Forms.RichTextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.treeInformation = New System.Windows.Forms.TreeView
    Me.rtbInformation = New System.Windows.Forms.RichTextBox
    Me.SuspendLayout()
    '
    'treeInformation
    '
    Me.treeInformation.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
    Me.treeInformation.ImageIndex = -1
    Me.treeInformation.Location = New System.Drawing.Point(0, 0)
    Me.treeInformation.Name = "treeInformation"
    Me.treeInformation.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Information1", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Example1"), New System.Windows.Forms.TreeNode("Example2"), New System.Windows.Forms.TreeNode("Example3")})})
    Me.treeInformation.SelectedImageIndex = -1
    Me.treeInformation.Size = New System.Drawing.Size(176, 392)
    Me.treeInformation.TabIndex = 0
    '
    'rtbInformation
    '
    Me.rtbInformation.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
    Or System.Windows.Forms.AnchorStyles.Left) _
    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
    Me.rtbInformation.Location = New System.Drawing.Point(176, 0)
    Me.rtbInformation.Name = "rtbInformation"
    Me.rtbInformation.Size = New System.Drawing.Size(384, 392)
    Me.rtbInformation.TabIndex = 1
    Me.rtbInformation.Text = "rtbInformation"
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(560, 389)
    Me.Controls.Add(Me.rtbInformation)
    Me.Controls.Add(Me.treeInformation)
    Me.Name = "Form1"
    Me.Text = "Information"
    Me.ResumeLayout(False)

    End Sub

    #End Region
    Function GetResourceContent(ByVal filename As String) As String
    ' get the current assembly
    Dim asm As System.Reflection.[Assembly] = _
    System.Reflection.[Assembly].GetExecutingAssembly()
    ' resources are named using a fully qualified name
    Dim strm As System.IO.Stream = asm.GetManifestResourceStream(asm.GetName().Name + "." + filename)
    ' read the contents of the embedded file
    Dim reader As New System.IO.StreamReader(strm)
    GetResourceContent = reader.ReadToEnd()
    reader.Close()
    End Function


    Private Sub treeInformation_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeInformation.AfterSelect
    rtbInformation.Text = GetResourceContent(treeInformation.SelectedNode.Text & ".txt")
    End Sub
    End Class
    Last edited by [email protected]; November 21st, 2004 at 01:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured