4

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);
    }
GJ.
  • 10,810
  • 2
  • 45
  • 62
zuh4n
  • 448
  • 1
  • 4
  • 11
  • If I am not wrong then you need each panel completely joined to each other,I mean there should be no gap between any of the panels.Isn't it ? – devavx Sep 16 '13 at 10:22
  • I tried your code and it's working perfectly.It is difficult to get what you problem is.I think it would be better if you post the image of what you are getting. – devavx Sep 16 '13 at 10:34
  • @Aviral Singh I posted a new pic in my question – zuh4n Sep 16 '13 at 10:41

2 Answers2

1

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

zuh4n
  • 448
  • 1
  • 4
  • 11
  • Check the value `Form.AutoScaleMode` property. If it's `Dpi` or `Font`, try changing your OS font size or DPI setting to make sure that the layout stays correct on other systems. For example, Windows XP has a default font of a different size than Vista, meaning that .NET will autoscale your contents to try to make your app "DPI-aware" as you move your app between these two systems. There are several answers on SO which deal with autoscaling ([this](http://stackoverflow.com/a/4076259/69809), or [this](http://stackoverflow.com/a/202172/69809)). – vgru Sep 16 '13 at 14:11
0

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);
    }
devavx
  • 1,035
  • 9
  • 22