滑动面板
Sliding the Panel
我正在使用 WinForms。在我的表单中,我有一个按钮和一个面板。当我单击该按钮时,我想将面板向右滑动。我的代码有问题。目前我在下面收到红色错误行
= panel2.Location.X + 1;
Error Message: Cannot implicitly convert type int to System.Drawing.Point
我试图通过扩大面板来移动面板。我在我的代码中提供了这一点。如何移动面板?
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;
}
}
您收到错误消息,因为您尝试使用整数设置位置。您将需要一个新的点实例:
panel2.Location = new Point(panel2.Location.X, panel2.Location.Y + 1);
尝试使用 .Left 而不是 .Location.X
这适用于 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
我很惊讶它是光滑的,但是面板是空的。
我正在使用 WinForms。在我的表单中,我有一个按钮和一个面板。当我单击该按钮时,我想将面板向右滑动。我的代码有问题。目前我在下面收到红色错误行
= panel2.Location.X + 1;
Error Message: Cannot implicitly convert type int to System.Drawing.Point
我试图通过扩大面板来移动面板。我在我的代码中提供了这一点。如何移动面板?
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;
}
}
您收到错误消息,因为您尝试使用整数设置位置。您将需要一个新的点实例:
panel2.Location = new Point(panel2.Location.X, panel2.Location.Y + 1);
尝试使用 .Left 而不是 .Location.X
这适用于 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
我很惊讶它是光滑的,但是面板是空的。