Fileopendialog

mourya

Member
Joined
Feb 18, 2006
Messages
8
Programming Experience
Beginner
HI friends,

I want to design a button, which when clicked shud navigate the text files in the system and when selected should be copied to Richtextbox.I have tried this sample code from .NET documentation but didnt worked

VB.NET:
Public Sub LoadMyFile()
    ' Create an OpenFileDialog to request a file to open.
    Dim openFile1 As New OpenFileDialog()
    
    ' Initialize the OpenFileDialog to look for RTF files.
    openFile1.DefaultExt = "*.txt
    openFile1.Filter = "TXT files|*.txt"
    
    ' Determine whether the user selected a file from the OpenFileDialog.
    If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
        And (openFile1.FileName.Length > 0) Then
        
        ' Load the contents of the file into the RichTextBox.
        richTextBox1.LoadFile(openFile1.FileName, _
            RichTextBoxStreamType.PlainText)
    End If
End Sub

So, plz help me with a better code
 
Ok i got it
VB.NET:
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 OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
        Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'RichTextBox1
        '
        Me.RichTextBox1.Location = New System.Drawing.Point(8, 24)
        Me.RichTextBox1.Name = "RichTextBox1"
        Me.RichTextBox1.Size = New System.Drawing.Size(272, 200)
        Me.RichTextBox1.TabIndex = 1
        Me.RichTextBox1.Text = ""
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(16, 240)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "Stop"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.RichTextBox1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
#End Region
   
    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
        Dim openFile1 As New OpenFileDialog()
        Dim s As New SpeechLib.SpVoice()
        openFile1.DefaultExt = "*.txt"
        openFile1.ShowDialog()
        openFile1.Filter = "TXT Files|*.txt"
        RichTextBox1.LoadFile(openFile1.FileName, _
        RichTextBoxStreamType.PlainText)
        s.Speak(RichTextBox1.Text)
        s.GetVoices()

    End Sub
 
 
End Class
 
change:
VB.NET:
    Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
        Dim openFile1 As New OpenFileDialog()
        Dim s As New SpeechLib.SpVoice()
        openFile1.DefaultExt = "*.txt"
        openFile1.ShowDialog()
        openFile1.Filter = "TXT Files|*.txt"
        RichTextBox1.LoadFile(openFile1.FileName, _
        RichTextBoxStreamType.PlainText)
        s.Speak(RichTextBox1.Text)
        s.GetVoices()

    End Sub
To:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim openFile1 As New OpenFileDialog()
  Dim s As New SpeechLib.SpVoice()
  With openFile1
    .DefaultExt = "*.txt"
    .Filter = "TXT Files|*.txt"
    If .ShowDialog() <> DialogResult.Cancel Then
    RichTextBox1.LoadFile(.FileName, RichTextBoxStreamType.PlainText)
    s.Speak(RichTextBox1.Text)
    s.GetVoices()
  End With
End Sub
 
mourya said:
Sir,
Thanks for your edited code regarding the TTS http://vbdotnetforums.com/showthread.php?p=28278

Now i would like to add few modifications to that like,
Pause button,Volume Changer,Voice Changer.Please Guide me

I'm not familiar with the code for the actual changing of volume or pausing and whatnot

but to provide that kind of functionality all you have to do is add more buttons to the form, then double click on each button to code the click event

for example add a button to the form and in the properties window change the Name to "btnVolumeUp" and change the Text to "Volume Up"
now double click on the button and this is where the code to increase the volume goes
 
Back
Top