Sliding windows?

I like the flat look of the Visual Studio environment, and have been trying to write something that allows 'panels' to dock against a side and particular to 'slide' in and out.

I've tried using the Windows API AnimateWindow, but it only works on forms.
So I tried writing a MDI form with the new forms sliding in and out of the blank space, but you get a window box around the blank area of the parent form.

Any ideas how this might be done?
LVL 4
broadbentAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DCDConnect With a Mentor Commented:
Don't worry about that...it's a hotkey component that I use to assign system wide hot keys (like ctrl + P) to my apps.

Regards
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
broadbentAuthor Commented:
Doesn't help, because there is a whole solution written in C, and it is difficult to get to grips with it.

Can you at least point me to the area I need to be looking at.
Is this Windows API?
Is this a clever MDI without borders?
There seems to be a timer at work, but does this involve redraws?

Thanks again.
Thanks for your previous help.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
DCDCommented:
For the slide it is real easy:
Add a timer to your form
On the click method of a button (whatever) enable the timer
On the timer_tick method move your item in increments:

'Assumes that Panel1 is shifted to the left of the form edge
Dim XPos as Integer
XPos = Me.Left  'Set XPos to the left of the form

Panel1.Left += 2 'Move the panel to the right by 2
If Panel1.Left >= XPos Then Timer1.Enabled = False 'If the left edge of the panel hits the left edge of the form, turn the timer off.

The docking is a little more engaging, but can be done. You have to do a lot of checks. See this site: http://www.divil.co.uk/

Regards
0
 
broadbentAuthor Commented:
Sorry, but the form looks awful when moving.
0
 
DCDCommented:
Use a panel instead of a form...Also adjust the timer count and the increment. Depending on how you set it, the movement is smooth.
0
 
broadbentAuthor Commented:
I've been trying to do this without much success. Redrawing the controls etc. takes too long for it to work neatly. AnimateWindow API does it neatly, but it only works on forms.
0
 
