private void RedrawBitmap()
        {
            Bitmap   bitmapa = new Bitmap(MaxWidth, MaxHeight);
            Graphics fl      = Graphics.FromImage(bitmapa);

            fl.Clear(Color.White);
            Bitmapa.Image = bitmapa;

            foreach (Element f in projectElements)
            {
                f.DrawImage(Graphics.FromImage(bitmapa));
            }
            Bitmapa.Refresh();

            if (Selected_Element is Furniture)
            {
                ListBox.DataSource = null;
                ListBox.DataSource = projectElements;
            }
            ListBox.Refresh();

            if (Selected_Element != null && Selected_Element.selected)
            {
                ListBox.SetSelected(GetIndex(Selected_Element), true);
            }
            else if (Selected_Element != null && !Selected_Element.selected)
            {
                ListBox.SetSelected(GetIndex(Selected_Element), false);
            }
            if (Selected_Element == null)
            {
                ListBox.ClearSelected();
            }
        }
        private void Bitmapa_MouseMove(object sender, MouseEventArgs e)
        {
            //wall drawing
            if (buildingWall)
            {
                Pen p = new Pen(Color.Black, 10);
                p.LineJoin = LineJoin.Bevel;
                Bitmap   bitmapa = new Bitmap(MaxWidth, MaxHeight);
                Graphics fl      = Graphics.FromImage(bitmapa);
                fl.Clear(Color.White);
                fl.DrawLine(p, Animation_Current_Point, new Point(e.X, e.Y));
                Bitmapa.Image = bitmapa;
                foreach (Element f in projectElements)
                {
                    f.DrawImage(Graphics.FromImage(bitmapa));
                }
                Bitmapa.Refresh();
            }

            //item moving
            if (Selected_Element != null)
            {
                int X = e.X - Animation_Current_Point.X;
                int Y = e.Y - Animation_Current_Point.Y;
                if (e.Button == MouseButtons.Left)
                {
                    if (Selected_Element.IsPointInsideElement(e.Location))
                    {
                        if (Selected_Element is Wall)
                        {
                            Wall w       = Selected_Element as Wall;
                            Wall newWall = new Wall(new Point(w.position.X + X, w.position.Y + Y));
                            foreach (Point p in w.punkty)
                            {
                                newWall.AddWall(new Point((int)p.X + X, (int)p.Y + Y));
                            }
                            projectElements.Remove(Selected_Element);
                            Selected_Element = newWall;
                            projectElements.Add(newWall);
                        }
                        else
                        {
                            Furniture f = Selected_Element as Furniture;
                            Selected_Element.position.X += X;
                            Selected_Element.position.Y += Y;
                        }
                    }
                }
                Animation_Current_Point   = e.Location;
                Selected_Element.selected = true;
                RedrawBitmap();
            }
        }
        private void OpenSchema_Click(object sender, EventArgs e)
        {
            OpenFileDialog SaveDialog = new OpenFileDialog();

            SaveDialog.Filter      = "Designer (*.bd)|*.bd";
            SaveDialog.FilterIndex = 1;
            if (SaveDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    FileStream      fStream    = File.Open(SaveDialog.FileName, FileMode.Open);
                    BinaryFormatter bFormatter = new BinaryFormatter();
                    AllDataToSave   dataToSave = bFormatter.Deserialize(fStream) as AllDataToSave;
                    projectElements = dataToSave.projectElements;
                    MaxHeight       = dataToSave.MaxHeight;
                    MaxWidth        = dataToSave.MaxWidth;
                    fStream.Close();
                    if (CultureInfo.CurrentUICulture.Name == "pl-PL")
                    {
                        MessageBox.Show("Otwarto pomyślnie");
                    }
                    else
                    {
                        MessageBox.Show("Open succesful");
                    }
                    Selected_Element = null;
                    RedrawBitmap();
                    Bitmapa.Refresh();
                }
                catch
                {
                    if (CultureInfo.CurrentUICulture.Name == "pl-PL")
                    {
                        MessageBox.Show("Coś poszło nie tak");
                    }
                    else
                    {
                        MessageBox.Show("It's something incorrect");
                    }
                }
            }
        }
        private void PictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            Animation_Current_Point = e.Location;

            int index = -1;

            for (int i = 0; i < 5; i++)
            {
                if (isclicked[i])
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                Point CurrentPoint = e.Location;
                if (projectElements.Count > 0)
                {
                    foreach (Element element in projectElements)
                    {
                        if (element.IsPointInsideElementSet(CurrentPoint, ref Selected_Element))
                        {
                            break;
                        }
                        if (Selected_Element != null)
                        {
                            Selected_Element.selected = false;
                        }
                        Selected_Element = null;
                    }
                    projectElements.Reverse();
                }
                RedrawBitmap();
                return;
            }

            if (index != 4)
            {
                isclicked[index]         = false;
                buttons[index].BackColor = Color.WhiteSmoke;
            }

            switch (buttons[index].Name)
            {
            case "kitchen_table":
            {
                Graphics bitmap = Graphics.FromImage(Bitmapa.Image);
                Image    pic = (new Bitmap(DamianBisWinFormsTask.Properties.Resources.coffee_table));
                int      x = e.X - pic.Size.Width / 2, y = e.Y - pic.Size.Height / 2;
                Element  f = new Furniture(pic, new Point(x, y), buttons[index].Name);
                f.DrawImage(bitmap);
                projectElements.Add(f);
                string text = "Kitchen table " + "{" + $"X={x}, Y={y}" + "}";
                break;
            }

            case "double_bed":
            {
                Graphics bitmap = Graphics.FromImage(Bitmapa.Image);
                Image    pic = (new Bitmap(DamianBisWinFormsTask.Properties.Resources.double_bed));
                int      x = e.X - pic.Size.Width / 2, y = e.Y - pic.Size.Height / 2;
                Element  f = new Furniture(pic, new Point(x, y), buttons[index].Name);
                f.DrawImage(bitmap);
                projectElements.Add(f);
                string text = "Double bed " + "{" + $"X={x}, Y={y}" + "}";
                break;
            }

            case "table":
            {
                Graphics bitmap = Graphics.FromImage(Bitmapa.Image);
                Image    pic = (new Bitmap(DamianBisWinFormsTask.Properties.Resources.table));
                int      x = e.X - pic.Size.Width / 2, y = e.Y - pic.Size.Height / 2;
                Element  f = new Furniture(pic, new Point(x, y), buttons[index].Name);
                f.DrawImage(bitmap);
                projectElements.Add(f);
                string text = "Table " + "{" + $"X={x}, Y={y}" + "}";
                break;
            }

            case "sofa":
            {
                Graphics bitmap = Graphics.FromImage(Bitmapa.Image);
                Image    pic = (new Bitmap(DamianBisWinFormsTask.Properties.Resources.sofa));
                int      x = e.X - pic.Size.Width / 2, y = e.Y - pic.Size.Height / 2;
                Element  f = new Furniture(pic, new Point(x, y), buttons[index].Name);
                f.DrawImage(bitmap);
                projectElements.Add(f);
                string text = "Sofa " + "{" + $"X={x}, Y={y}" + "}";
                break;
            }

            case "wall":
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (!buildingWall)
                    {
                        if (Selected_Element != null)
                        {
                            Selected_Element.selected = false;
                        }
                        Selected_Element = null;
                        Element f = new Wall(Animation_Current_Point);
                        projectElements.Add(f);
                        string text = "Wall " + "{" + $"X={Animation_Current_Point.X}, Y={Animation_Current_Point.Y}" + "}";
                    }

                    if (buildingWall)
                    {
                        Wall w = projectElements.Last() as Wall;
                        w.AddWall(Animation_Current_Point);
                    }
                    buildingWall = true;
                }
                else if (e.Button == MouseButtons.Right)
                {
                    buildingWall         = false;
                    isclicked[4]         = false;
                    buttons[4].BackColor = Color.WhiteSmoke;
                    RedrawBitmap();
                }
                break;
            }

            default:
            {
                break;
            }
            }
            if (Selected_Element == null)
            {
                ListBox.ClearSelected();
            }
            Bitmapa.Refresh();
        }