Sliding windows?

Posted on 2005-03-15
Medium Priority
Last Modified: 2007-12-19
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?
Question by:broadbent
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
  • 5
  • 4

Author Comment

ID: 13554041
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.

Expert Comment

ID: 13556177
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/

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.


Author Comment

ID: 13557801
Sorry, but the form looks awful when moving.

Expert Comment

ID: 13558819
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.

Author Comment

ID: 13586172
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.

Expert Comment

ID: 13593603
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()

        'This call is required by the Windows Form Designer.

        '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
            End If
        End If
    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.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
        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
        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
        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.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
        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"
        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
        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
        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"
        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"
        Me.Timer2.Interval = 10
        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"
        Me.Button3.Location = New System.Drawing.Point(424, 408)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 7
        Me.Button3.Text = "Button3"
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 18)
        Me.ClientSize = New System.Drawing.Size(720, 496)
        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"

    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)

        Dim htk2 As HotKey = New HotKey("Hide Panel", Keys.PageDown, HotKey.HotKeyModifiers.MOD_CONTROL)
    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
                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
                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
            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
    End Sub
End Class

Author Comment

ID: 13610128
what's Imports SySWideHotKey.Components.HotKey?

Accepted Solution

DCD earned 375 total points
ID: 13616076
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.


Author Comment

ID: 13616954
It works fine on simple forms, but where forms need a lot of repainting???

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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