Greetings fellow developers i just want to ask for help on how to slide the panel from right to left of the screen. I only know the sliding panel from left-to-right but is it possible to slide the panel from right-to-left?

Dani AI

Generated

correctly pointed out that the panel must be repositioned while it changes size, and 's boundary check prevents it from moving off the form. A tighter, more responsive solution is to avoid a blocking Do While loop and animate with a UI Timer (or an async loop with Task.Delay). The Timer keeps the UI responsive, makes the motion smooth, and makes it easy to tune speed and bounds.

' Place this in the form (slideTimer can be a designer Timer or created in code)
Private WithEvents slideTimer As New System.Windows.Forms.Timer()
Private ReadOnly slideTargetX As Integer = 20
Private ReadOnly slideStep As Integer = 8

Private Sub StartSlideFromRight()
    Panel1.Left = Me.ClientSize.Width            ' start off the right edge
    Panel1.Visible = True
    slideTimer.Interval = 16                     ' ~60 FPS = 16ms; increase for slower motion
    slideTimer.Start()
End Sub

Private Sub slideTimer_Tick(sender As Object, e As EventArgs) Handles slideTimer.Tick
    Dim nextLeft = Math.Max(slideTargetX, Panel1.Left - slideStep)
    Panel1.Left = nextLeft
    If Panel1.Left <= slideTargetX Then slideTimer.Stop()
End Sub

Notes: keep slideStep and Interval tuned for desired smoothness. If the goal is to expand from right to left while keeping the right edge fixed, increase Width and set Left = fixedRight - Width each tick. Avoid Do While loops without yielding (they freeze the UI). For ASP.NET (web) do the animation client-side with CSS transitions or JavaScript rather than server-side code. Consider double-buffering or SuspendLayout/ResumeLayout for complex UIs to reduce flicker.

Recommended Answers

All 5 Replies

When you say sliding the panel, do you mean in the parent control or the scroll bar of the panel?

In the parent control. like this for example

private slide_in()
do while panel1.width < 730
panel1.width += 1
loop

like this code but it only grows it's width from left-

If you are only wanting to increase the width (on the left) you will have to reposition the panel on resize to give the user the illusion it is only increasing the width on the left.

For exmaple:

Do While Panel1.Width < 730
    Panel1>Width += 1
    Panel1.Location = New Point(Panel1.Location.X - 1, Panel1>Location.Y)
Loop

You might want to consider a further check that X doesn't go less than zero. Something like:

Do While Panel1.Width < 730 andalso Panel1.Location.X > 0
commented: Very true! :) +8

Thank you sir! it worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.