0

I have a panel, lets says this panel is 500px in height. Inside that panel is a multiline textbox, which is bigger than the panel - let's says the height is 1000px.

The panel is set so that the scroll bar appears, and it scrolls fine with the mouse wheel and by dragging the scroll bar. However, When selecting text in the textbox (highlighting) and then dragging the selection beyond the displayed text it does not scroll, but I want it to. Much like when you select text in a browser beyond what is visible.

It is probably worth noting that my panel is customized, although not much, I have simply added the following code to prevent an issue with setting focus on the textbox, which causes it to scroll to the bottom:

class PanelNoScrollOnFocus : Panel
{
    protected override System.Drawing.Point ScrollToControl(Control activeControl)
    {
        return DisplayRectangle.Location;
    }
}

I got this code from here, so you can see more info about why I am using it if need be.

Community
  • 1
  • 1
musefan
  • 47,875
  • 21
  • 135
  • 185
  • It's because you mouse movement is in the `textbox` not your `panel`, can you just use the `scrollbar` of the `textbox`? – Bolu Jun 18 '13 at 10:53
  • @Bolu: Of course I can use it, but it's not really an expected behavior. I can live with it for now though. The main reason for doing it is for better support when copying text. No rush, I can let this question stew for a bit and see if anything comes back – musefan Jun 18 '13 at 11:05

1 Answers1

0

You can try this :

public Form1()
{
    InitializeComponent();
    textBox1.MouseWheel += textBox1_MouseWheel;
    panel1.KeyDown += panel1_KeyDown;
}

void panel1_KeyDown(object sender, KeyEventArgs e)
{
    textBox1.Focus();
}

void textBox1_MouseWheel(object sender, MouseEventArgs e)
{
    panel1.Focus();
}
SerkanOzvatan
  • 231
  • 1
  • 5
  • This does not work. Perhaps you misunderstood my question, as I already have mouse scrolling working when the textbox is selected – musefan Jun 18 '13 at 12:31