[英]Drawing dynamic panels C#
Good afternoon. 下午好。 There was a problem with the rendering of dynamically created panel, all panels initially were 100px and I their renders (y + = 100), but now the production has changed a bit, these panels can be of different sizes, and the distance between them actually remains unchanged 100rh ...
动态创建的面板的渲染存在问题,所有面板最初都是100px,我是它们的渲染(y + = 100),但是现在生产有所改变,这些面板可以具有不同的大小,并且它们之间的距离实际上保持不变100rh ...
Pliz tell me how to make, that they are somehow drawn at equal (10px) distances from each other. 普立兹(Pliz)告诉我如何制作,它们以某种方式彼此等距(10px)地绘制。 Read that you can somehow make a method SetBounds, but did not understand.
读到您可以以某种方式创建SetBounds方法,但并不清楚。
http://pastebin.com/TnSuFTti http://pastebin.com/TnSuFTti
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;
}
Just set the position based on the previous panel... 只需根据上一个面板设置位置即可。
// 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;
panel.Location = new Point(5, y);
//.....
y = panel.Bottom + 10;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.