Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to use a tabControl for TextPad like tabbed documents?

Posted on 2005-04-08
38
Medium Priority
?
362 Views
Last Modified: 2008-03-03
I have a windows App that is somewhat like NotePad or TextPad.  What I want to do is have the first document be on tab 1 and the second on tab 2 and so forth.  I added a tabControl and one page to my app.  On this page I added my richText box.  I have a toolbar at the top with buttons that allow me to open and save a file, bold, underline and italicize, and also a tab button that will create another tab.
When the new tab button is clicked it shows a new tab but now my RichTextBox is gone.  

How do I make it so the rich text box shows on all tabs?  
I want to be able to open a different document on each tab.

Maybe I need to have my RichTextBox not on my tabControl but below.
I can post my code if anyone needs it.
0
Comment
Question by:jettman26
  • 19
  • 19
38 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13740972
well you could either have one instance of a RTB control and keep changing the contents when you switch between documents (having to store contents elsewhere)   or one instance for each tabpage...

where's the code where you add the tabpage open opening/creating a new document  (so we know where to insert any extra code)
0
 

Author Comment

by:jettman26
ID: 13741292
Here is the code of my toolbar, a SaveAs procedure and a print procedure.  This has most of the code for my app.  Case 11 is to add tabs.  Hopefully the comments will help.


Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        ' Print the content of the RichTextBox. Store the last character printed.
        checkPrint = RichTextBoxPrintCtrl1.Print(checkPrint, RichTextBoxPrintCtrl1.TextLength, e)

        ' Look for more pages
        If checkPrint < RichTextBoxPrintCtrl1.TextLength Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

    Private Sub SaveAs()
        SaveFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
        If SaveFileDialog1.ShowDialog = DialogResult.OK Then
            Try
                RichTextBoxPrintCtrl1.SaveFile(SaveFileDialog1.FileName)
                'Displays file name in Label1
                Dim filename As String = Path.GetFileName(SaveFileDialog1.FileName)
                Label1.Text = filename
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub


    Private Sub ToolBar1_ButtonClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case 0
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        RichTextBoxPrintCtrl1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
                        'Displays file name in Label1
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)
                        Label1.Text = filename
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If

            Case 1
                'Save
                If File.Exists(OpenFileDialog1.FileName) Then
                    Try
                        RichTextBoxPrintCtrl1.SaveFile(OpenFileDialog1.FileName)
                        'Displays file name in Label1
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)
                        Label1.Text = filename
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    End Try
                ElseIf File.Exists(SaveFileDialog1.FileName) Then
                    Try
                        RichTextBoxPrintCtrl1.SaveFile(SaveFileDialog1.FileName)
                        'Displays file name in Label1
                        Dim filename As String = Path.GetFileName(SaveFileDialog1.FileName)
                        Label1.Text = filename
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    End Try
                Else
                    SaveAs()
                End If

            Case 2
                'Save As
                SaveAs()

            Case 3
                'Bold
                If e.Button.Pushed = True Then
                    If RichTextBoxPrintCtrl1.SelectionFont.Underline = True Then
                        If RichTextBoxPrintCtrl1.SelectionFont.Italic = False Then
                            Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Underline)
                            RichTextBoxPrintCtrl1.SelectionFont = fontbold
                        Else
                            Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Underline + FontStyle.Italic)
                            RichTextBoxPrintCtrl1.SelectionFont = fontbold
                        End If
                    ElseIf RichTextBoxPrintCtrl1.SelectionFont.Italic = True Then
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Italic)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    Else
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    End If
                ElseIf RichTextBoxPrintCtrl1.SelectionFont.Underline = True Then
                    If RichTextBoxPrintCtrl1.SelectionFont.Italic = False Then
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Underline)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    Else
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Underline + FontStyle.Italic)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    End If
                ElseIf RichTextBoxPrintCtrl1.SelectionFont.Italic = True Then
                    Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Italic)
                    RichTextBoxPrintCtrl1.SelectionFont = fontbold
                Else
                    Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Regular)
                    RichTextBoxPrintCtrl1.SelectionFont = fontbold
                End If

            Case 4
                'Underline
                If e.Button.Pushed = True Then
                    If RichTextBoxPrintCtrl1.SelectionFont.Bold = True Then
                        If RichTextBoxPrintCtrl1.SelectionFont.Italic = False Then
                            Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Underline)
                            RichTextBoxPrintCtrl1.SelectionFont = fontbold
                        Else
                            Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Underline + FontStyle.Italic)
                            RichTextBoxPrintCtrl1.SelectionFont = fontbold
                        End If
                    ElseIf RichTextBoxPrintCtrl1.SelectionFont.Italic = True Then
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Underline + FontStyle.Italic)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    Else
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Underline)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    End If

                ElseIf RichTextBoxPrintCtrl1.SelectionFont.Bold = True Then
                    If RichTextBoxPrintCtrl1.SelectionFont.Italic = False Then
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    Else
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Italic)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    End If
                ElseIf RichTextBoxPrintCtrl1.SelectionFont.Italic = True Then
                    Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Italic)
                    RichTextBoxPrintCtrl1.SelectionFont = fontbold
                Else
                    Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Regular)
                    RichTextBoxPrintCtrl1.SelectionFont = fontbold
                End If

            Case 5
                'Italics
                If e.Button.Pushed = True Then
                    If RichTextBoxPrintCtrl1.SelectionFont.Underline = True Then
                        If RichTextBoxPrintCtrl1.SelectionFont.Bold = False Then
                            Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Italic + FontStyle.Underline)
                            RichTextBoxPrintCtrl1.SelectionFont = fontbold
                        Else
                            Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Underline + FontStyle.Italic)
                            RichTextBoxPrintCtrl1.SelectionFont = fontbold
                        End If
                    ElseIf RichTextBoxPrintCtrl1.SelectionFont.Bold = True Then
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold + FontStyle.Italic)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    Else
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Italic)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    End If
                ElseIf RichTextBoxPrintCtrl1.SelectionFont.Underline = True Then
                    If RichTextBoxPrintCtrl1.SelectionFont.Bold = False Then
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Underline)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    Else
                        Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Underline + FontStyle.Bold)
                        RichTextBoxPrintCtrl1.SelectionFont = fontbold
                    End If
                ElseIf RichTextBoxPrintCtrl1.SelectionFont.Bold = True Then
                    Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Bold)
                    RichTextBoxPrintCtrl1.SelectionFont = fontbold
                Else
                    Dim fontbold As New Font(RichTextBoxPrintCtrl1.Font, FontStyle.Regular)
                    RichTextBoxPrintCtrl1.SelectionFont = fontbold
                End If

            Case 6
                'Page Setup
                PageSetupDialog1.ShowDialog()

            Case 7
                'Print Preview
                PrintPreviewDialog1.ShowDialog()

            Case 8
                'Print
                If PrintDialog1.ShowDialog() = DialogResult.OK Then
                    PrintDocument1.Print()
                End If
            Case 9
                'Close Program
                MySettings.SaveSetting("Width", Me.Width)
                MySettings.SaveSetting("Height", Me.Height)
                MySettings.SaveSetting("Left", Me.Left)
                MySettings.SaveSetting("Top", Me.Top)

                NotifyIcon1.Visible = False
                End
            Case 10
                If e.Button.Pushed = True Then
                    Me.TopMost = True
                Else
                    Me.TopMost = False
                End If

            Case 11
                'Add new Tabs
                Dim myTabPage As New TabPage
                myTabPage.Text = "TabPage" & (TabControl1.TabPages.Count + 1)
                TabControl1.TabPages.Add(myTabPage)

        End Select
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13741870
ok....  first of all... there's going to be more than one instance of a RTB control.... so most of the toolbar buttons will want to apply to the topmost RTB... which is  the RTB in the selected tabpage.

