I have a Custom panel which contains 4 labels (in example pasted, I have erased definition of those 2 I didn't used). This custom panel is added to a panel dynamically, as many records I have in an array. The parent panel, has the Horizontal scroll enabled = false, as I should scroll only vertically. Everything works fine, as I can use mouse on vertical scrollbar and I can scroll the panel container. But when I want to use mouse wheel to scroll all the custom panels (child objects) it does not do anything. I have tried many of the solutions that works for other on this site, but none of them works for me and I don't know why.
I read about the panel has to have focus to be able to scroll, and I will have to pass the OnMouseWheel event to parent, in child. But I am not able to do it, I don't know how to do it.
my custom panel (child):
public class PlaylistRecords : Panel
{
public Label lblRecordNumber { get; private set; }
private Label lblRecordName;
public static int RecordNumber { get; set; }
public static String RecordName { get; set; }
public PlaylistRecords(
int RecordNumber,
String RecordName
)
{
InitializeComponent();
this.Size = new System.Drawing.Size(800,50);
this.BackColor = System.Drawing.Color.FromArgb(20,20,20);
PlaylistRecords.RecordNumber = RecordNumber;
PlaylistRecords.RecordName = RecordName;
this.lblRecordNumber.Text = PlaylistRecords.RecordNumber.ToString()+".";
this.lblRecordName.Text = PlaylistRecords.RecordName;
this.lblRecordNumber.Location = new System.Drawing.Point(2, (int)(this.Height - this.lblRecordNumber.Height) / 2);
this.lblRecordName.Location = new System.Drawing.Point(
this.lblRecordNumber.Location.X+ this.lblRecordNumber.Width+2,
(int)(this.Height - this.lblRecordName.Height) / 2);
}
private void InitializeComponent()
{
this.lblRecordNumber = new myLabel();
this.lblRecordName = new myLabel();
this.lblRegistPath = new myLabel();
this.SuspendLayout();
//
// lblRecordNumber
//
this.lblRecordNumber.Name = "lblRecordNumber";
this.lblRecordNumber.Size = new System.Drawing.Size(50, 23);
//
// lblRecordName
//
this.lblRecordName.Name = "lblRecordName";
this.lblRecordName.Size = new System.Drawing.Size(150, 23);
//
// PlaylistRecords
//
this.Controls.Add(this.lblRecordNumber);
this.Controls.Add(this.lblRecordName);
this.ResumeLayout(false);
}
}