0

私は、さらに 6 つのパネル (このパネルの写真の内側) を含む 1 つのパネルを持つ小さなアプリを持っています。ボタンをクリックすると、このパネルは動的にいくつかのパネルを作成し、パネルがこのパネル全体を作成すると、このパネルが点滅します...見た目ですよくない...どうしたらいいのか教えてください。

パネルを作成したサイクルで、ボタンをクリックしてパネルを作成すると、同じ数のパネルが追加されます

for (int i = 0; i < list_afy_add.Count; i++)
{
    Panel main_panel = new Panel();
    main_panel.Name = i.ToString();
    main_panel.Width = 308;
    main_panel.BackColor = Color.Transparent;
    main_panel.Location = new Point(x, y);

    Panel panel = new Panel();
    panel.Name = i.ToString();
    panel.MouseEnter += new EventHandler(panel_MouseEnter);
    panel.Width = 300;
    panel.Location = new Point(3, 5);

    Label textBox_date = new Label();
    panel.Controls.Add(textBox_date);
    textBox_date.Name = "textBox_date" + i.ToString();
    textBox_date.Location = new Point(220, 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.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(208)))), ((int)(((byte)(217)))));
    textBox_date.Anchor = AnchorStyles.Right | AnchorStyles.Top;
    textBox_date.ForeColor = SystemColors.InactiveCaption;

    Label textBox_name = new Label();
    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.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(208)))), ((int)(((byte)(217)))));
    textBox_name.ForeColor = SystemColors.InactiveCaption;

    Label textBox_msg = new Label();
    panel.Controls.Add(textBox_msg);
    textBox_msg.Location = new Point(5, 30);
    textBox_msg.Name = i.ToString();
    textBox_msg.Tag = list_afy_add[i]._AddEventNotification.eventNotificationId;
    textBox_msg.BorderStyle = BorderStyle.None;
    textBox_msg.BackColor = Color.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(208)))), ((int)(((byte)(217)))));
    textBox_msg.ForeColor = SystemColors.Highlight;
    textBox_msg.Cursor = Cursors.Arrow;
    textBox_msg.MaximumSize = new System.Drawing.Size(280, 100);
    textBox_msg.MinimumSize = new System.Drawing.Size(280, 14);
    textBox_msg.AutoSize = true;
    textBox_msg.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;

    Label labelOpenChat = new Label(); 
    labelOpenChat.Size = new System.Drawing.Size(90, 15);
    labelOpenChat.Text = "Открыть чат";
    labelOpenChat.Font = new Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(200)));
    labelOpenChat.Location = new Point(10, 8);
    labelOpenChat.BorderStyle = BorderStyle.None;
    labelOpenChat.BackColor = Color.FromArgb(((int)(((byte)(203)))), ((int)(((byte)(208)))), ((int)(((byte)(217)))));
    labelOpenChat.ForeColor = SystemColors.InactiveCaption;
    panel.Controls.Add(labelOpenChat);


    main_panel.Controls.Add(panel);
    panel1.Controls.Add(main_panel);
    panel.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
    main_panel.Dock = DockStyle.Top;

    date_and_msg_check(list_afy_add[i]._AddEventNotification.eventNotificationName, list_afy_add[i]._AddEventNotification.eventNotificationDate, list_afy_add[i]._AddEventNotification.eventNotificationMsg); 
    textBox_name.Text = valForName; 
    textBox_date.Text = valForDate;
    textBox_msg.Text = valForMsg;

    int height = textBox_msg.Size.Height + textBox_name.Height + 19;
    panel.Height = height; 
    main_panel.Height = height + 10; 
    int panHei = panel.Height;


    /*--------------------------------*/
    Panel panel_top_left = new Panel();
    Panel panel_top_right = new Panel();
    Panel panel_bottom_left = new Panel();
    Panel panel_bottom_right = new Panel();

    Bitmap btm_msg_panel_top_left = new Bitmap(Properties.Resources.blue_t_l1);
    panel_top_left.BackgroundImage = btm_msg_panel_top_left;
    Bitmap btm_msg_panel_top_right = new Bitmap(Properties.Resources.blue_t_r);
    panel_top_right.BackgroundImage = btm_msg_panel_top_right;
    Bitmap btm_msg_panel_bottom_left = new Bitmap(Properties.Resources.blue_b_l);
    panel_bottom_left.BackgroundImage = btm_msg_panel_bottom_left;
    Bitmap btm_msg_panel_bottom_right = new Bitmap(Properties.Resources.blue_b_r);
    panel_bottom_right.BackgroundImage = btm_msg_panel_bottom_right;

    panel_top_left.Width = panel.Width;
    panel_top_left.Height = height + 2;
    panel_top_right.Width = btm_msg_panel_top_right.Width;
    panel_bottom_left.Height = btm_msg_panel_bottom_left.Height;
    panel_bottom_left.Width = btm_msg_panel_bottom_left.Width;
    panel_bottom_right.Height = btm_msg_panel_bottom_right.Height;
    panel_bottom_right.Width = btm_msg_panel_bottom_right.Width;

    panel_top_right.Location = new Point(panel_top_left.Width - 4, 0);
    panel_bottom_left.Location = new Point(0, panel_top_left.Height - panel_bottom_left.Height);
    panel_bottom_right.Location = new Point(panel_top_left.Width - 4, panel_top_left.Height - panel_bottom_right.Height);


    panel_top_right.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
    panel_bottom_right.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
    panel_bottom_left.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
    panel_top_left.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
    /*--------------------------------*/


    Button delButt = new Button();
    delButt.Name = list_afy_add[i]._AddEventNotification.eventNotificationId;
    delButt.Click += new EventHandler(delButt_Click);
    delButt.Size = new System.Drawing.Size(12, 12);
    delButt.Location = new Point(292, 6);
    delButt.Anchor = AnchorStyles.Right | AnchorStyles.Top;
    delButt.BackColor = Color.Transparent;
    delButt.FlatStyle = FlatStyle.Flat;
    delButt.FlatAppearance.BorderSize = 0;
    delButt.FlatAppearance.MouseDownBackColor = Color.Transparent;
    delButt.FlatAppearance.MouseOverBackColor = Color.Transparent;
    delButt.BackgroundImage = bmp_close_normal;
    panel_top_left.Controls.Add(delButt);
    delButt.Hide();

    panel.Controls.Add(panel_bottom_right);
    panel.Controls.Add(panel_top_right);
    panel.Controls.Add(panel_bottom_left);
    panel.Controls.Add(panel_top_left);
}
4

2 に答える 2

0

子コントロールを追加する前にControl のメソッドを使用するようにしてください。終了後にSuspendLayout()を呼び出すことを忘れないでください。ResumeLayout()これは、まばたきを軽減または排除するのに役立ちます。

于 2013-09-18T13:36:15.150 に答える