Quantcast
Viewing all articles
Browse latest Browse all 12583

What's the code for a void that generates panels? [C# 2013]

Salut!

How do you create a panel via code? I've been searching many articles about this but all they answer would be creating pictureboxes. When I do try to change some variables, I fail. Here's an example of a failed attempt;

        public void loadblock2(Point Location1, String Type, String Name)        {                var Xp = blockm(Location1.X);                var Yp = blockm(Location1.Y);                var Location = new Point();                var OPSize = new Size();                Location.X = Xp;                Location.Y = Yp;                OPSize.Height = 30;                OPSize.Width = 30;                var pbName = new Panel();                pbName.Size = OPSize;                pbName.Location = Location;                pbName.BackgroundImage = Super_Mario_Plus.Properties.Resources.NEWY;                pbName.BackgroundImageLayout = ImageLayout.Stretch;                pbName.Parent = this.panel1;        }


So, this fails.

To make things narrower, I was intending loadblock2 to be reusable, thus every time it would be executed, It would display a new panel. For example, run 50 times, creates 50 panels.

Thanks!
Grass Dinosaur


Viewing all articles
Browse latest Browse all 12583

Trending Articles