После очистки статей в Интернете я придумал этот дизайн для сенсорного экрана на основе winforms, для которого требуется смартфон, например, прокрутка. Само приложение будет работать на планшетном ноутбуке или рабочем столе с сенсорным экраном.
- Я помещаю все, что я хочу прокрутить на панели.
- Установите autoscroll в значение true (которое отобразит полосы прокрутки)
- Теперь поместите всю эту панель внутри группового ящика
- Сжимайте групповой ящик до тех пор, пока полосы прокрутки не будут скрыты (визуально скрыты, не видны = false)
Теперь интересная часть, на которую я застрял. Я думаю, что мне нужно обработать мышь, мышь и мусмове на панели, чтобы установить автопрокрутку, чтобы, когда кто-то касается панели и перетаскивает ее, она прокручивает магию. Пожалуйста, помогите заполнить несколько строк кода ниже в методах. msdn doc в autoscrollposition очень запутан, так как он возвращает отрицательные числа, но должен быть установлен положительным с абс, а что нет.
Point mouseDownPoint;
Point mouseUpPoint;
Point mouseDragPoint;
private void myPanel_MouseDown(object sender, MouseEventArgs e)
{
this.mouseDownPoint = e.Location;
Console.WriteLine("Mouse down at {0}", e.location);
}
private void myPanel_MouseUp(object sender, MouseEventArgs e)
{
this.mouseUpPoint = e.Location;
this.mouseDownPoint = new Point(); //will set for IsEmpty check
Console.WriteLine("Mouse Up at {0}", e.location);
}
private void myPanel_MouseMove(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse at {0}", e.location);
if (mouseDownPoint.IsEmpty()) //finger is off the touchscreen
return;
myPanel.Autocrollposition = ??
}
Благодарю вас
//UPDATE - Ниже я имею пробный и ошибочный рабочий и проверенный код. (не рефакторинг). Если у кого-то есть более элегантное решение, отправьте сообщение.
Point mouseDownPoint;
private void innerpanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
this.mouseDownPoint = e.Location;
}
private void innerpanel_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
if ((mouseDownPoint.X == e.Location.X) && (mouseDownPoint.Y == e.Location.Y))
return;
Point currAutoS = innerpanel.AutoScrollPosition;
if (mouseDownPoint.Y > e.Location.Y)
{
//finger slide UP
if (currAutoS.Y != 0)
currAutoS.Y = Math.Abs(currAutoS.Y) - 5;
}
else if (mouseDownPoint.Y < e.Location.Y)
{
//finger slide down
currAutoS.Y = Math.Abs(currAutoS.Y) + 5;
}
else
{
currAutoS.Y = Math.Abs(currAutoS.Y);
}
if (mouseDownPoint.X > e.Location.X)
{
//finger slide left
if (currAutoS.X != 0)
currAutoS.X = Math.Abs(currAutoS.X) - 5;
}
else if (mouseDownPoint.X < e.Location.X)
{
//finger slide right
currAutoS.X = Math.Abs(currAutoS.X) + 5;
}
else
{
currAutoS.X = Math.Abs(currAutoS.X);
}
innerpanel.AutoScrollPosition = currAutoS;
mouseDownPoint = e.Location; //IMPORTANT
}