zuh4n
zuh4n

Reputation: 448

How to make at panel couple pictures to one

I need to make 4 different images in one, and it will be in the panel. Panel size will vary from 180 to 320. I tried to do one main panel, and in her place 4, which are fixed by anchors...

What I have (source four pics)

enter image description here

What i need to get. Panel like this

enter image description here

What I got

enter image description here

private void Form1_Load(object sender, EventArgs e)
    {
        Panel main_panel = new Panel();
        main_panel.BackColor = Color.Azure;
        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_l);
        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;

        main_panel.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
        panel_top_left.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
        panel_top_right.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left;
        panel_bottom_left.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
        panel_bottom_right.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

        main_panel.Controls.Add(panel_top_left);
        main_panel.Controls.Add(panel_top_right);
        main_panel.Controls.Add(panel_bottom_left);
        main_panel.Controls.Add(panel_bottom_right);

        panel1.Controls.Add(main_panel);
    }

Upvotes: 4

Views: 168

Answers (2)

zuh4n
zuh4n

Reputation: 448

Well... I will answer on my own post :))

private void Form1_Load(object sender, EventArgs e)
    {
        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_l);
        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 = btm_msg_panel_top_left.Width;
        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 - panel_top_right.Width, 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 - panel_bottom_right.Width, panel_top_left.Height - panel_bottom_right.Height);


        panel1.Controls.Add(panel_bottom_right);
        panel1.Controls.Add(panel_top_right);
        panel1.Controls.Add(panel_bottom_left);
        panel1.Controls.Add(panel_top_left);
    }

This is result

enter image description here

Upvotes: 1

devavx
devavx

Reputation: 1045

See if this helps;

    private void Form1_Load(object sender, EventArgs e)
    {
        Panel main_panel = new Panel();
        main_panel.BackColor = Color.Azure;
        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_l);
        panel_top_left.BackgroundImage = btm_msg_panel_top_left;
        Bitmap btm_msg_panel_top_right = new Bitmap(Properties.Resources.blue_t_l);
        panel_top_right.BackgroundImage = btm_msg_panel_top_right;
        Bitmap btm_msg_panel_bottom_left = new Bitmap(Properties.Resources.blue_t_l);
        panel_bottom_left.BackgroundImage = btm_msg_panel_bottom_left;
        Bitmap btm_msg_panel_bottom_right = new Bitmap(Properties.Resources.blue_t_l);
        panel_bottom_right.BackgroundImage = btm_msg_panel_bottom_right;

        main_panel.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
        panel_top_left.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
        panel_top_right.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom;
        panel_bottom_left.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
        panel_bottom_right.Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left;

        main_panel.Controls.Add(panel_top_left);
        main_panel.Controls.Add(panel_top_right);
        main_panel.Controls.Add(panel_bottom_left);
        main_panel.Controls.Add(panel_bottom_right);

        panel1.Controls.Add(main_panel);
    }

Upvotes: 0

Related Questions