Learning_To_Code
Learning_To_Code

Reputation: 43

Sliding the Panel

I'm using WinForms. In My form i have a button and a panel. When i click on that button i want to slide the panel to the right. I'm having issues with the code. Currently I'm getting red error lines under = panel2.Location.X + 1;

Error Message: Cannot implicitly convert type int to System.Drawing.Point

I was trying to move the panel with the similar approach i did by growing the panel. I provided that in my code. How can i move the panel?

private void btn_Right_Click(object sender, EventArgs e)
{   
    // Make Panel Grow
    //while (panel1.Width < 690)
    //{
    //    panel1.Width = panel1.Width + 1;
    //}

    while (panel2.Location.X < 690)
    {
        panel2.Location = panel2.Location.X + 1;
    }
}

Upvotes: 0

Views: 457

Answers (2)

rheitzman
rheitzman

Reputation: 2297

Try using .Left instead of .Location.X

This works in VB...

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    If sender.text = ">" Then
        Do Until Panel1.Left > Me.Width - 50
            Panel1.Left += 1
        Loop
        sender.text = "<"
    Else
        Panel1.Left = 511
        sender.text = ">"
    End If
End Sub

I'm surprised it is a smooth as it is - panel is empty however.

Upvotes: 0

Christoph Wider
Christoph Wider

Reputation: 66

You get an error because you try to set the location with an integer. You will need a new point instance:

panel2.Location = new Point(panel2.Location.X, panel2.Location.Y + 1);

Upvotes: 4

Related Questions