Click here to Skip to main content
16,011,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to create panel one beside another programmatically in loop how can i do that ?
and i dont know how to add background color to that panel

CSS
if (!IsPostBack)
          {
              Panel p = new Panel() {
                  ToolTip="hy",
                  Width=23,
                  Height=55,


              };



          }
Posted

C#
Panel panel = new Panel();
panel.BackColor = System.Drawing.Color.Black;
this.Controls.Add(panel);
 
Share this answer
 
C#
Panel panel1 = new Panel();


Once it is declared, you can access all the properties.
To add the panel to the form you would do something like this.

C#
myform.controls.add(panel1);
 
Share this answer
 
after you instancead this component, use Show() method.

like it:

C#
Panel p = new Panel();
p.Show();
 
Share this answer
 
if (!IsPostBack)
{
for (int i = 0; 2 > i; i++)
{
Panel p = new Panel()
{
ToolTip = "hyderabad",
BackColor = System.Drawing.Color.Crimson,
HorizontalAlign = HorizontalAlign.Center,

CssClass = "Alert Alert-Info"

};

Label label = new Label()
{
Text = "Product Name"


};

Image img = new Image()
{
Height = 171,
CssClass = "image image-circle"
};

p.Controls.Add(img);
p.Controls.Add(label);

Panel2.Controls.Add(p);
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900