you need to replace all instances of RichTextBoxPrintCtrl1   With     selectedRTB      (also put error checking in for when selectedRTB Is nothing   i.e. when there are no tabs)

==========================

Now... the updated toolbuttons (only putting in important ones ive changed.... might suggest making a backup of ur old project at this point)

            Case 0
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)
                        NewTabWithRTB(filename)
                        selectedRTB.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
                        Label1.Text = filename
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If


            Case 3, 4, 5
                'Style change
                SetCurrentStyle(ToolBar1.Buttons(3).Pushed, ToolBar1.Buttons(4).Pushed, ToolBar1.Buttons(5).Pushed)


            Case 11
                'Add new Tabs
                NewTabWithRTB()


=====================

The new methods:

    Private TabCounter As Integer = 1
    Dim selectedRTB As RichTextBox = Nothing

    Private Sub NewTabWithRTB(Optional ByVal NewText As String = "")
        Dim myTabPage As New TabPage
        Dim myRTB As New RichTextBox
        selectedRTB = myRTB
        myTabPage.Controls.Add(myRTB)

        TabControl1.TabPages.Add(myTabPage)

        myRTB.Left = 10
        myRTB.Top = 10
        myRTB.Width = myTabPage.Width - 20
        myRTB.Height = myTabPage.Height - 20
        myRTB.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
        If NewText = "" Then
            myTabPage.Text = "TabPage" & (TabCounter)
        Else
            myTabPage.Text = NewText
        End If
        TabCounter += 1
        TabControl1.SelectedTab = myTabPage
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.TabCount >= 1 Then
            Dim thisTab As TabPage = TabControl1.SelectedTab
            If Not thisTab Is Nothing Then
                selectedRTB = thisTab.Controls(0)

            End If
        Else
            selectedRTB = Nothing
        End If
    End Sub

    Private Sub SetCurrentStyle(ByVal NewBold As Boolean, ByVal NewUnderline As Boolean, ByVal NewItalic As Boolean)
        Dim newStyle As New FontStyle
        If NewBold Then newStyle = newStyle + FontStyle.Bold
        If NewUnderline Then newStyle = newStyle + FontStyle.Underline
        If NewItalic Then newStyle = newStyle + FontStyle.Italic

        If Not NewBold And Not NewUnderline And Not NewItalic Then newStyle = FontStyle.Regular

        If selectedRTB Is Nothing Then
            'do nothing
        Else
            Dim newFont As New Font(selectedRTB.Font, newStyle)
            selectedRTB.SelectionFont = newFont
        End If
    End Sub

========================

let me know of any probs.... i tried to keep it as close as to your program as possible
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jettman26
ID: 13742237
I should probably mention the the RichTextBox is a class that I got from somewhere on this site that allows you to print Rich Text.  Not sure if this matters.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13742245
shouldn't be a problem...
0
 

Author Comment

by:jettman26
ID: 13742291
I get the following error when I try to run the program.

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid values.

THIS HAPPENS ON THIS LINE:
selectedRTB = thisTab.Controls(0)
OF THIS SUBPROCEDURE
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13742300
are you adding tabs any other way ie. not using the   NewTabWithRTB   method
0
 

Author Comment

by:jettman26
ID: 13742318
No, but I think the problem is with selected RTB.  I can't replace all the instances of RichTextBoxPrintCtrl1 with selectedRTB.  I get
 C:\Documents and Settings\Server\My Documents\Visual Studio Projects\Copy of DesktopApp\Form1.vb(388): 'Print' is not a member of 'System.Windows.Forms.RichTextBox'.  
I think my RichTextBoxPrintCtrl1 class is causing a problem.
0
 

Author Comment

by:jettman26
ID: 13742324
If you want I can post a link to my code files.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13742329
please... or just post all the code up in here (including form designer code)... and I can create project that mimics yours
0
 

Author Comment

by:jettman26
ID: 13742355
0
 

Author Comment

by:jettman26
ID: 13742366
here is the code to my RichTextBoxPrintCtrl1.

I got it from this link:

http://support.microsoft.com/kb/811401/EN-US/
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13742487
make a backup of your project...

