Announcement

Collapse
No announcement yet.

Panel horizontal scrollen - unerwartetes verhalten

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Panel horizontal scrollen - unerwartetes verhalten

    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

  • #2
    Hallo nochmal,

    ich muss doch noch mal nachfragen: Hat niemand jemals dieses Problem beobachtet oder hat niemand jemals eine Lösung gefunden?

    luker

    Comment

    Working...
    X