Solved

Mother form with control form in MID form

Posted on 2001-09-10
7
407 Views
Last Modified: 2013-11-25


i have a MID form. What i to have a form which when loads instantiate another form which is associated with this form. the second form is much smaller then the mother form, basically a control panel for the mother for with some control buttons. what i want is that when the mother form is maximized in the MID form then it hides the control form. what is want is that whenever the mther form has the focus then its control form should be visible momatter it has the focus or not or whether the mother form is mazimized or not. i just want the contorl for whould be visible at all times when the mother form has the focus.

Shahzad

0
Comment
Question by:shahzad73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 1

Expert Comment

by:harsh008_k
ID: 6470483
hi shahzad,
1)First create a MDI form
2)Make the other form MDIChild =True

make the startup object- Childform
so the parent form will also come

Thie should solve ur problem.It has nothing to do with maximize,unless u have not made the other form MDIChild=true
0
 
LVL 1

Author Comment

by:shahzad73
ID: 6470766

hi harsh008_k


i am using MDI form. in the MID form menu i have a munu option NEW which create a instance of mother form. you can creare as many instances of Mother form as you wish. each mother form when loads also instances the child form whcih is associated with this form. so in the MDI form you have mother forms and associate child or contro, forms. so i want that when mother form has the control the child form should always be visible . any suggestion



Shahzad
0
 
LVL 8

Accepted Solution

by:
DennisBorg earned 30 total points
ID: 6471022
You can use the Mother form's Activate Event to ensure that the Control Panel Form is visible.

This Control Panel Form should *NOT* be a MDI Child form. But you can cause this form to float on top your MDI Parent form with a line of code such as the following:

   ControlPanelForm.Show , MDIForm1


An alternative would be to use a ToolBar on your MDI Parent form instead of using a separate form. There are toolbars which can be docked to the form, or free-float above the forms.


-Dennis Borg
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:shahzad73
ID: 6508284
sorry DennisBorg  for the late response.

Shahzad
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6508831
That's alright. Thank you for following up on it. :-)

-Dennis Borg
0
 

Expert Comment

by:jasoncuevas
ID: 14305864
Imports System.IO
Imports System.Drawing.Printing


Public Class Form1
    Inherits System.Windows.Forms.Form

    Private strFileName As String
    Private objStreamToPrint As StreamReader
    Private objPrintFont As Font

    ' Declare a PrintDocument object named document.
    Private WithEvents document As New System.Drawing.Printing.PrintDocument