(you may get an error about a reference at some point... we'll correct it if needs be)

open up your form and replace all form code with the following:

Imports System.IO
Imports System.Drawing.Printing

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 NotifyIcon1 As System.Windows.Forms.NotifyIcon
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
    Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
    Friend WithEvents PageSetupDialog1 As System.Windows.Forms.PageSetupDialog
    Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
    Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
    Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton6 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton8 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton9 As System.Windows.Forms.ToolBarButton
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents ToolBarButton10 As System.Windows.Forms.ToolBarButton
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    Friend WithEvents ToolBarButton11 As System.Windows.Forms.ToolBarButton
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ToolBarButton7 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton12 As System.Windows.Forms.ToolBarButton
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
        Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
        Me.PageSetupDialog1 = New System.Windows.Forms.PageSetupDialog
        Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
        Me.ToolBar1 = New System.Windows.Forms.ToolBar
        Me.ToolBarButton10 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton8 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton11 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton6 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton9 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton7 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton12 = New System.Windows.Forms.ToolBarButton
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.Label1 = New System.Windows.Forms.Label
        Me.TabControl1 = New System.Windows.Forms.TabControl
        Me.SuspendLayout()
        '
        'NotifyIcon1
        '
        Me.NotifyIcon1.ContextMenu = Me.ContextMenu1
        Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"), System.Drawing.Icon)
        Me.NotifyIcon1.Text = "DesktopApp"
        Me.NotifyIcon1.Visible = True
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.Text = "Exit"
        '
        'PrintDialog1
        '
        Me.PrintDialog1.Document = Me.PrintDocument1
        '
        'PrintDocument1
        '
        '
        'PageSetupDialog1
        '
        Me.PageSetupDialog1.Document = Me.PrintDocument1
        '
        'PrintPreviewDialog1
        '
        Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
        Me.PrintPreviewDialog1.Document = Me.PrintDocument1
        Me.PrintPreviewDialog1.Enabled = True
        Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
        Me.PrintPreviewDialog1.Location = New System.Drawing.Point(39, 56)
        Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
        Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
        Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
        Me.PrintPreviewDialog1.Visible = False
        '
        'ToolBar1
        '
        Me.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
        Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton10, Me.ToolBarButton8, Me.ToolBarButton11, Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, Me.ToolBarButton5, Me.ToolBarButton6, Me.ToolBarButton9, Me.ToolBarButton7, Me.ToolBarButton12})
        Me.ToolBar1.Divider = False
        Me.ToolBar1.DropDownArrows = True
        Me.ToolBar1.ImageList = Me.ImageList1
        Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
        Me.ToolBar1.Name = "ToolBar1"
        Me.ToolBar1.ShowToolTips = True
        Me.ToolBar1.Size = New System.Drawing.Size(792, 26)
        Me.ToolBar1.TabIndex = 8
        Me.ToolBar1.Wrappable = False
        '
        'ToolBarButton10
        '
        Me.ToolBarButton10.ImageIndex = 9
        Me.ToolBarButton10.ToolTipText = "Open File"
        '
        'ToolBarButton8
        '
        Me.ToolBarButton8.ImageIndex = 3
        Me.ToolBarButton8.ToolTipText = "Save"
        '
        'ToolBarButton11
        '
        Me.ToolBarButton11.ImageIndex = 10
        Me.ToolBarButton11.ToolTipText = "Save As"
        '
        'ToolBarButton1
        '
        Me.ToolBarButton1.ImageIndex = 0
        Me.ToolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton1.ToolTipText = "Bold"
        '
        'ToolBarButton2
        '
        Me.ToolBarButton2.ImageIndex = 1
        Me.ToolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton2.ToolTipText = "Underline"
        '
        'ToolBarButton3
        '
        Me.ToolBarButton3.ImageIndex = 5
        Me.ToolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton3.ToolTipText = "Italicize"
        '
        'ToolBarButton4
        '
        Me.ToolBarButton4.ImageIndex = 7
        Me.ToolBarButton4.ToolTipText = "Page Setup"
        '
        'ToolBarButton5
        '
        Me.ToolBarButton5.ImageIndex = 6
        Me.ToolBarButton5.ToolTipText = "Print Preview"
        '
        'ToolBarButton6
        '
        Me.ToolBarButton6.ImageIndex = 2
        Me.ToolBarButton6.ToolTipText = "Print"
        '
        'ToolBarButton9
        '
        Me.ToolBarButton9.ImageIndex = 8
        Me.ToolBarButton9.ToolTipText = "Close"
        '
        'ToolBarButton7
        '
        Me.ToolBarButton7.ImageIndex = 11
        Me.ToolBarButton7.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton7.ToolTipText = "Always on Top"
        '
        'ToolBarButton12
        '
        Me.ToolBarButton12.ImageIndex = 12
        '
        'ImageList1
        '
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'Label1
        '
        Me.Label1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(156, 614)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(480, 24)
        Me.Label1.TabIndex = 10
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TabControl1
        '
        Me.TabControl1.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.TabControl1.Location = New System.Drawing.Point(0, 24)
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(800, 582)
        Me.TabControl1.TabIndex = 11
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(792, 646)
        Me.ControlBox = False
        Me.Controls.Add(Me.TabControl1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ToolBar1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
        Me.Location = New System.Drawing.Point(500, 0)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "DesktopApp"
        Me.ResumeLayout(False)

    End Sub

#End Region


    'Private PrintPageSettings As New PageSettings
    'Private StringToPrint As String
    'Private PrintFont As New Font("Arial", 10)

    Private checkPrint As Integer
    Dim MySettings As New clsAppSettings(Application.StartupPath & "\Test.Config")


    Dim activeRTB As RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl

    Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
        checkPrint = 0
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim width As Integer = Screen.PrimaryScreen.Bounds.Width
        'Me.Location = New System.Drawing.Point(Screen.PrimaryScreen.Bounds.Width - Me.Width, 0)
        If MySettings.GetSetting("Width") >= 376 Then
            Me.Width = MySettings.GetSetting("Width")
        End If
        If MySettings.GetSetting("Height") >= 300 Then
            Me.Height = MySettings.GetSetting("Height")
        End If
        If MySettings.GetSetting("Left") > 0 Then
            If MySettings.GetSetting("Left") < Screen.PrimaryScreen.Bounds.Width Then
                Me.Left = MySettings.GetSetting("Left")
            End If
        End If

        If MySettings.GetSetting("Top") > 0 Then
            If MySettings.GetSetting("Top") < Screen.PrimaryScreen.Bounds.Height Then
                Me.Top = MySettings.GetSetting("Top")
            End If
        End If
    End Sub

    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
        Me.Activate()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        ' Print the content of the RichTextBox. Store the last character printed.
        checkPrint = activeRTB.Print(checkPrint, activeRTB.TextLength, e)

        ' Look for more pages
        If checkPrint < activeRTB.TextLength Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

    Private Sub SaveAs()
        SaveFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
        If SaveFileDialog1.ShowDialog = DialogResult.OK Then
            Try
                activeRTB.SaveFile(SaveFileDialog1.FileName)
                'Displays file name in Label1
                Dim filename As String = Path.GetFileName(SaveFileDialog1.FileName)
                Label1.Text = filename
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub


    Private Sub ToolBar1_ButtonClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case 0
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)

                        NewTabWithRTB(filename)

                        activeRTB.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
                        'Displays file name in Label1
                        Label1.Text = filename
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If

            Case 1
                'Save
                If File.Exists(OpenFileDialog1.FileName) Then
                    Try
                        activeRTB.SaveFile(OpenFileDialog1.FileName)
                        'Displays file name in Label1
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)
                        Label1.Text = filename
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    End Try
                ElseIf File.Exists(SaveFileDialog1.FileName) Then
                    Try
                        activeRTB.SaveFile(SaveFileDialog1.FileName)
                        'Displays file name in Label1
                        Dim filename As String = Path.GetFileName(SaveFileDialog1.FileName)
                        Label1.Text = filename
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    End Try
                Else
                    SaveAs()
                End If

            Case 2
                'Save As
                SaveAs()

            Case 3, 4, 5
                'Style change
                SetCurrentStyle(ToolBar1.Buttons(3).Pushed, ToolBar1.Buttons(4).Pushed, ToolBar1.Buttons(5).Pushed)

            Case 6
                'Page Setup
                PageSetupDialog1.ShowDialog()

            Case 7
                'Print Preview
                PrintPreviewDialog1.ShowDialog()

            Case 8
                'Print
                If PrintDialog1.ShowDialog() = DialogResult.OK Then
                    PrintDocument1.Print()
                End If
            Case 9
                'Close Program
                MySettings.SaveSetting("Width", Me.Width)
                MySettings.SaveSetting("Height", Me.Height)
                MySettings.SaveSetting("Left", Me.Left)
                MySettings.SaveSetting("Top", Me.Top)

                NotifyIcon1.Visible = False
                End
            Case 10
                If e.Button.Pushed = True Then
                    Me.TopMost = True
                Else
                    Me.TopMost = False
                End If

            Case 11
                'Add new Tabs
               NewTabWithRTB()

        End Select


    End Sub

    Private Sub ContextMenu1_Popup_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup

    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        MySettings.SaveSetting("Width", Me.Width)
        MySettings.SaveSetting("Height", Me.Height)
        MySettings.SaveSetting("Left", Me.Left)
        MySettings.SaveSetting("Top", Me.Top)
        NotifyIcon1.Visible = False
        End
    End Sub


    Private TabCounter As Integer = 1

    Private Sub NewTabWithRTB(Optional ByVal NewText As String = "")
        Dim myTabPage As New TabPage
        Dim myRTB As New RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
        activeRTB = myRTB
        myTabPage.Controls.Add(myRTB)

        TabControl1.TabPages.Add(myTabPage)

        myRTB.Left = 10
        myRTB.Top = 10
        myRTB.Width = myTabPage.Width - 20
        myRTB.Height = myTabPage.Height - 20
        myRTB.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
        If NewText = "" Then
            myTabPage.Text = "TabPage" & (TabCounter)
        Else
            myTabPage.Text = NewText
        End If
        TabCounter += 1
        TabControl1.SelectedTab = myTabPage
    End Sub



    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.TabCount >= 1 Then
            Dim thisTab As TabPage = TabControl1.SelectedTab
            If Not thisTab Is Nothing Then
                activeRTB = thisTab.Controls(0)

            End If
        Else
            activeRTB = Nothing
        End If
    End Sub

    Private Sub SetCurrentStyle(ByVal NewBold As Boolean, ByVal NewUnderline As Boolean, ByVal NewItalic As Boolean)
        Dim newStyle As New FontStyle
        If NewBold Then newStyle = newStyle + FontStyle.Bold
        If NewUnderline Then newStyle = newStyle + FontStyle.Underline
        If NewItalic Then newStyle = newStyle + FontStyle.Italic

        If Not NewBold And Not NewUnderline And Not NewItalic Then newStyle = FontStyle.Regular

        If activeRTB Is Nothing Then
            'do nothing
        Else
            Dim newFont As New Font(activeRTB.Font, newStyle)
            activeRTB.SelectionFont = newFont
        End If
    End Sub
