I want to load books from a database to a FlowLayoutPanel in a Forms app
(this part works fine), but if I enable autoscroll the scroll bar appears, but only for a split second when the library databse is loading into the flowLayoutPanel and then its not scrollable.
Here is the code that fills in the books into the flowLayoutPanel:
private Panel CreateBookPanel(Book book)
{
Panel bookPanel = new Panel
{
Width = 200,
Height = 250,
Margin = new Padding(10),
BorderStyle = BorderStyle.FixedSingle,
Tag = book // Store the book object for easy retrieval
};
bookPanel.Click += BookPanel_Click;
PictureBox coverPictureBox = new PictureBox
{
Width = 180,
Height = 120,
SizeMode = PictureBoxSizeMode.Zoom,
Dock = DockStyle.Top,
};
coverPictureBox.Load(book.ImageURL);
coverPictureBox.Click += BookPanel_Click;
Label titleLabel = new Label
{
Text = book.BookName,
AutoSize = false,
Width = bookPanel.Width,
Height = 40,
TextAlign = ContentAlignment.MiddleCenter,
Dock = DockStyle.Top
};
titleLabel.Click += BookPanel_Click;
Label authorLabel = new Label
{
Text = "Author: " + book.AuthorName,
AutoSize = false,
Width = bookPanel.Width,
Height = 20,
TextAlign = ContentAlignment.MiddleCenter,
Dock = DockStyle.Top
};
authorLabel.Click += BookPanel_Click;
bookPanel.Controls.Add(coverPictureBox);
bookPanel.Controls.Add(titleLabel);
bookPanel.Controls.Add(authorLabel);
return bookPanel;
}
Screenshot of the app:
I tried adding the scroll bar separately and linking it to the flowLayoutPanel somehow, but it did not help at all.
3