我创建了一个WinForm,该WinForm的使用类似于工具栏,并且可以粘贴在屏幕的两侧。 为了粘贴工具栏,我有一个粘贴按钮,用户可以选择上/右/下/左。 我正在计算高度或宽度,并将工具栏放在中心。 设置好位置后,它会滑出屏幕:
1)计算将值移动到像素所需的时间。
2)在0.1秒后启动计时器以设置其新位置,同时添加要移动的像素。
3)仅在屏幕上还有2个像素时停止。
4)当我将鼠标悬停在2个像素上时,它会滑入。
即使有2个屏幕,它也可以完美运行! 问题是,当我有2个屏幕并且将工具栏粘贴在它们之间的一侧时,工具栏消失了。
我检查了工具栏的位置,它仍然在屏幕内,但我看不到它。 我注意到当它到达屏幕上的-90 x位置时会发生这种情况。
我确实尝试刷新WinForm,甚至还想禁用此选项,但我不知道如何检查这一面是否是它们之间的边界。
我将不胜感激,可以提供任何帮助或提示。 如果您有任何疑问,请询问,我会尽力解释。
这是我的滑动功能(与计时器配合使用):
private void _timer_Tick(object sender, EventArgs e)
{
int xPos = this.Location.X;
int yPos = this.Location.Y;
Screen myScreen = Screen.FromControl(this);
int ScreenW = myScreen.Bounds.Width;
int ScreenHWA = myScreen.WorkingArea.Height;
int ScreenH = myScreen.Bounds.Height;
if (_slidingOut && !pinFormPopup.Visible)
{
// sliding out
switch (this.pinned)
{
case "u":
if (yPos > SLIDING_STEP - this.Height)
{
yPos -= SLIDING_STEP;
}
else
{
yPos = myScreen.Bounds.Top + 2 - this.Height;
_animateTimer.Enabled = false;
}
break;
case "l":
if (xPos > 2 + SLIDING_STEP + myScreen.Bounds.Left - this.Width)
{
xPos -= SLIDING_STEP;
}
else
{
xPos = myScreen.Bounds.Left + 2 - this.Width;
_animateTimer.Enabled = false;
}
break;
case "d":
if (yPos < myScreen.Bounds.Bottom - SLIDING_STEP - 5)
{
yPos += SLIDING_STEP;
}
else
{
yPos = myScreen.Bounds.Bottom -5;
_animateTimer.Enabled = false;
}
break;
case "r":
if (xPos < myScreen.Bounds.Right - 2 - SLIDING_STEP)
{
xPos += SLIDING_STEP;
}
else
{
xPos = myScreen.Bounds.Right - 2;
_animateTimer.Enabled = false;
}
break;
}
}
else
{
// sliding in
switch (this.pinned)
{
case "u":
if (yPos + SLIDING_STEP < myScreen.Bounds.Top)
{
yPos += SLIDING_STEP;
}
else
{
yPos = myScreen.Bounds.Top;
_animateTimer.Enabled = false;
}
break;
case "l":
if (xPos + SLIDING_STEP < myScreen.Bounds.Left)
{
xPos += SLIDING_STEP;
}
else
{
xPos = myScreen.Bounds.Left;
_animateTimer.Enabled = false;
}
break;
case "d":
if (yPos > myScreen.Bounds.Bottom - this.Height + SLIDING_STEP + 4)
{
yPos -= SLIDING_STEP;
}
else
{
yPos = myScreen.Bounds.Bottom - this.Height;
_animateTimer.Enabled = false;
}
break;
case "r":
if (xPos > ScreenW - this.Width + SLIDING_STEP)
{
xPos -= SLIDING_STEP;
}
else
{
xPos = ScreenW - this.Width;
_animateTimer.Enabled = false;
}
break;
}
}
if (!_animateTimer.Enabled)
{
if (!this.isToolbarOnScrenn())
{
Console.Write("Could not set to this position, please try another one");
}
}
this.Location = new Point(xPos, yPos);
this.Refresh();
}
它应该如何工作(当向右固定时)到左向的问题。