End Class
0
 

Author Comment

by:jettman26
ID: 13743256
This is very good.
I doubled the points as I believe this is a rather hard question.
I have a couple more questions.
1.  How do I have it open to tab1 when the application opens?  Currently it opens to no tabs.
2.  Scenario.  I open two existing documents, so now I have two tabs open.  I then type something different into the first tab page.  I then click on Save.  What happens is that it save what is in Tab 1 into the file that is open in Tab 2.  I want it to be saved in the Tab 1 file because it is the tab that I clicked and then typed info into.  How would I do this?
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13744527
1)    you want a new tab when the application opens... i.e. a new document?

2)    shouldnt me too much of a problem... we just need to associate a filename with each tab (if it was loaded from a file)... and no filename if it was created from scratch... i'll work on that once i wake up some more
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 2000 total points
ID: 13744600


PART 2 - Correcting the save methods

ok... here are the updated subs... just put them in over the old ones but keep any that i haven't changed (might want to make a backup).

    Private Const bOpen As Integer = 0
    Private Const bSave As Integer = 1
    Private Const bSaveAs As Integer = 2
    Private Const bBold As Integer = 3
    Private Const bUnderline As Integer = 4
    Private Const bItalic As Integer = 5
    Private Const bPageSetup As Integer = 6
    Private Const bPrintPreview As Integer = 7
    Private Const bPrint As Integer = 8
    Private Const bCloseProgram As Integer = 9
    Private Const bTopMost As Integer = 10
    Private Const bNew As Integer = 11

    Dim activeFile As String = ""

    Private Sub SaveAs()
        SaveFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"

       If SaveFileDialog1.ShowDialog = DialogResult.OK Then
            Try
                activeFile = SaveFileDialog1.FileName
                activeRTB.SaveFile(activeFile)
                activeRTB.Tag =activeFile

                'Displays file name in Label1
                Dim filename As String = Path.GetFileName(activeFile)
                Label1.Text = filename
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub

    Private Sub ToolBar1_ButtonClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case bOpen
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)

                        NewTabWithRTB(filename, OpenFileDialog1.FileName)
                        activeRTB.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If

            Case bSave
                'Save
                If activeFile = "" Then
                    SaveAs()
                Else
                    If File.Exists(activeFile) Then
                        Try
                            activeRTB.SaveFile(activeFile)
                        Catch ex As Exception
                            MsgBox(ex.ToString)
                        End Try
                    Else
                        SaveAs()
                    End If
                End If


            Case bSaveAs
                'Save As
                SaveAs()

            Case bBold, bUnderline, bItalic
                'Style change
                SetCurrentStyle(ToolBar1.Buttons(3).Pushed, ToolBar1.Buttons(4).Pushed, ToolBar1.Buttons(5).Pushed)

            Case bPageSetup
                'Page Setup
                PageSetupDialog1.ShowDialog()

            Case bPrintPreview
                'Print Preview
                PrintPreviewDialog1.ShowDialog()

            Case bPrint
                'Print
                If PrintDialog1.ShowDialog() = DialogResult.OK Then
                    PrintDocument1.Print()
                End If
            Case bCloseProgram
                'Close Program
                MySettings.SaveSetting("Width", Me.Width)
                MySettings.SaveSetting("Height", Me.Height)
                MySettings.SaveSetting("Left", Me.Left)
                MySettings.SaveSetting("Top", Me.Top)

                NotifyIcon1.Visible = False
                End
            Case bTopMost
                If e.Button.Pushed = True Then
                    Me.TopMost = True
                Else
                    Me.TopMost = False
                End If

            Case bNew
                'Add new Tabs
                NewTabWithRTB()

        End Select

    Private Sub NewTabWithRTB(Optional ByVal NewText As String = "", Optional ByVal FullFileName As String = "")
        Dim myTabPage As New TabPage
        activeFile = FullFileName
        Label1.Text = NewText
        Dim myRTB As New RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
        activeRTB = myRTB
        activeRTB.Tag = FullFileName
        myTabPage.Controls.Add(myRTB)

        TabControl1.TabPages.Add(myTabPage)

        myRTB.Left = 10
        myRTB.Top = 10
        myRTB.Width = myTabPage.Width - 20
        myRTB.Height = myTabPage.Height - 20
        myRTB.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
        If NewText = "" Then
            myTabPage.Text = "TabPage" & (TabCounter)
        Else
            myTabPage.Text = NewText
        End If
        TabCounter += 1
        TabControl1.SelectedTab = myTabPage
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.TabCount >= 1 Then
            Dim thisTab As TabPage = TabControl1.SelectedTab
            If Not thisTab Is Nothing Then
                activeRTB = thisTab.Controls(0)
                activeFile = activeRTB.Tag
                Label1.Text = Path.GetFileName(activeRTB.Tag)
            Else
                activeRTB = Nothing
                activeFile = ""
                Label1.Text = ""
            End If
        Else
            activeRTB = Nothing
            activeFile = ""
            Label1.Text = ""
        End If
    End Sub

