I'm posting the pertinent code from my form. You'll need to create the following but change whatever you don't like to fit your needs: - form (frmMain) with a MenuStrip at the top and a StatusStrip as the bottom. The default size is 800x600. - panel (pnlEXTRA) with the BackColor set equal to your form's TransparencyKey color. I set the Dock = Fill which makes it 784x518. Making the panel transparent allows you to see through the panel and click through it as well which allows the form to sit around EXTRA and still allow you to click directly in it. - MenuItem (DockSessionToolStripMenuItem) that fires the Dock/Undock session sub - button (btnBringToFront) - this fires off ActivateExtra which just brings focus to the docked Session in the panel. Is useful when EXTRA gets lost behind other windows or is minimized. I refer to the EXTRA object as G.mySess which is a global variable I store in a module. I din't include the code I use to initialize the session object, but you probably already have that. I cut out this code from my form so I hope I gave you all you need. It should give you a general idea to get started though. CODE'I have this enum in another class but you can use it in the form as well 'I did this because the EXTRA object doesn't specify which numbers 'pertain to what window state Public Enum SessionWindowState Minimized = 0 Restore = 1 Maximized = 2 End Enum
Public Class frmMain Public IsDocked As Boolean = False 'These variables are set prior to docking so that if the user undocks EXTRA, 'it will return to it's original location on the screen Private eTop As Integer, eLeft As Integer, eHeight As Integer, eWidth As Integer, eWindowState As SessionWindowState
Private Sub DockSessionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DockSessionToolStripMenuItem.Click DockExtra(Not IsDocked) ActivateExtra() End Sub
Private Sub ActivateExtra() 'Because the form and EXTRA aren't the same application, EXTRA can get 'lost behind other windows at times; this brings it to focus If IsDocked Then If G.mySess.WindowState = SessionWindowState.Minimized Then G.mySess.WindowState = SessionWindowState.Restore End If AppActivate(G.mySess.Name + " - EXTRA! for NetWare") End If End Sub
Private Sub DockExtra(ByVal Dock As Boolean) Try IsDocked = Dock btnBringToFront.Visible = Dock
Select Case Dock Case False With G.mySess If eTop <> 0 AndAlso .WindowState <> SessionWindowState.Minimized AndAlso eTop > 0 Then 'reset EXTRA's size to what it was prior to docking .Top = eTop .Left = eLeft .Height = eHeight .Width = eWidth .WindowState = eWindowState End If
End With
DockSessionToolStripMenuItem.Text = "&Dock Session" Case True GetSessionSize() SizeForm() SizeExtra()
DockSessionToolStripMenuItem.Text = "&Undock Session" End Select Catch ex As Exception
End Try
End Sub
Private Sub GetSessionSize() If Me.Visible = True Then With G.mySess eTop = .Top eLeft = .Left eHeight = .Height eWidth = .Width 'Extra WindowState: 0=Minimized,1=Restore,2=Maximized eWindowState = .WindowState End With End If End Sub
Private Sub SizeExtra() With G.mySess If pnlEXTRA.Height > 0 Then .WindowState = 1 .Top = Me.Top + pnlEXTRA.Top + 29 .Left = Me.Left + pnlEXTRA.Left + 9 .Height = pnlEXTRA.Height .Width = pnlEXTRA.Width + 5 End If End With End Sub
Private Sub frmMain_Move(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Move, MyBase.ResizeEnd If Me.Visible = True AndAlso IsDocked = True AndAlso Me.Top > 0 Then SizeExtra() End If End Sub
Private Sub btnBringToFront_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBringToFront.Click ActivateExtra() End Sub |
|