public void Show(KLayout klayout)
        {
            while (pictureBoxes.Count < klayout.images.Count)
            {
                button_addImage_Click(null, null);
            }

            while (pictureBoxes.Count > klayout.images.Count)
            {
                button_removeImage_Click(null, null);
            }

            for (int i = 0; i < klayout.images.Count; i++)
            {
                //var temp = Convert.FromBase64String(klayout.images[i]);
                //var tempmem = new MemoryStream(temp);
                //Image image = new Bitmap(tempmem);
                //image = ImageTools.ResizeImage(image, pictureBoxes[i].Width, pictureBoxes[i].Height);
                var image      = klayout.images[i].image;
                var fixedImage = ImageTools.FixSize(image, pictureBoxes[i].Width, pictureBoxes[i].Height);
                pictureBoxes[i].Image = fixedImage;
                pictureBoxes[i].Tag   = klayout.images[i];
            }

            textBox_name.Text      = klayout.Name;
            numericUpDown_ID.Value = klayout.WID;

            ShowDialog();
        }
        private void button_save_Click(object sender, EventArgs e)
        {
            DisplayMaker displayMaker = new DisplayMaker();
            var          cImages      = new List <List <List <string> >    >();
            //var imagesAsStrings = new List<string>();
            var previewTags = new List <PreviewTag>();

            foreach (var pBox in pictureBoxes)
            {
                var pBoxTag = (PreviewTag)pBox.Tag;
                previewTags.Add(pBoxTag);

                cImages.Add(displayMaker.MakeCImageFromImage(pBoxTag.image, DisplayMaker.IMAGE_SIZE, pBoxTag.threshold, pBoxTag.invert));

                //MemoryStream imageAsStream = new MemoryStream();
                //image = ImageTools.FixSize(image, DisplayMaker.IMAGE_SIZE);
                //image.Save(imageAsStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                //var imageAsString = Convert.ToBase64String(imageAsStream.ToArray());
                //imagesAsStrings.Add(imageAsString);
            }

            List <string> cDisplay = displayMaker.MakeCDisplayFromCImage(cImages.ToArray());

            var klayout = new KLayout(textBox_name.Text, numericUpDown_ID.Value, cDisplay, previewTags);

            //var klayoutfile = KLayout.KLayoutToFile(klayout);

            string file;

            saveFileDialog_save.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "layouts\\";
            saveFileDialog_save.FileName         = textBox_name.Text + ".klayout";
            var result = saveFileDialog_save.ShowDialog();

            if (result == DialogResult.OK)
            {
                file = saveFileDialog_save.FileName;
            }
            else
            {
                return;
            }

            BinarySerializer.WriteToBinaryFile <KLayout>(file, klayout);
            Close();
        }
        private void checkedListBox_layouts_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            var index = checkedListBox_layouts.IndexFromPoint(e.Location);

            if (index != ListBox.NoMatches)
            {
                _selectedMenuItem = (KLayout)checkedListBox_layouts.Items[index];
                checkedListBoxContextMenu.Show(Cursor.Position);
                checkedListBoxContextMenu.Visible = true;
            }
            else
            {
                checkedListBoxContextMenu.Visible = false;
            }
        }
        private void DefaultClick(object sender, EventArgs e)
        {
            if (defaultLayout == _selectedMenuItem)
            {
                defaultLayout = null;
                pictureBox_defaultLayout.Visible = false;

                return;
            }
            defaultLayout = _selectedMenuItem;
            var index = checkedListBox_layouts.Items.IndexOf(_selectedMenuItem);

            checkedListBox_layouts.SetItemCheckState(index, CheckState.Checked);

            var point = pictureBox_defaultLayout.Location;

            point.Y = 32 + (15 * (checkedListBox_layouts.Items.IndexOf(_selectedMenuItem)));
            pictureBox_defaultLayout.Location = point;
            pictureBox_defaultLayout.Visible  = true;
        }