#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 MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileNew As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileSave As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFilePrint As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileExit As System.Windows.Forms.MenuItem
    Friend WithEvents mnuEditUndo As System.Windows.Forms.MenuItem
    Friend WithEvents mnuEditCut As System.Windows.Forms.MenuItem
    Friend WithEvents mnuEditCopy As System.Windows.Forms.MenuItem
    Friend WithEvents mnuEditPaste As System.Windows.Forms.MenuItem
    Friend WithEvents mnuEditSelect As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuViewToolbarsMain As System.Windows.Forms.MenuItem
    Friend WithEvents tbrMain As System.Windows.Forms.ToolBar
    Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbnNew As System.Windows.Forms.ToolBarButton
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents tbnOpen As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbnSave As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbnPrint As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbnUndo As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbnCut As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnCopy As System.Windows.Forms.ToolBarButton
    Friend WithEvents tbnPaste As System.Windows.Forms.ToolBarButton
    Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog
    Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents cmuCopy As System.Windows.Forms.MenuItem
    Friend WithEvents cmuCut As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents cmuUndo As System.Windows.Forms.MenuItem
    Friend WithEvents cmuPaste As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    Friend WithEvents cmuSelectAll As System.Windows.Forms.MenuItem
    Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog
    Friend WithEvents mnuStyleFont As System.Windows.Forms.MenuItem
    Friend WithEvents tbnFont As System.Windows.Forms.ToolBarButton
    <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.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        Me.mnuFileNew = New System.Windows.Forms.MenuItem
        Me.mnuFileOpen = New System.Windows.Forms.MenuItem
        Me.mnuFileSave = New System.Windows.Forms.MenuItem
        Me.MenuItem4 = New System.Windows.Forms.MenuItem
        Me.mnuFilePrint = New System.Windows.Forms.MenuItem
        Me.MenuItem6 = New System.Windows.Forms.MenuItem
        Me.mnuFileExit = New System.Windows.Forms.MenuItem
        Me.MenuItem8 = New System.Windows.Forms.MenuItem
        Me.mnuEditUndo = New System.Windows.Forms.MenuItem
        Me.MenuItem10 = New System.Windows.Forms.MenuItem
        Me.mnuEditCut = New System.Windows.Forms.MenuItem
        Me.mnuEditCopy = New System.Windows.Forms.MenuItem
        Me.mnuEditPaste = New System.Windows.Forms.MenuItem
        Me.MenuItem14 = New System.Windows.Forms.MenuItem
        Me.mnuEditSelect = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.mnuStyleFont = New System.Windows.Forms.MenuItem
        Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.tbrMain = New System.Windows.Forms.ToolBar
        Me.tbnNew = New System.Windows.Forms.ToolBarButton
        Me.tbnOpen = New System.Windows.Forms.ToolBarButton
        Me.tbnSave = New System.Windows.Forms.ToolBarButton
        Me.tbnPrint = New System.Windows.Forms.ToolBarButton
        Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton
        Me.tbnUndo = New System.Windows.Forms.ToolBarButton
        Me.tbnCut = New System.Windows.Forms.ToolBarButton
        Me.btnCopy = New System.Windows.Forms.ToolBarButton
        Me.tbnPaste = New System.Windows.Forms.ToolBarButton
        Me.tbnFont = New System.Windows.Forms.ToolBarButton
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.PrintDialog1 = New System.Windows.Forms.PrintDialog
        Me.ContextMenu1 = New System.Windows.Forms.ContextMenu
        Me.cmuUndo = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.cmuCut = New System.Windows.Forms.MenuItem
        Me.cmuCopy = New System.Windows.Forms.MenuItem
        Me.cmuPaste = New System.Windows.Forms.MenuItem
        Me.MenuItem5 = New System.Windows.Forms.MenuItem
        Me.cmuSelectAll = New System.Windows.Forms.MenuItem
        Me.FontDialog1 = New System.Windows.Forms.FontDialog
        Me.SuspendLayout()
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem8, Me.MenuItem2})
        '
        'MenuItem1
        '
        Me.MenuItem1.Index = 0
        Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFileNew, Me.mnuFileOpen, Me.mnuFileSave, Me.MenuItem4, Me.mnuFilePrint, Me.MenuItem6, Me.mnuFileExit})
        Me.MenuItem1.Text = "&File"
        '
        'mnuFileNew
        '
        Me.mnuFileNew.Index = 0
        Me.mnuFileNew.Text = "&New"
        '
        'mnuFileOpen
        '
        Me.mnuFileOpen.Index = 1
        Me.mnuFileOpen.MdiList = True
        Me.mnuFileOpen.MergeType = System.Windows.Forms.MenuMerge.Replace
        Me.mnuFileOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO
        Me.mnuFileOpen.Text = "&Open"
        '
        'mnuFileSave
        '
        Me.mnuFileSave.Index = 2
        Me.mnuFileSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS
        Me.mnuFileSave.Text = "&Save"
        '
        'MenuItem4
        '
        Me.MenuItem4.Index = 3
        Me.MenuItem4.Text = "-"
        '
        'mnuFilePrint
        '
        Me.mnuFilePrint.Index = 4
        Me.mnuFilePrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP
        Me.mnuFilePrint.Text = "&Print"
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 5
        Me.MenuItem6.Text = "-"
        '
        'mnuFileExit
        '
        Me.mnuFileExit.Index = 6
        Me.mnuFileExit.Text = "E&xit"
        '
        'MenuItem8
        '
        Me.MenuItem8.Index = 1
        Me.MenuItem8.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEditUndo, Me.MenuItem10, Me.mnuEditCut, Me.mnuEditCopy, Me.mnuEditPaste, Me.MenuItem14, Me.mnuEditSelect})
        Me.MenuItem8.Text = "&Edit"
        '
        'mnuEditUndo
        '
        Me.mnuEditUndo.Index = 0
        Me.mnuEditUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ
        Me.mnuEditUndo.Text = "&Undo"
        '
        'MenuItem10
        '
        Me.MenuItem10.Index = 1
        Me.MenuItem10.Text = "-"
        '
        'mnuEditCut
        '
        Me.mnuEditCut.Index = 2
        Me.mnuEditCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX
        Me.mnuEditCut.Text = "Cu&t"
        '
        'mnuEditCopy
        '
        Me.mnuEditCopy.Index = 3
        Me.mnuEditCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC
        Me.mnuEditCopy.Text = "&Copy"
        '
        'mnuEditPaste
        '
        Me.mnuEditPaste.Index = 4
        Me.mnuEditPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV
        Me.mnuEditPaste.Text = "&Paste"
        '
        'MenuItem14
        '
        Me.MenuItem14.Index = 5
        Me.MenuItem14.Text = "-"
        '
        'mnuEditSelect
        '
        Me.mnuEditSelect.Index = 6
        Me.mnuEditSelect.Shortcut = System.Windows.Forms.Shortcut.CtrlA
        Me.mnuEditSelect.Text = "Select &All"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 2
        Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuStyleFont})
        Me.MenuItem2.Text = "&Style"
        '
        'mnuStyleFont
        '
        Me.mnuStyleFont.Index = 0
        Me.mnuStyleFont.Shortcut = System.Windows.Forms.Shortcut.CtrlF
        Me.mnuStyleFont.Text = "&Font Style"
        '
        'tbrMain
        '
        Me.tbrMain.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.tbnNew, Me.tbnOpen, Me.tbnSave, Me.tbnPrint, Me.ToolBarButton5, Me.tbnUndo, Me.tbnCut, Me.btnCopy, Me.tbnPaste, Me.tbnFont})
        Me.tbrMain.DropDownArrows = True
        Me.tbrMain.ImageList = Me.ImageList1
        Me.tbrMain.Location = New System.Drawing.Point(0, 0)
        Me.tbrMain.Name = "tbrMain"
        Me.tbrMain.ShowToolTips = True
        Me.tbrMain.Size = New System.Drawing.Size(552, 28)
        Me.tbrMain.TabIndex = 1
        '
        'tbnNew
        '
        Me.tbnNew.ImageIndex = 0
        Me.tbnNew.ToolTipText = "New"
        '
        'tbnOpen
        '
        Me.tbnOpen.ImageIndex = 1
        Me.tbnOpen.ToolTipText = "Open"
        '
        'tbnSave
        '
        Me.tbnSave.ImageIndex = 2
        Me.tbnSave.ToolTipText = "Save"
        '
        'tbnPrint
        '
        Me.tbnPrint.ImageIndex = 3
        Me.tbnPrint.ToolTipText = "Print"
        '
        'ToolBarButton5
        '
        Me.ToolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'tbnUndo
        '
        Me.tbnUndo.ImageIndex = 4
        Me.tbnUndo.ToolTipText = "Undo"
        '
        'tbnCut
        '
        Me.tbnCut.ImageIndex = 5
        Me.tbnCut.ToolTipText = "Cut"
        '
        'btnCopy
        '
        Me.btnCopy.ImageIndex = 6
        Me.btnCopy.ToolTipText = "Copy"
        '
        'tbnPaste
        '
        Me.tbnPaste.ImageIndex = 7
        Me.tbnPaste.ToolTipText = "Paste"
        '
        'tbnFont
        '
        Me.tbnFont.ImageIndex = 8
        Me.tbnFont.ToolTipText = "Change Font"
        '
        '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
        '
        'ContextMenu1
        '
        Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmuUndo, Me.MenuItem3, Me.cmuCut, Me.cmuCopy, Me.cmuPaste, Me.MenuItem5, Me.cmuSelectAll})
        '
        'cmuUndo
        '
        Me.cmuUndo.Index = 0
        Me.cmuUndo.Shortcut = System.Windows.Forms.Shortcut.CtrlZ
        Me.cmuUndo.Text = "Undo"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 1
        Me.MenuItem3.Text = "-"
        '
        'cmuCut
        '
        Me.cmuCut.Index = 2
        Me.cmuCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX
        Me.cmuCut.Text = "Cut"
        '
        'cmuCopy
        '
        Me.cmuCopy.Index = 3
        Me.cmuCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC
        Me.cmuCopy.Text = "Copy"
        '
        'cmuPaste
        '
        Me.cmuPaste.Index = 4
        Me.cmuPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV
        Me.cmuPaste.Text = "Paste"
        '
        'MenuItem5
        '
        Me.MenuItem5.Index = 5
        Me.MenuItem5.Text = "-"
        '
        'cmuSelectAll
        '
        Me.cmuSelectAll.Index = 6
        Me.cmuSelectAll.Shortcut = System.Windows.Forms.Shortcut.CtrlA
        Me.cmuSelectAll.Text = "Select All"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(552, 382)
        Me.Controls.Add(Me.tbrMain)
        Me.ImeMode = System.Windows.Forms.ImeMode.On
        Me.IsMdiContainer = True
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "Cuevas Text Editor"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim frm2 As New Form2

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim login As New Jason_Cuevas.LoginUser

        Dim userID As Integer = login.Go(Me)

        If userID <> 0 Then
            MessageBox.Show("Your Password is valid.")
        Else
            MessageBox.Show("You must login with a correct password to access this program")
            Me.Close()
        End If

        Dim frm2 As New Form2
        frm2.MdiParent = Me
        frm2.Show()



    End Sub


    Private Sub mnuFileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileNew.Click
        newFile()
       
    End Sub

    Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
        openFile()
    End Sub

    Private Sub mnuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click
        With SaveFileDialog1
            .DefaultExt = "txt"
            .FileName = strFileName
            .Filter = "Text files (*.txt)|*.txt|All Files (*.*)|*.*"
            .FilterIndex = 1
            .InitialDirectory = "C:\Temp\"
            .OverwritePrompt = True
            .Title = "Save File"
        End With

        'Show the Save dialog and if the user clikcs the Save button load the file
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            strFileName = SaveFileDialog1.FileName
            Dim objWriter As StreamWriter = New StreamWriter(strFileName, False)
            objWriter.Write(frm2.txtMain.Text)
            objWriter.Close()
            objWriter = Nothing
        End If
    End Sub

    Private Sub mnuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrint.Click

        Dim objPrintDocument As PrintDocument = New PrintDocument

        objPrintDocument.DocumentName = "Text File Print Demo"

        PrintDialog1.AllowPrintToFile = False
        PrintDialog1.AllowSelection = False
        PrintDialog1.AllowSomePages = False

        PrintDialog1.Document = objPrintDocument

        If PrintDialog1.ShowDialog() = DialogResult.OK Then
            objStreamToPrint = New StreamReader(strFileName)

            objPrintFont = FontDialog1.Font

            AddHandler objPrintDocument.PrintPage, _
                AddressOf objPrintDocument_PrintPage

            objPrintDocument.PrinterSettings = PrintDialog1.PrinterSettings

            objPrintDocument.Print()

            objStreamToPrint.Close()
            objStreamToPrint = Nothing
        End If
    End Sub

    Private Sub objPrintDocument_PrintPage(ByVal sender As Object, _
            ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        'Declare variables
        Dim sngLinesPerpage As Single = 0
        Dim sngVerticalPosition As Single = 0
        Dim intLineCount As Integer = 0
        Dim sngLeftMargin As Single = e.MarginBounds.Left
        Dim sngTopMargin As Single = e.MarginBounds.Top
        Dim strLine As String

        sngLinesPerpage = e.MarginBounds.Height / objPrintFont.GetHeight(e.Graphics)

        strLine = objStreamToPrint.ReadLine()
        While (intLineCount < sngLinesPerpage And Not (strLine Is Nothing))
            sngVerticalPosition = sngTopMargin + (intLineCount * objPrintFont.GetHeight(e.Graphics))

            e.Graphics.DrawString(strLine, objPrintFont, Brushes.Black, _
                sngLeftMargin, sngVerticalPosition, New StringFormat)

            intLineCount = intLineCount + 1

            If (intLineCount < sngLinesPerpage) Then
                strLine = objStreamToPrint.ReadLine()
            End If

        End While

        If (strLine <> Nothing) Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

    Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click

        If MessageBox.Show("Do you want to save your current project before you exit?", "Save?", MessageBoxButtons.YesNo, _
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then

            mnuFileSave_Click(Nothing, Nothing)

        End If

        Me.Close()
    End Sub

    Private Sub mnuEditUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditUndo.Click
        Dim objTextBox As TextBox = Me.ActiveControl

        'Undo the last operation
        objTextBox.Undo()
    End Sub

    Private Sub mnuEditCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditCut.Click
        Dim objTextBox As TextBox = Me.ActiveControl

        'Copy the text to the clipboard and clear the field
        objTextBox.Cut()
    End Sub

    Private Sub mnuEditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditCopy.Click
        Dim objTextBox As TextBox = Me.ActiveControl

        objTextBox.Copy()
    End Sub

    Private Sub mnuEditSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditSelect.Click

        Dim objTextBox As TextBox = Me.ActiveControl

        objTextBox.SelectAll()

    End Sub

    Private Sub mnuEditPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditPaste.Click
        Dim objTextBox As TextBox = Me.ActiveControl

        objTextBox.Paste()
    End Sub

    Private Sub tbrMain_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tbrMain.ButtonClick
        Select Case tbrMain.Buttons.IndexOf(e.Button)
            Case 0
                Me.newFile()
            Case 1
                Me.openFile()
            Case 2
                mnuFileSave_Click(Nothing, Nothing)
            Case 3
                mnuFilePrint_Click(Nothing, Nothing)
            Case 4
            Case 5
                mnuEditUndo_Click(Nothing, Nothing)
            Case 6
                mnuEditCut_Click(Nothing, Nothing)
            Case 7
                mnuEditCopy_Click(Nothing, Nothing)
            Case 8
                mnuEditPaste_Click(Nothing, Nothing)
            Case 9
                mnuStyleFont_Click(Nothing, Nothing)
            Case 10
                mnuStyleFont_Click(Nothing, Nothing)
        End Select
    End Sub

    Private Sub mnuStyleFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStyleFont.Click
        FontDialog1.ShowColor = True

        'Show the Font dialog
        If FontDialog1.ShowDialog() = DialogResult.OK Then
            frm2.txtMain.Font = FontDialog1.Font
            frm2.txtMain.ForeColor = FontDialog1.Color
        End If
    End Sub

    Private Sub txtMain_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        ToggleMenus()
    End Sub

    Private Sub ToggleMenus()
        Dim objTextBox As TextBox = Me.ActiveControl

        mnuEditUndo.Enabled = objTextBox.CanUndo
        cmuUndo.Enabled = objTextBox.CanUndo

        mnuEditCut.Enabled = objTextBox.SelectionLength
        cmuCut.Enabled = objTextBox.SelectionLength

        mnuEditCopy.Enabled = objTextBox.SelectionLength
        cmuCopy.Enabled = objTextBox.SelectionLength

        mnuEditPaste.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)
        cmuPaste.Enabled = Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)

        mnuEditSelect.Enabled = objTextBox.SelectionLength < objTextBox.Text.Length
        cmuSelectAll.Enabled = objTextBox.SelectionLength < objTextBox.Text.Length

    End Sub

    Private Sub cmuUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmuUndo.Click
        mnuEditUndo_Click(Nothing, Nothing)
    End Sub

    Private Sub cmuCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmuCut.Click
        mnuEditCut_Click(Nothing, Nothing)
    End Sub

    Private Sub cmuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmuCopy.Click
        mnuEditCopy_Click(Nothing, Nothing)
    End Sub

    Private Sub cmuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmuPaste.Click
        mnuEditPaste_Click(Nothing, Nothing)
    End Sub

    Private Sub cmuSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmuSelectAll.Click
        mnuEditSelect_Click(Nothing, Nothing)
    End Sub

    Public Sub newFile()
        If MessageBox.Show("Do you want to save your current project before creating a new one?", "Save?", MessageBoxButtons.YesNo, _
                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then

            mnuFileSave_Click(Nothing, Nothing)

        End If

        frm2.txtMain.Text = ""

    End Sub

    Public Sub openFile()
        With OpenFileDialog1
            .Filter = "Text files (*.txt)|*.txt|All Files (*.*)|*.*"
            .FilterIndex = 1
            .InitialDirectory = "C:\Temp\"
            .Title = "Open File"
        End With

        'Show the Open dialog and if the user clicks the OK button load the file
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            strFileName = OpenFileDialog1.FileName
            Dim objReader As StreamReader = New StreamReader(strFileName)
            frm2.txtMain.Text = objReader.ReadToEnd()
            objReader.Close()
            objReader = Nothing
        End If
    End Sub

End Class

That's form1. There is a login form when the program opens that has worked fine the whole time. Here is code for form2
Public Class Form2
    Inherits System.Windows.Forms.Form

    ' Declare a PrintDocument object named document.

#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.
    Public WithEvents txtMain As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtMain = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'txtMain
        '
        Me.txtMain.AcceptsReturn = True
        Me.txtMain.AcceptsTab = True
        Me.txtMain.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.txtMain.CausesValidation = False
        Me.txtMain.HideSelection = False
        Me.txtMain.Location = New System.Drawing.Point(0, 0)
        Me.txtMain.Multiline = True
        Me.txtMain.Name = "txtMain"
        Me.txtMain.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.txtMain.Size = New System.Drawing.Size(492, 444)
        Me.txtMain.TabIndex = 0
        Me.txtMain.Text = ""
        '
        'Form2
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(488, 438)
        Me.Controls.Add(Me.txtMain)
        Me.Name = "Form2"
        Me.Text = "New File"
        Me.ResumeLayout(False)

    End Sub

#End Region

   
End Class

I left out the windows generated code on form1 due to the massive space it would take up but can print that if need be



0
 

Expert Comment

by:jasoncuevas
ID: 14305868
Excuse my comment above, I posted in the wrong screen and don't know how to remove it.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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