Results 1 to 8 of 8

Thread: text editor saving problem

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    64

    text editor saving problem

    Hi guys

    I'm just in the process of writing a text editor and am having trouble working out why my program doesn't save files.
    Any chance that someone can look at my code and work out why it wont??
    Here is my code:

    Code:
    Imports system.Windows.Forms
    Imports System.IO
    
    Public Class form
    
        Private mFileName As String
        Private modified As Boolean
    
    
        Private Sub ToolbarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miViewToolBar.Click
            If (miViewToolBar.Checked = True) Then
                tbToolBar.Visible = True
            Else
                tbToolBar.Visible = False
            End If
    
    
        End Sub
    
        Private Sub BulletsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles miBulletToolBar.Click
            miBulletToolBar.Checked = Not miBulletToolBar.Checked
            If (miBulletToolBar.Checked = True) Then
                RtbEditor.SelectionBullet = True
            Else
                RtbEditor.SelectionBullet = False
            End If
        End Sub
    
        Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
            modification(sender, e)
            Clipboard.Clear()
            Application.Exit()
        End Sub
    
        Private Sub clearAlignment()
            LeftAlign.Checked = False
            Centered.Checked = False
            RightAlign.Checked = False
        End Sub
        Private Sub LeftAlignToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftAlign.Click
            clearAlignment()
            LeftAlign.Checked = Not LeftAlign.Checked
            If (LeftAlign.Checked = True) Then
                RtbEditor.SelectionAlignment = HorizontalAlignment.Left
            End If
        End Sub
    
        Private Sub Centered_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Centered.Click
            clearAlignment()
            Centered.Checked = Not Centered.Checked
            If (Centered.Checked = True) Then
                RtbEditor.SelectionAlignment = HorizontalAlignment.Center
            End If
        End Sub
    
        Private Sub RightAlign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightAlign.Click
            clearAlignment()
            RightAlign.Checked = Not Centered.Checked
            If (RightAlign.Checked = True) Then
                RtbEditor.SelectionAlignment = HorizontalAlignment.Right
            End If
        End Sub
        Private Sub MyPopupEventHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
            If (RtbEditor.SelectionAlignment = HorizontalAlignment.Center) Then
                Centered.Checked = True
            ElseIf (RtbEditor.SelectionAlignment = HorizontalAlignment.Left) Then
                LeftAlign.Checked = True
            Else
                RightAlign.Checked = True
            End If
    
        End Sub
    
        Private Sub New_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
            modification(sender, e)
            Clipboard.Clear()
            RtbEditor.Clear()
            mFileName = ""
            modified = False
            Me.Text = "WixsPad - Untitled"
        End Sub
    
    
        Private Sub Open_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
            modification(sender, e)
            New_click(sender, e)
            Dim isFileThere As DialogResult
            modified = False
            isFileThere = ofdFileOpen.ShowDialog()
            mFileName = ofdFileOpen.FileName
    
            Me.Text = "WixsPad - " & Path.GetFileName(mFileName)
            If (isFileThere = Windows.Forms.DialogResult.OK) Then
                RtbEditor.LoadFile(mFileName)
            End If
    
    
        End Sub
    
        Private Sub SaveAs_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveAsToolStripMenuItem.Click
            modified = False
            sfdFileSave.FileName = mFileName
            sfdFileSave.ShowDialog()
    
    
            If (Windows.Forms.DialogResult.OK) Then
                If (mFileName <> "") Then
                    mFileName = sfdFileSave.FileName
                    Me.Text = "WixsPad - " & Path.GetFileName(mFileName)
                    RtbEditor.SaveFile(mFileName)
                End If
            End If
        End Sub
    
        Private Sub Save_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
    
            modified = False
    
            If (mFileName = "") Then
                SaveAs_click(sender, e)
            Else
                RtbEditor.SaveFile(mFileName)
            End If
        End Sub
    
        Private Sub AboutWixsPadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutWixsPadToolStripMenuItem.Click
            AboutScreen.Show()
        End Sub
    
        Private Sub modified_TextChanged(ByVal sender As Object, _
                                         ByVal e As EventArgs) Handles RtbEditor.TextChanged
            modified = True
            If (modified = True) Then
                Me.Text = "WixsPad - " & Path.GetFileName(mFileName) & "  (Modified)"
            Else
                Me.Text = "WixsPad - " & Path.GetFileName(mFileName)
            End If
        End Sub
    
        Private Sub modification(ByVal sender As Object, ByVal e As EventArgs)
            If (modified = True) Then
                modifiedScreen.Show()
                modifiedScreen.Visible = False
                If (modifiedScreen.ShowDialog = Windows.Forms.DialogResult.OK) Then
                    Save_click(sender, e)
                End If
            End If
        End Sub
    
    
        Private Sub ParagraphToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParagraphToolStripMenuItem.Click
            indentation.ShowDialog()
            If (indentation.DialogResult = Windows.Forms.DialogResult.OK) Then
                RtbEditor.SelectionIndent = indentation.leftIndent.Text
                RtbEditor.SelectionRightIndent = indentation.rightIndent.Text
                RtbEditor.RightMargin = indentation.rightMargin.Text
            End If
        End Sub
    
        Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cut.Click
            RtbEditor.Cut()
        End Sub
    
        Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy.Click
            RtbEditor.Copy()
        End Sub
    
        Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Paste.Click
            RtbEditor.Paste()
        End Sub
    
        Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAll.Click
            RtbEditor.SelectAll()
        End Sub
    
        Private Sub Edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Edit.Click
    
            If RtbEditor.SelectionLength > 0 Then
                Cut.Enabled = True
                Copy.Enabled = True
            End If
            If Clipboard.ContainsText Then
                Paste.Enabled = True
            End If
            If RtbEditor.TextLength > 0 Then
                SelectAll.Enabled = True
            End If
        End Sub
    
        Private Sub toolNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolNew.Click
            New_click(sender, e)
        End Sub
    
        Private Sub toolOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolOpen.Click
            Open_click(sender, e)
        End Sub
    
        Private Sub toolSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolSave.Click
            Save_click(sender, e)
        End Sub
    
        Private Sub toolBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolBold.Click
            toolBold.CheckOnClick = True
            RtbEditor.SelectionFont = New Font(RtbEditor.SelectionFont, RtbEditor.SelectionFont.Style Xor FontStyle.Bold)
        End Sub
    
        Private Sub toolItalics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolItalics.Click
            toolItalics.CheckOnClick = True
            RtbEditor.SelectionFont = New Font(RtbEditor.SelectionFont.Name, RtbEditor.SelectionFont.Size, RtbEditor.SelectionFont.Style Xor FontStyle.Italic)
        End Sub
    
        Private Sub toolUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolUnderline.Click
            toolUnderline.CheckOnClick = True
            RtbEditor.SelectionFont = New Font(RtbEditor.SelectionFont.Name, RtbEditor.SelectionFont.Size, RtbEditor.SelectionFont.Style Xor FontStyle.Underline)
        End Sub
    
        Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
            fontDialog.ShowDialog()
            RtbEditor.SelectionFont = fontDialog.Font
        End Sub
    
        Private Sub OptionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
            options.ShowDialog()
            If (options.DialogResult = Windows.Forms.DialogResult.OK) Then
                If (options.tabs.Checked = True) Then
                    RtbEditor.AcceptsTab = True
                End If
                If (options.returns.Checked = True) Then
                    RtbEditor.Multiline = True
                End If
                If (options.wraps.Checked = True) Then
                    RtbEditor.WordWrap = True
                End If
    
            End If
        End Sub
    End Class
    Thanks heaps guys....

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    64

    Re: text editor saving problem

    Also getting the same exception when opening a file.

    It's saying that the file format is not valid.

    The annoying thing is that it was working before i added a lot of other functionality.

  3. #3
    Banned
    Join Date
    Dec 2006
    Location
    India
    Posts
    89

    Re: text editor saving problem

    Quote Originally Posted by wixsas
    Also getting the same exception when opening a file.

    It's saying that the file format is not valid.

    The annoying thing is that it was working before i added a lot of other functionality.
    Oh ya even for opening files its
    Code:
    RtbEditor.LoadFile(OpenFileDialog.FileName, _
                                    RichTextBoxStreamType.PlainText)
    Sure man Your code really helped me out I just posted a topic asking about saving files that have already been saved and are modified
    Cool

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    64

    Re: text editor saving problem

    Nah no go mate. Did the same thing as my current code.
    I can't understand what i would have changed that would stop it from working.
    The only thing i've added to those methods is modified = true/false but i wouldnt have thought that would change it.

  5. #5
    Banned
    Join Date
    Dec 2006
    Location
    India
    Posts
    89

    Re: text editor saving problem

    Quote Originally Posted by wixsas
    Nah no go mate. Did the same thing as my current code.
    I can't understand what i would have changed that would stop it from working.
    The only thing i've added to those methods is modified = true/false but i wouldnt have thought that would change it.
    I think try and remove that mine is working fine without that modified thing there should be another way to it(checking if its modified).
    Im on it i asked in the other post let me see what happens

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    64

    Re: text editor saving problem

    i gtg to bed neway mate...
    Thanks for ur help
    Cheers

  7. #7
    Banned
    Join Date
    Dec 2006
    Location
    India
    Posts
    89

    Re: text editor saving problem

    hi man even Im creating a text editor but an mdi one anyway the problem is ur not saving as the stream u have to save stuff like this
    If RtbEditor is your richtextbox then
    Code:
    RtbEditor.SaveFile(SaveFileDialog.FileName, _
                                            RichTextBoxStreamType.PlainText)

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