DCDCommented:
Below is posted code from a test app I threw together. I was using hot keys (adding labels) to slide in/out the panel (in the window's generated code it was called "nicepanel1".
The form has two timers a panel and a few buttons. Look it over and see how the slide effect happens.


Imports SySWideHotKey.Components.HotKey

Public Class Form1
    Inherits SySWideHotKey.Components.HotKey.HotKeyForm

#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 NicePanel1 As PureComponents.NicePanel.NicePanel
    Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
    Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
    Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
    Friend WithEvents Timer1 As System.Windows.Forms.Timer
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Timer2 As System.Windows.Forms.Timer
    Friend WithEvents lblRight As System.Windows.Forms.Label
    Friend WithEvents lblLeft As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button3 As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim ContainerImage1 As PureComponents.NicePanel.ContainerImage = New PureComponents.NicePanel.ContainerImage
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Dim HeaderImage1 As PureComponents.NicePanel.HeaderImage = New PureComponents.NicePanel.HeaderImage
        Dim HeaderImage2 As PureComponents.NicePanel.HeaderImage = New PureComponents.NicePanel.HeaderImage
        Dim PanelStyle1 As PureComponents.NicePanel.PanelStyle = New PureComponents.NicePanel.PanelStyle
        Dim ContainerStyle1 As PureComponents.NicePanel.ContainerStyle = New PureComponents.NicePanel.ContainerStyle
        Dim PanelHeaderStyle1 As PureComponents.NicePanel.PanelHeaderStyle = New PureComponents.NicePanel.PanelHeaderStyle
        Dim PanelHeaderStyle2 As PureComponents.NicePanel.PanelHeaderStyle = New PureComponents.NicePanel.PanelHeaderStyle
        Me.NicePanel1 = New PureComponents.NicePanel.NicePanel
        Me.lblLeft = New System.Windows.Forms.Label
        Me.TabControl1 = New System.Windows.Forms.TabControl
        Me.TabPage1 = New System.Windows.Forms.TabPage
        Me.TabPage2 = New System.Windows.Forms.TabPage
        Me.lblRight = New System.Windows.Forms.Label
        Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Timer2 = New System.Windows.Forms.Timer(Me.components)
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button3 = New System.Windows.Forms.Button
        Me.NicePanel1.SuspendLayout()
        Me.TabControl1.SuspendLayout()
        Me.SuspendLayout()
        '
        'NicePanel1
        '
        Me.NicePanel1.BackColor = System.Drawing.Color.Transparent
        ContainerImage1.Alignment = System.Drawing.ContentAlignment.MiddleLeft
        ContainerImage1.ClipArt = PureComponents.NicePanel.ImageClipArt.None
        ContainerImage1.Image = CType(resources.GetObject("ContainerImage1.Image"), System.Drawing.Image)
        ContainerImage1.Size = PureComponents.NicePanel.ContainerImageSize.Small
        ContainerImage1.Transparency = 0
        Me.NicePanel1.ContainerImage = ContainerImage1
        Me.NicePanel1.ContextMenuButton = False
        Me.NicePanel1.Controls.Add(Me.lblLeft)
        Me.NicePanel1.Controls.Add(Me.TabControl1)
        Me.NicePanel1.Controls.Add(Me.lblRight)
        HeaderImage1.ClipArt = PureComponents.NicePanel.ImageClipArt.None
        HeaderImage1.Image = Nothing
        Me.NicePanel1.FooterImage = HeaderImage1
        Me.NicePanel1.FooterText = "Control Panel"
        Me.NicePanel1.ForeColor = System.Drawing.Color.Black
        HeaderImage2.ClipArt = PureComponents.NicePanel.ImageClipArt.ControlPanel
        HeaderImage2.Image = Nothing
        Me.NicePanel1.HeaderImage = HeaderImage2
        Me.NicePanel1.HeaderText = "UNWD Viewer"
        Me.NicePanel1.IsExpanded = True
        Me.NicePanel1.Location = New System.Drawing.Point(0, 0)
        Me.NicePanel1.MouseMoveTarget = PureComponents.NicePanel.MouseMoveTarget.Self
        Me.NicePanel1.Name = "NicePanel1"
        Me.NicePanel1.OriginalFooterVisible = True
        Me.NicePanel1.OriginalHeight = 0
        Me.NicePanel1.Size = New System.Drawing.Size(328, 392)
        ContainerStyle1.BackColor = System.Drawing.Color.WhiteSmoke
        ContainerStyle1.BaseColor = System.Drawing.Color.Transparent
        ContainerStyle1.BorderColor = System.Drawing.Color.Gray
        ContainerStyle1.BorderStyle = PureComponents.NicePanel.BorderStyle.Double
        ContainerStyle1.CaptionAlign = PureComponents.NicePanel.CaptionAlign.Left
        ContainerStyle1.FadeColor = System.Drawing.Color.Gainsboro
        ContainerStyle1.FillStyle = PureComponents.NicePanel.FillStyle.DiagonalForward
        ContainerStyle1.FlashItemBackColor = System.Drawing.Color.Red
        ContainerStyle1.FocusItemBackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(255, Byte), CType(255, Byte))
        ContainerStyle1.Font = New System.Drawing.Font("Segoe UI", 7.8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        ContainerStyle1.ForeColor = System.Drawing.Color.Black
        ContainerStyle1.Shape = PureComponents.NicePanel.Shape.Rounded
        PanelStyle1.ContainerStyle = ContainerStyle1
        PanelHeaderStyle1.BackColor = System.Drawing.Color.Gray
        PanelHeaderStyle1.ButtonColor = System.Drawing.Color.FromArgb(CType(172, Byte), CType(191, Byte), CType(227, Byte))
        PanelHeaderStyle1.FadeColor = System.Drawing.Color.LightGray
        PanelHeaderStyle1.FillStyle = PureComponents.NicePanel.FillStyle.HorizontalFading
        PanelHeaderStyle1.FlashBackColor = System.Drawing.Color.FromArgb(CType(243, Byte), CType(122, Byte), CType(1, Byte))
        PanelHeaderStyle1.FlashFadeColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(215, Byte), CType(159, Byte))
        PanelHeaderStyle1.FlashForeColor = System.Drawing.Color.White
        PanelHeaderStyle1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!)
        PanelHeaderStyle1.ForeColor = System.Drawing.Color.Gainsboro
        PanelHeaderStyle1.Size = PureComponents.NicePanel.PanelHeaderSize.Small
        PanelStyle1.FooterStyle = PanelHeaderStyle1
        PanelHeaderStyle2.BackColor = System.Drawing.Color.Silver
        PanelHeaderStyle2.ButtonColor = System.Drawing.Color.Gainsboro
        PanelHeaderStyle2.FadeColor = System.Drawing.Color.FromArgb(CType(51, Byte), CType(51, Byte), CType(51, Byte))
        PanelHeaderStyle2.FillStyle = PureComponents.NicePanel.FillStyle.VerticalFading
        PanelHeaderStyle2.FlashBackColor = System.Drawing.Color.FromArgb(CType(243, Byte), CType(122, Byte), CType(1, Byte))
        PanelHeaderStyle2.FlashFadeColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(215, Byte), CType(159, Byte))
        PanelHeaderStyle2.FlashForeColor = System.Drawing.Color.White
        PanelHeaderStyle2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold)
        PanelHeaderStyle2.ForeColor = System.Drawing.Color.WhiteSmoke
        PanelHeaderStyle2.Size = PureComponents.NicePanel.PanelHeaderSize.Medium
        PanelStyle1.HeaderStyle = PanelHeaderStyle2
        Me.NicePanel1.Style = PanelStyle1
        Me.NicePanel1.TabIndex = 3
        '
        'lblLeft
        '
        Me.lblLeft.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lblLeft.Image = CType(resources.GetObject("lblLeft.Image"), System.Drawing.Image)
        Me.lblLeft.Location = New System.Drawing.Point(0, 136)
        Me.lblLeft.Name = "lblLeft"
        Me.lblLeft.Size = New System.Drawing.Size(16, 120)
        Me.lblLeft.TabIndex = 8
        '
        '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.Controls.Add(Me.TabPage1)
        Me.TabControl1.Controls.Add(Me.TabPage2)
        Me.TabControl1.HotTrack = True
        Me.TabControl1.Location = New System.Drawing.Point(16, 48)
        Me.TabControl1.Name = "TabControl1"
        Me.TabControl1.SelectedIndex = 0
        Me.TabControl1.Size = New System.Drawing.Size(296, 320)
        Me.TabControl1.TabIndex = 2
        '
        'TabPage1
        '
        Me.TabPage1.BackColor = System.Drawing.Color.WhiteSmoke
        Me.TabPage1.ForeColor = System.Drawing.Color.Transparent
        Me.TabPage1.Location = New System.Drawing.Point(4, 27)
        Me.TabPage1.Name = "TabPage1"
        Me.TabPage1.Size = New System.Drawing.Size(288, 289)
        Me.TabPage1.TabIndex = 0
        Me.TabPage1.Text = "TabPage1"
        '
        'TabPage2
        '
        Me.TabPage2.Location = New System.Drawing.Point(4, 25)
        Me.TabPage2.Name = "TabPage2"
        Me.TabPage2.Size = New System.Drawing.Size(288, 291)
        Me.TabPage2.TabIndex = 1
        Me.TabPage2.Text = "TabPage2"
        Me.TabPage2.Visible = False
        '
        'lblRight
        '
        Me.lblRight.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblRight.Image = CType(resources.GetObject("lblRight.Image"), System.Drawing.Image)
        Me.lblRight.Location = New System.Drawing.Point(312, 136)
        Me.lblRight.Name = "lblRight"
        Me.lblRight.Size = New System.Drawing.Size(16, 120)
        Me.lblRight.TabIndex = 7
        '
        'Timer1
        '
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(424, 312)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 32)
        Me.Button1.TabIndex = 4
        Me.Button1.Text = "Button1"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(424, 360)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(80, 32)
        Me.Button2.TabIndex = 5
        Me.Button2.Text = "Button2"
        '
        'Timer2
        '
        Me.Timer2.Interval = 10
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(392, 40)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(280, 248)
        Me.TextBox1.TabIndex = 6
        Me.TextBox1.Text = "TextBox1"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(424, 408)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 7
        Me.Button3.Text = "Button3"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 18)
        Me.ClientSize = New System.Drawing.Size(720, 496)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.NicePanel1)
        Me.Font = New System.Drawing.Font("Segoe UI", 7.8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.NicePanel1.ResumeLayout(False)
        Me.TabControl1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim XPos As Integer, YPos As Integer

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

        XPos = NicePanel1.Left
            Panel1.Left = -400
        Timer1.Interval = 1

        ' add an event handler for hot key pressed (or could just use Handles)
        AddHandler Me.HotKeyPressed, AddressOf hotKey_Pressed

        ' set the hotkey:
        Dim htk As HotKey = New HotKey("Show Panel", Keys.PageUp, HotKey.HotKeyModifiers.MOD_CONTROL)
        Me.HotKeys.Add(htk)

        Dim htk2 As HotKey = New HotKey("Hide Panel", Keys.PageDown, HotKey.HotKeyModifiers.MOD_CONTROL)
        Me.HotKeys.Add(htk2)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Panel1.Left += 2
        If Panel1.Left >= XPos Then Timer1.Enabled = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer2.Enabled = True
    End Sub

    Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
            Panel1.Left -= 2
        If Panel1.Left = -400 Then Timer2.Enabled = False
    End Sub

    Private Sub hotKey_Pressed(ByVal sender As System.Object, ByVal e As HotKeyPressedEventArgs)
        If e.HotKey.Name Is "Show Panel" Then
            If Timer2.Enabled = False Then
                Timer1.Enabled = True
            Else
                Timer2.Enabled = False
                Timer1.Enabled = True
            End If
        End If
        If e.HotKey.Name Is "Hide Panel" Then
            If Timer1.Enabled = False Then
                Timer2.Enabled = True
            Else
                Timer1.Enabled = False
                Timer2.Enabled = True
            End If
        End If
    End Sub

    Private Sub lblLeft_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblLeft.Click

    End Sub

    Private Sub lblRight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblRight.Click
        If Timer1.Enabled = False Then
            Timer2.Enabled = True
        Else
            Timer1.Enabled = False
            Timer2.Enabled = True
        End If
    End Sub

    Private Sub Panel1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
        If Panel1.Left + 25 > Me.Width Then
                Panel1.Left = Me.Width - Panel1.Width + 5
            Exit Sub
        End If
        If Panel1.Left < Me.Left Then
                Panel1.Left = Me.Left
            Exit Sub
        End If

        If Panel1.Top < Me.Bottom Then
                 Panel1.Top = Me.Bottom - Panel1.Height
            Exit Sub
        End If
    End Sub


   
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub
End Class
0
 
broadbentAuthor Commented:
what's Imports SySWideHotKey.Components.HotKey?
0
 
broadbentAuthor Commented:
It works fine on simple forms, but where forms need a lot of repainting???
0
All Courses

From novice to tech pro — start learning today.