-1

I am making a VOS where the desktop is a MDI Parent form. But, as soon as I show any Child windows, they show up, load all their resources and then hide again. And they don't show back up.

The code that shows an app:

Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click, Label1.Click, TestToolStripMenuItem.Click
        showapp(Maininternet)
    End Sub

''' <summary>
    ''' Add's an app to the Galaxy OS MDI child tree and shows it.
    ''' </summary>
    ''' <param name="app">Name of the app.</param>
    ''' <remarks></remarks>
    Sub showapp(app As Form)
        AddNewForm(app)
        app.Show()
    End Sub

And in one of the modules:

''' <summary>
    ''' Adds a form to the MDI application
    ''' And links it with a TaskBarItem
    ''' </summary>
    ''' <param name="frm">The form to use</param>
    ''' <remarks></remarks>
    Private Sub AddNewForm(ByVal frm As Form)
        frm.MdiParent = GalaxyOS.Core.GUI.Desktop

        Dim img As Image = CType(New ImageConverter().ConvertFrom(frm.Icon), Image)

        Dim tbItem As New TaskBarItem(frm.Text, img, frm)
        tbItem.ImageScaling = ToolStripItemImageScaling.SizeToFit
        TaskBar.Items.Add(tbItem)

        frm.Show()
    End Sub

As it is an OS, there is a menustrip acting like a taskbar, and the TaskBarItem is a MenuStrip item that shows the icon of an app, it's name, and options to Close and Restore it. Code:

Namespace Core.GUI.Desktop.Taskbar
''' <summary>
''' The TaskBarItem class is a item on the TaskBar that can close/restore a application
''' It represents the form's icon and text on the visual side
''' </summary>
''' <remarks></remarks>
Public Class TaskBarItem
    Inherits ToolStripMenuItem

    Private WithEvents CloseItem As New ToolStripMenuItem("Close")
    Private WithEvents RestoreItem As New ToolStripMenuItem("Restore")
    Friend WithEvents Control1 As System.Windows.Forms.Control

    Private _form As Form


    ''' <summary>
    ''' Creates a new instance of the TaskBarItem class
    ''' </summary>
    ''' <param name="text">The text used on the item</param>
    ''' <param name="img">The image used on the item</param>
    ''' <param name="frm">The form that is linked to it</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal text As String, ByVal img As Image, ByVal frm As Form)
        MyBase.New(text, img)
        CloseItem.BackColor = color.black
        CloseItem.ForeColor = color.deepskyblue
        RestoreItem.BackColor = color.black
        RestoreItem.ForeColor = color.deepskyblue
        BackColor = color.black
        ForeColor = color.deepskyblue
        _form = frm
        AddHandler CloseItem.Click, AddressOf Close_Click
        AddHandler RestoreItem.Click, AddressOf Restore_Click

        AddHandler frm.FormClosing, AddressOf Form_Closed

        Me.DropDownItems.Add(CloseItem)
        Me.DropDownItems.Add(RestoreItem)
        frm.Show()
    End Sub

    '' A event to remove the item when the form has been closed by the close button
    '' or a internal Form.Close call
    Private Sub Close_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.Parent.Items.Remove(Me)
        If (Not IsNothing(_form)) Then
            _form.Close()
        End If
    End Sub

    '' A event to restore the form's previous state
    Private Sub Restore_Click(ByVal sender As Object, ByVal e As EventArgs)
        If (_form.WindowState = FormWindowState.Minimized) Then
            _form.WindowState = FormWindowState.Normal
            _form.Visible = True
        End If
    End Sub

    '' A event to close the form using the TaskBarItem
    Private Sub Form_Closed(sender As Object, e As FormClosingEventArgs)
        For Each tsmi As ToolStripMenuItem In GalaxyOs.Core.GUI.Desktop.Desktop.TaskBar.Items
            If (tsmi.Text = _form.Text) Then
                Me.Parent.Items.Remove(tsmi)
                Exit For
            End If
        Next
    End Sub
End Class
End Namespace

I am a complete noob and am really stuck on this...

Any help appreciated greatly, Hamza Ali

Ali Hamza
  • 1
  • 2
  • It's unclear what you are doing: `frm.MdiParent = Me` can't compile if that line is in a module since Me wouldn't refer to a form. I wouldn't try showing the form before setting the MdiParent property. – LarsTech Oct 26 '14 at 16:33
  • oops, I meant to put Desktop there...I'll change it now. – Ali Hamza Oct 26 '14 at 16:35
  • Well, that's as clear as mud. What's `GalaxyOS.Core.GUI.Desktop`? That doesn't look like it would reference an instance of the MDI Parent form. – LarsTech Oct 26 '14 at 16:37
  • Oh yeah, and it is showing the form after setting the MdiParent property. – Ali Hamza Oct 26 '14 at 16:37
  • `GalaxyOS.Core.GUI.Desktop` is the Desktop form, it's just been put in namespaces for easier navigation. This project has over 125 forms, so putting everything in a namespace makes it easier for navigating to the correct one, bearing in mind that there are multiple forms with the same names. Sorry I didn't explain that before. – Ali Hamza Oct 26 '14 at 16:43

1 Answers1

0

I figured the problem out! The problem is, I have a flowlayoutpanel on the MDI Parent form, and that is in the foreground, leaving the MDI children to show up in the background. Is there any way where the FlowLayoutPanel is NOT in the way of the MDI children?

Thanks, Hamza Ali

Ali Hamza
  • 1
  • 2