Hallo Experten,
zuerst wünsche ich allen ein gesegnetes neues Jahr. Auch 2010 hat wieder interessante Aufgaben zu bieten, so wie diese hier.
Ich möchte einem MyPanel:Panel folgendes Verhalten beibringen:
- Mausrad drehen -> vertikales Scrollen
- [Shift] + Mausrad -> horizontales Scrollen
- [Ctrl] + Mausrad -> Zoom
vertikales Scrollen funktioniert mit einem bloßen[highlight=c#]base.OnMouseWheel(e);[/highlight]Meine horizontale Entsprechung sieht so aus:
[highlight=c#]protected override void OnMouseWheel(MouseEventArgs e)
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
m_iMouseWheelDeltaAccumulator += e.Delta;
int iHorizontalPosition = 0;
while (
m_iMouseWheelDeltaAccumulator < -m_iMouseWheelDeltaThreshold
|| m_iMouseWheelDeltaAccumulator > m_iMouseWheelDeltaThreshold
)
{
iHorizontalPosition = HorizontalScroll.Value;
if (m_iMouseWheelDeltaAccumulator < 0)
{
iHorizontalPosition -= m_iMouseWheelDeltaThreshold;
m_iMouseWheelDeltaAccumulator += m_iMouseWheelDeltaThreshold;
}
else if (m_iMouseWheelDeltaAccumulator > 0)
{
iHorizontalPosition += m_iMouseWheelDeltaThreshold;
m_iMouseWheelDeltaAccumulator -= m_iMouseWheelDeltaThreshold;
}
if (iHorizontalPosition < HorizontalScroll.Minimum)
iHorizontalPosition = HorizontalScroll.Minimum;
else if (iHorizontalPosition > HorizontalScroll.Maximum)
iHorizontalPosition = HorizontalScroll.Maximum;
}
HorizontalScroll.Value = iHorizontalPosition;
}[/highlight]Im Ansatz funktioniert das auch. MyPanel scrollt grundsätzlich wie gewünscht. Allerdings verhält sich das horizontale Scrollen nicht ganz nachvollziehbar:
- die Bewegungen von Panel und Scrollbar stimmen nicht überein.
- scrolle ich in der Mitte des Scrollbereichs, ohne die Ränder zu berühren, einige Male je einen Mausradrastpunkt vor und wieder zurück, dann wird die Verschiebung je Rastpunkt erst immer größer, nach ca 10 Rastpunkten wieder kleiner, nach weiteren 10 wieder größer...
Wie wird das üblicherweise "ordentlich" gemacht?
Danke schonmal fürs Interesse,
luker
zuerst wünsche ich allen ein gesegnetes neues Jahr. Auch 2010 hat wieder interessante Aufgaben zu bieten, so wie diese hier.
Ich möchte einem MyPanel:Panel folgendes Verhalten beibringen:
- Mausrad drehen -> vertikales Scrollen
- [Shift] + Mausrad -> horizontales Scrollen
- [Ctrl] + Mausrad -> Zoom
vertikales Scrollen funktioniert mit einem bloßen[highlight=c#]base.OnMouseWheel(e);[/highlight]Meine horizontale Entsprechung sieht so aus:
[highlight=c#]protected override void OnMouseWheel(MouseEventArgs e)
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
{
m_iMouseWheelDeltaAccumulator += e.Delta;
int iHorizontalPosition = 0;
while (
m_iMouseWheelDeltaAccumulator < -m_iMouseWheelDeltaThreshold
|| m_iMouseWheelDeltaAccumulator > m_iMouseWheelDeltaThreshold
)
{
iHorizontalPosition = HorizontalScroll.Value;
if (m_iMouseWheelDeltaAccumulator < 0)
{
iHorizontalPosition -= m_iMouseWheelDeltaThreshold;
m_iMouseWheelDeltaAccumulator += m_iMouseWheelDeltaThreshold;
}
else if (m_iMouseWheelDeltaAccumulator > 0)
{
iHorizontalPosition += m_iMouseWheelDeltaThreshold;
m_iMouseWheelDeltaAccumulator -= m_iMouseWheelDeltaThreshold;
}
if (iHorizontalPosition < HorizontalScroll.Minimum)
iHorizontalPosition = HorizontalScroll.Minimum;
else if (iHorizontalPosition > HorizontalScroll.Maximum)
iHorizontalPosition = HorizontalScroll.Maximum;
}
HorizontalScroll.Value = iHorizontalPosition;
}[/highlight]Im Ansatz funktioniert das auch. MyPanel scrollt grundsätzlich wie gewünscht. Allerdings verhält sich das horizontale Scrollen nicht ganz nachvollziehbar:
- die Bewegungen von Panel und Scrollbar stimmen nicht überein.
- scrolle ich in der Mitte des Scrollbereichs, ohne die Ränder zu berühren, einige Male je einen Mausradrastpunkt vor und wieder zurück, dann wird die Verschiebung je Rastpunkt erst immer größer, nach ca 10 Rastpunkten wieder kleiner, nach weiteren 10 wieder größer...
Wie wird das üblicherweise "ordentlich" gemacht?
Danke schonmal fürs Interesse,
luker
Comment