=============================================

let me know of any problems

as for PART 1 of your question... if i understood it right, just add this in your form load event (after the other code):

NewTabWithRTB()
0
 

Author Comment

by:jettman26
ID: 13744706
This works excellent.  Here are the points.  
I have a couple of side questions.  
1.  Is there any way to make the tabs along with the tab control box a different color than the crappy tan color?
2.  Is there a way to make the bold, underline and italics behave similar to the saves?  Currently If I click the bold button and bold stuff on tab 1, and then go to tab 2 the bold button is still pushed.  I want it not to be pushed on tab 2 since I am not bolding.  Essentially I want it to remember button state for each tab.
Thanks.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13744716
I'll look into part 1


as for part 2... that's simple enough really... you want to update the state of the style buttons when:

1)   the selection of the current RTB control changes
2)   the currentRTB is replaced for another (different tab selected)

I'll post code up for that in a mo... just having programmer fuel at the mo (coffee)
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13745239
I can change the colour of the tabpage easily... but it doesn't colour the top bit (where you click to change the tab)... i'm sure you can prolly change this gray colour by changing the default control colour or soemthing, but im not sure you can have individual tab colours without overriding the paint event of the tab control

=========================

and for updating the style buttons... here are the updated methods (overwrite only ones mentioned here... may want to back up again)

========================

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.TabCount >= 1 Then
            Dim thisTab As TabPage = TabControl1.SelectedTab
            If Not thisTab Is Nothing Then
                activeRTB = thisTab.Controls(0)
                activeFile = activeRTB.Tag
                Label1.Text = Path.GetFileName(activeRTB.Tag)
                activeRTB.Focus()
            Else
                activeRTB = Nothing
                activeFile = ""
                Label1.Text = ""
            End If
        Else
            activeRTB = Nothing
            activeFile = ""
            Label1.Text = ""
        End If
        UpdateStyleButtons()
    End Sub


    Private Sub NewTabWithRTB(Optional ByVal NewText As String = "", Optional ByVal FullFileName As String = "")
        Dim myTabPage As New TabPage
        myTabPage.BackColor = tabColors(TabCounter Mod tabColors.Length)
        activeFile = FullFileName
        Label1.Text = NewText
        Dim myRTB As New RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
        activeRTB = myRTB
        activeRTB.Tag = FullFileName
        myTabPage.Controls.Add(myRTB)

        TabControl1.TabPages.Add(myTabPage)

        myRTB.Left = 20
        myRTB.Top = 20
        myRTB.Width = myTabPage.Width - 42
        myRTB.Height = myTabPage.Height - 42
        myRTB.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
        If NewText = "" Then
            myTabPage.Text = "TabPage" & (TabCounter)
        Else
            myTabPage.Text = NewText
        End If
        TabCounter += 1
        TabControl1.SelectedTab = myTabPage
        UpdateStyleButtons()
        activeRTB.Focus()
    End Sub

    Dim WithEvents activeRTB As RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
    Private boolUpdatingStyle As Boolean = False

    Private Sub RTBSelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles activeRTB.SelectionChanged
        UpdateStyleButtons()
    End Sub

    Private Sub UpdateStyleButtons()
        boolUpdatingStyle = True
        If activeRTB Is Nothing Then
            ToolBar1.Buttons(bBold).Pushed = False
            ToolBar1.Buttons(bUnderline).Pushed = False
            ToolBar1.Buttons(bItalic).Pushed = False
        Else
            ToolBar1.Buttons(bBold).Pushed = activeRTB.SelectionFont.Bold
            ToolBar1.Buttons(bUnderline).Pushed = activeRTB.SelectionFont.Underline
            ToolBar1.Buttons(bItalic).Pushed = activeRTB.SelectionFont.Italic
        End If
        boolUpdatingStyle = False
    End Sub

    Private Sub SetCurrentStyle(ByVal NewBold As Boolean, ByVal NewUnderline As Boolean, ByVal NewItalic As Boolean)
        If boolUpdatingStyle Then Exit Sub
        Dim newStyle As New FontStyle
        If NewBold Then newStyle = newStyle + FontStyle.Bold
        If NewUnderline Then newStyle = newStyle + FontStyle.Underline
        If NewItalic Then newStyle = newStyle + FontStyle.Italic

        If Not NewBold And Not NewUnderline And Not NewItalic Then newStyle = FontStyle.Regular

        If activeRTB Is Nothing Then
            'do nothing
        Else
            Dim newFont As New Font(activeRTB.Font, newStyle)
            activeRTB.SelectionFont = newFont
        End If
    End Sub
