Jelytin

I have a split container with a Panel2 that needs to scroll. In order to avoid smearing the controls, I'd like to override WndProc for Panel2, but the SplitterPanel class is sealed. Is there a way for me to work around this besides putting a panel within Panel2

Re: Windows Forms General Overriding WndProc for a SplitterPanel

Andreas Johansson

I am not sure if there might be another solution for your situation but you can always create a message filter and add it to the application object. In the message filter you can see if the message is for the handle of the SplitterPanel and do what you want with that message.




Re: Windows Forms General Overriding WndProc for a SplitterPanel

Zhi-Xin Ye - MSFT

And a sample code for you:

Code Snippet

public partial class Form2 : Form,IMessageFilter

{

public Form2()

{

InitializeComponent();

}

private void Form2_Load(object sender, EventArgs e)

{

Application.AddMessageFilter(this);

}

private const int WM_LBUTTONDOWN = 0x0201;

public bool PreFilterMessage(ref Message m)

{

if (m.Msg == WM_LBUTTONDOWN)

{

if (m.HWnd == this.splitContainer1.Panel2.Handle)

{

MessageBox.Show("Click on panel2");

return true;

}

}

return false ;

}

}