1

I'm trying to add a scrollable list of buttons inside a panel from C# scripting inside Visual Studio.

I can make the scrollbar and attach it to a panel and manually add buttons inside the panel from the UI but I want to code for the entire panel along with scrollbar and create buttons inside that newly created panel.

Can anyone help me with this?

In Unity I can use the OnGUI function and use the GUI class to add these features but I dont know how to do that in Winform application.

1 Answer 1

8

if you are trying to achieve somethings like this  Here then just create a flowLayout pannel and Just add buttons to the flowlayout pannel and set the Autoscroll property of the flowlayout to true.

for (int i = 0; i < 19; i++)
{
  Button b = new Button();
  b.Text = "b" + i;
  flowLayoutPanel1.Controls.Add(b);
}

and set the autoscroll property for the flowlayoutpannel.

flowLayoutPanel1.AutoScroll = true;
Sign up to request clarification or add additional context in comments.

5 Comments

yh thats exactly what im looking for. just one more questions: do i have to declare and initialize the flowLayoutPanel1 property outside of the for loop first? Cause it looks like you set the autoscroll property outside of the for loop.
thanks yu made it very simple and easy to understand. However I'm now thinking about the response function for each newly created button. From the script, how would I check which newly button is clicked and create a response function that would respond to that click only? Sorry for all this trouble
Then you have all your button object in the flowlayoutpannel and from there u can list to the button click event's
@MarkJackson has it worked for you if its worked then mark it as answer and do a upvote so that it will be helpful for other users
oh sorry it worked. I'm new to this statckoverflow system so I didn't know that lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.