0
 

Author Comment

by:jettman26
ID: 13746236
Thanks for the code.  for some reason tabColors in the NewTabWithRTB sub procedure is not declared.  What should this be declared as?
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13746242
you can just remove that line:

       myTabPage.BackColor = tabColors(TabCounter Mod tabColors.Length)
 

it was when i was testing changing the tab colours... but didnt really work that well
0
 

Author Comment

by:jettman26
ID: 13748539
Thanks for everything.  
I will continue trying to get the tabControl color to change.
0
 

Author Comment

by:jettman26
ID: 13749212
S-Twilley,
I didn't test this very much last night and one thing that I am noticing is that there is no text on the tabs now.

Here is my form code.


Imports System.IO
Imports System.Drawing.Printing

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 NotifyIcon1 As System.Windows.Forms.NotifyIcon
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
    Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
    Friend WithEvents PageSetupDialog1 As System.Windows.Forms.PageSetupDialog
    Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog
    Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
    Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton6 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton8 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton9 As System.Windows.Forms.ToolBarButton
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents ToolBarButton10 As System.Windows.Forms.ToolBarButton
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    Friend WithEvents ToolBarButton11 As System.Windows.Forms.ToolBarButton
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ToolBarButton7 As System.Windows.Forms.ToolBarButton
    Friend WithEvents ToolBarButton12 As System.Windows.Forms.ToolBarButton
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
        Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument
        Me.PageSetupDialog1 = New System.Windows.Forms.PageSetupDialog
        Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog
        Me.ToolBar1 = New System.Windows.Forms.ToolBar
        Me.ToolBarButton10 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton8 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton11 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton6 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton9 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton7 = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton12 = New System.Windows.Forms.ToolBarButton
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.Label1 = New System.Windows.Forms.Label
        Me.TabControl1 = New System.Windows.Forms.TabControl
        Me.SuspendLayout()
        '
        'NotifyIcon1
        '
        Me.NotifyIcon1.ContextMenu = Me.ContextMenu1
        Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"), System.Drawing.Icon)
        Me.NotifyIcon1.Text = "DesktopApp"
        Me.NotifyIcon1.Visible = True
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.Text = "Exit"
        '
        'PrintDialog1
        '
        Me.PrintDialog1.Document = Me.PrintDocument1
        '
        'PrintDocument1
        '
        '
        'PageSetupDialog1
        '
        Me.PageSetupDialog1.Document = Me.PrintDocument1
        '
        'PrintPreviewDialog1
        '
        Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
        Me.PrintPreviewDialog1.Document = Me.PrintDocument1
        Me.PrintPreviewDialog1.Enabled = True
        Me.PrintPreviewDialog1.Icon = CType(resources.GetObject("PrintPreviewDialog1.Icon"), System.Drawing.Icon)
        Me.PrintPreviewDialog1.Location = New System.Drawing.Point(39, 56)
        Me.PrintPreviewDialog1.MinimumSize = New System.Drawing.Size(375, 250)
        Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
        Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
        Me.PrintPreviewDialog1.Visible = False
        '
        'ToolBar1
        '
        Me.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat
        Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton10, Me.ToolBarButton8, Me.ToolBarButton11, Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, Me.ToolBarButton5, Me.ToolBarButton6, Me.ToolBarButton9, Me.ToolBarButton7, Me.ToolBarButton12})
        Me.ToolBar1.Divider = False
        Me.ToolBar1.DropDownArrows = True
        Me.ToolBar1.ImageList = Me.ImageList1
        Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
        Me.ToolBar1.Name = "ToolBar1"
        Me.ToolBar1.ShowToolTips = True
        Me.ToolBar1.Size = New System.Drawing.Size(792, 26)
        Me.ToolBar1.TabIndex = 8
        Me.ToolBar1.Wrappable = False
        '
        'ToolBarButton10
        '
        Me.ToolBarButton10.ImageIndex = 9
        Me.ToolBarButton10.ToolTipText = "Open File"
        '
        'ToolBarButton8
        '
        Me.ToolBarButton8.ImageIndex = 3
        Me.ToolBarButton8.ToolTipText = "Save"
        '
        'ToolBarButton11
        '
        Me.ToolBarButton11.ImageIndex = 10
        Me.ToolBarButton11.ToolTipText = "Save As"
        '
        'ToolBarButton1
        '
        Me.ToolBarButton1.ImageIndex = 0
        Me.ToolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton1.ToolTipText = "Bold"
        '
        'ToolBarButton2
        '
        Me.ToolBarButton2.ImageIndex = 1
        Me.ToolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton2.ToolTipText = "Underline"
        '
        'ToolBarButton3
        '
        Me.ToolBarButton3.ImageIndex = 5
        Me.ToolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton3.ToolTipText = "Italicize"
        '
        'ToolBarButton4
        '
        Me.ToolBarButton4.ImageIndex = 7
        Me.ToolBarButton4.ToolTipText = "Page Setup"
        '
        'ToolBarButton5
        '
        Me.ToolBarButton5.ImageIndex = 6
        Me.ToolBarButton5.ToolTipText = "Print Preview"
        '
        'ToolBarButton6
        '
        Me.ToolBarButton6.ImageIndex = 2
        Me.ToolBarButton6.ToolTipText = "Print"
        '
        'ToolBarButton9
        '
        Me.ToolBarButton9.ImageIndex = 8
        Me.ToolBarButton9.ToolTipText = "Close"
        '
        'ToolBarButton7
        '
        Me.ToolBarButton7.ImageIndex = 11
        Me.ToolBarButton7.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.ToolBarButton7.ToolTipText = "Always on Top"
        '
        'ToolBarButton12
        '
        Me.ToolBarButton12.ImageIndex = 12
        '
        'ImageList1
        '
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'Label1
        '
        Me.Label1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(156, 614)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(480, 24)
        Me.Label1.TabIndex = 10
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TabControl1
        '
        Me.TabControl1.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.TabControl1.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed
        Me.TabControl1.Location = New System.Drawing.Point(0, 24)
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(800, 582)
        Me.TabControl1.TabIndex = 11
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(792, 646)
        Me.ControlBox = False
        Me.Controls.Add(Me.TabControl1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ToolBar1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
        Me.Location = New System.Drawing.Point(500, 0)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "DesktopApp"
        Me.ResumeLayout(False)

    End Sub

#End Region


    'Private PrintPageSettings As New PageSettings
    'Private StringToPrint As String
    'Private PrintFont As New Font("Arial", 10)

    Private checkPrint As Integer
    Dim MySettings As New clsAppSettings(Application.StartupPath & "\Test.Config")


    'Dim activeRTB As RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
    Private Const bOpen As Integer = 0
    Private Const bSave As Integer = 1
    Private Const bSaveAs As Integer = 2
    Private Const bBold As Integer = 3
    Private Const bUnderline As Integer = 4
    Private Const bItalic As Integer = 5
    Private Const bPageSetup As Integer = 6
    Private Const bPrintPreview As Integer = 7
    Private Const bPrint As Integer = 8
    Private Const bCloseProgram As Integer = 9
    Private Const bTopMost As Integer = 10
    Private Const bNew As Integer = 11

    Dim activeFile As String = ""
    Dim WithEvents activeRTB As RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
    Private boolUpdatingStyle As Boolean = False



    Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
        checkPrint = 0
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If MySettings.GetSetting("Width") >= 376 Then
            Me.Width = MySettings.GetSetting("Width")
        End If
        If MySettings.GetSetting("Height") >= 300 Then
            Me.Height = MySettings.GetSetting("Height")
        End If
        If MySettings.GetSetting("Left") > 0 Then
            If MySettings.GetSetting("Left") < Screen.PrimaryScreen.Bounds.Width Then
                Me.Left = MySettings.GetSetting("Left")
            End If
        End If

        If MySettings.GetSetting("Top") > 0 Then
            If MySettings.GetSetting("Top") < Screen.PrimaryScreen.Bounds.Height Then
                Me.Top = MySettings.GetSetting("Top")
            End If
        End If
        NewTabWithRTB()
    End Sub

    Private Sub NotifyIcon1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.Click
        Me.Activate()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        ' Print the content of the RichTextBox. Store the last character printed.
        checkPrint = activeRTB.Print(checkPrint, activeRTB.TextLength, e)

        ' Look for more pages
        If checkPrint < activeRTB.TextLength Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

    Private Sub SaveAs()
        SaveFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
        If SaveFileDialog1.ShowDialog = DialogResult.OK Then
            Try
                activeFile = SaveFileDialog1.FileName
                activeRTB.SaveFile(activeFile)
                activeRTB.Tag = activeFile
                'Displays file name in Label1
                Dim filename As String = Path.GetFileName(SaveFileDialog1.FileName)
                Label1.Text = filename
                TabControl1.SelectedTab.Text = filename
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub


    Private Sub ToolBar1_ButtonClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
        Select Case ToolBar1.Buttons.IndexOf(e.Button)
            Case bOpen
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        Dim filename As String = Path.GetFileName(OpenFileDialog1.FileName)

                        NewTabWithRTB(filename, OpenFileDialog1.FileName)
                        activeRTB.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If

            Case bSave
                'Save
                If activeFile = "" Then
                    SaveAs()
                Else
                    If File.Exists(activeFile) Then
                        Try
                            activeRTB.SaveFile(activeFile)
                        Catch ex As Exception
                            MsgBox(ex.ToString)
                        End Try
                    Else
                        SaveAs()
                    End If
                End If


            Case bSaveAs
                'Save As
                SaveAs()

            Case bBold, bUnderline, bItalic
                'Style change
                SetCurrentStyle(ToolBar1.Buttons(3).Pushed, ToolBar1.Buttons(4).Pushed, ToolBar1.Buttons(5).Pushed)

            Case bPageSetup
                'Page Setup
                PageSetupDialog1.ShowDialog()

            Case bPrintPreview
                'Print Preview
                PrintPreviewDialog1.ShowDialog()

            Case bPrint
                'Print
                If PrintDialog1.ShowDialog() = DialogResult.OK Then
                    PrintDocument1.Print()
                End If
            Case bCloseProgram
                'Close Program
                MySettings.SaveSetting("Width", Me.Width)
                MySettings.SaveSetting("Height", Me.Height)
                MySettings.SaveSetting("Left", Me.Left)
                MySettings.SaveSetting("Top", Me.Top)

                NotifyIcon1.Visible = False
                End
            Case bTopMost
                If e.Button.Pushed = True Then
                    Me.TopMost = True
                Else
                    Me.TopMost = False
                End If

            Case bNew
                'Add new Tabs
                NewTabWithRTB()

        End Select
    End Sub

    Private Sub ContextMenu1_Popup_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup

    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        MySettings.SaveSetting("Width", Me.Width)
        MySettings.SaveSetting("Height", Me.Height)
        MySettings.SaveSetting("Left", Me.Left)
        MySettings.SaveSetting("Top", Me.Top)
        NotifyIcon1.Visible = False
        End
    End Sub


    Private TabCounter As Integer = 1

    Private Sub NewTabWithRTB(Optional ByVal NewText As String = "", Optional ByVal FullFileName As String = "")
        Dim myTabPage As New TabPage
        activeFile = FullFileName
        Label1.Text = NewText
        Dim myRTB As New RichTextBoxPrintCtrl.RichTextBoxPrintCtrl.RichTextBoxPrintCtrl
        activeRTB = myRTB
        activeRTB.Tag = FullFileName
        myTabPage.Controls.Add(myRTB)

        TabControl1.TabPages.Add(myTabPage)

        myRTB.Left = 20
        myRTB.Top = 20
        myRTB.Width = myTabPage.Width - 42
        myRTB.Height = myTabPage.Height - 42
        myRTB.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
        If NewText = "" Then
            myTabPage.Text = "TabPage" & (TabCounter)
        Else
            myTabPage.Text = NewText
        End If
        TabCounter += 1
        TabControl1.SelectedTab = myTabPage
        UpdateStyleButtons()
        activeRTB.Focus()
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.TabCount >= 1 Then
            Dim thisTab As TabPage = TabControl1.SelectedTab
            If Not thisTab Is Nothing Then
                activeRTB = thisTab.Controls(0)
                activeFile = activeRTB.Tag
                Label1.Text = Path.GetFileName(activeRTB.Tag)
                activeRTB.Focus()
            Else
                activeRTB = Nothing
                activeFile = ""
                Label1.Text = ""
            End If
        Else
            activeRTB = Nothing
            activeFile = ""
            Label1.Text = ""
        End If
        UpdateStyleButtons()
    End Sub

    Private Sub RTBSelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles activeRTB.SelectionChanged
        UpdateStyleButtons()
    End Sub

    Private Sub UpdateStyleButtons()
        boolUpdatingStyle = True
        If activeRTB Is Nothing Then
            ToolBar1.Buttons(bBold).Pushed = False
            ToolBar1.Buttons(bUnderline).Pushed = False
            ToolBar1.Buttons(bItalic).Pushed = False
        Else
            ToolBar1.Buttons(bBold).Pushed = activeRTB.SelectionFont.Bold
            ToolBar1.Buttons(bUnderline).Pushed = activeRTB.SelectionFont.Underline
            ToolBar1.Buttons(bItalic).Pushed = activeRTB.SelectionFont.Italic
        End If
        boolUpdatingStyle = False
    End Sub

    Private Sub SetCurrentStyle(ByVal NewBold As Boolean, ByVal NewUnderline As Boolean, ByVal NewItalic As Boolean)
        If boolUpdatingStyle Then Exit Sub
        Dim newStyle As New FontStyle
        If NewBold Then newStyle = newStyle + FontStyle.Bold
        If NewUnderline Then newStyle = newStyle + FontStyle.Underline
        If NewItalic Then newStyle = newStyle + FontStyle.Italic

        If Not NewBold And Not NewUnderline And Not NewItalic Then newStyle = FontStyle.Regular

        If activeRTB Is Nothing Then
            'do nothing
        Else
            Dim newFont As New Font(activeRTB.Font, newStyle)
            activeRTB.SelectionFont = newFont
        End If
    End Sub
End Class
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749240
you mean the captions for the tabs?

if so, put a break point at this line (within the NewTabWithRTB):

  If NewText = "" Then

and then step thru to see which branch of the If statement it goes to...

NewText should hold  the short file name if a file is opened... and if its empty (new document)... it should create it based on the current count of tabs in the lifetime of the app
0
 

Author Comment

by:jettman26
ID: 13749310
Just starting the app, which calls NewTabWithRTB, it goes from
'If NewText = "" Then'
to
'myTabPage.Text = "TabPage" & (TabCounter)'
and then
'End If'
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749332
ok, in your form load... add this line at hte top

TabCounter  = 1

==============

change:

'myTabPage.Text = "TabPage" & (TabCounter)'

for

myTabPage.Text = "TabPage" & TabCounter.ToString

============

if that doesn't make a difference, just tell me what the value of myTabPage.Text is after that line
0
 

Author Comment

by:jettman26
ID: 13749378
Sorry, I don't know much about debugging but I put a breakpoint at 'If NewText = "" Then'
and then I stepped into 'myTabPage.Text = "TabPage" & TabCounter.ToString' and when the yellow arrow is pointing on this line the 'myTabPage.Text' says it is "".
Then when I click the Step Into button the 'myTabPage.Text' variable is set to TabPage1.  

Is there a way to see the value of the variables without having to mouse over them?
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749387
you can select the statement you want to watch... and right click, and goto "Add Watch"... that should open up a window which watches the statement... so you can select 'myTabPage.Text' and goto add watch

======

alternatively, you could use the debug window (what some experts use), or msgbox:

        If NewText = "" Then
            myTabPage.Text = "TabPage" & (TabCounter)
        Else
            myTabPage.Text = NewText
        End If
        Msgbox("NewText:" & NewText)
        Msgbox("Text Property:" & myTabPage.Text)
0
 

Author Comment

by:jettman26
ID: 13749395
I just tried the Add Watch and the 'myTabPage.Text' is 'TabPage1'
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749402
isn't that what it should be by default?   have i confused the problem... can you explain a lil more so i get what the problem is
0
 

Author Comment

by:jettman26
ID: 13749411
your right, the tab should say TabPage1.  I am not talking about the contents in the RTB, I am talking about the name or the text of the tab.  The problem is that the tab is blank when the form loads.  The tabs are blank no matter what.  If I open a file, SaveAs a file or open a new tab, they are all
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749442
not a problem with my code... you had changed the DrawMode of the tabcontrol to "OwnerDrawFixed"... change back to normal
0
 

Author Comment

by:jettman26
ID: 13749454
oh crap, sorry about that, i was trying to change the color of the tab control and completely forgot about that.  How could you tell that it was set to OwnerDrawFixed?
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749462
cos my project worked... then thought that maybe the forecolor of the tabcontol was set to gray (making the text invisible)... then i saw the "bolder" property for DrawMode
0
 

Author Comment

by:jettman26
ID: 13749653
I have one more question for you.  I can open another question if you would like so you can get more points becuase you deserve it.  Let me know what u want me to do.

When I do Open File, I don't want it to open the file in a new tab.  I want it to open in the current tab.  I just commented out
'NewTabWithRTB(filename, OpenFileDialog1.FileName)'
of the bOpen case.  This caused a problem since the tab name or tab text didn't get updated w/the file name.  Also it screws up the save routine.  Just wondering if you knew a way around this.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749666
           Case bOpen
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        activeFileName = OpenFileDialog1.FileName
                        Dim filename As String = Path.GetFileName(activeFileName)

                        TabControl1.SelectedTab.Text = fileName
                        activeRTB.Tag = activeFileName
                        activeRTB.LoadFile(activeFileName, RichTextBoxStreamType.RichText)
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If
0
 

Author Comment

by:jettman26
ID: 13749743
I used 'Dim activeFileName As String'
not sure if that is right.  

The Save routine is still not working.
If I open a file, then add some text to it and click the Save button, it brings up the SaveAs dialog box.  It should just save it.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13749749
oh sorry... remove that dim statement, i meant activeFile, not activeFileName

           Case bOpen
                'Open File
                OpenFileDialog1.Filter = "Rich Text (*.rtf)|*.rtf"
                If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                    Try
                        activeFile = OpenFileDialog1.FileName
                        Dim filename As String = Path.GetFileName(activeFile )

                        TabControl1.SelectedTab.Text = fileName
                        activeRTB.Tag = activeFile
                        activeRTB.LoadFile(activeFile , RichTextBoxStreamType.RichText)
                    Catch
                        MsgBox("Error opening file.")
                    End Try
                End If
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question