下午好。 渲染动态创建的面板时出现问题,所有面板最初都是100px,我的渲染(y + = 100),但现在生产有所改变,这些面板可以有不同的尺寸,它们之间的距离也是实际上保持不变100rh ...
Pliz告诉我如何制作它们以某种方式彼此相等(10px)的距离绘制。阅读你可以以某种方式制作方法SetBounds,但不明白。
for (int i = data_list.Count - 1; i >= 0; i--)
{
Panel panel = new Panel(); //создание блока сообщения и наложение картинки
panel.Name = i.ToString();
panel.MouseEnter += new EventHandler(panel_MouseEnter);
Label textBox_name = new Label();
Label textBox_date = new Label();
Label textBox_msg = new Label();
panel.Width = 308;
Bitmap btm_msg = new Bitmap(
Properties.Resources.NotificationCenterWindow_msg_box);
panel.BackgroundImage = btm_msg;
panel.BackgroundImageLayout = ImageLayout.Stretch;
panel.Location = new Point(5, 5);
panel.Controls.Add(textBox_date);
textBox_date.Name = "textBox_date" + i.ToString();
textBox_date.Location = new Point(232, 8);
textBox_date.Size = new System.Drawing.Size(70, 15);
textBox_date.BorderStyle = BorderStyle.None;
textBox_date.MinimumSize = new System.Drawing.Size(72, 15);
textBox_date.TextAlign = ContentAlignment.MiddleRight;
textBox_date.BackColor = Color.DarkGray;
textBox_date.Anchor = AnchorStyles.Right | AnchorStyles.Top;
textBox_date.ForeColor = SystemColors.ScrollBar;
panel.Controls.Add(textBox_name);
textBox_name.Size = new System.Drawing.Size(100, 15);
textBox_name.MinimumSize = new System.Drawing.Size(100, 15);
textBox_name.Location = new Point(5, 8);
textBox_name.BorderStyle = BorderStyle.None;
textBox_name.BackColor = Color.DarkGray;
textBox_name.ForeColor = SystemColors.ScrollBar;
panel.Height = textBox_name.Height + 19;
panel1.Controls.Add(panel);
panel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
y += 100;
}
答案 0 :(得分:0)
只需根据上一个面板设置位置......
// This will put the panel to the right of an existing one
panel_b.Left = panel_a.Left + panel_a.Width + 10;
// This will put the panel below an existing one
panel_b.Top= panel_a.Top+ panel_a.Height+ 10;
答案 1 :(得分:0)
panel.Location = new Point(5, y);
//.....
y = panel.Bottom + 10;