Beispiel #1
0
        private void Form2_LoadFile()
        {
            toolStripMenuItem2.Click += toolStripMenuItem_Click;
            toolStripMenuItem3.Click += toolStripMenuItem_Click;
            toolStripMenuItem4.Click += toolStripMenuItem_Click;
            toolStripMenuItem5.Click += toolStripMenuItem_Click;
            toolStripMenuItem6.Click += toolStripMenuItem_Click;
            toolStripMenuItem7.Click += toolStripMenuItem_Click;
            toolStripMenuItem8.Click += toolStripMenuItem_Click;

            SetDoubleBuffered(panel1);
            if (idcard.backgroundImage != null)
            {
                panel1.BackgroundImage = idcard.backgroundImage;
            }
            toolStripStatusLabel1.Text = "Right Click to add Fields...";
            enableItems();
            titleLbl.Text       = idcard.title;
            titleLbl.MouseDown += tmplbl_MouseDown;
            ControlMover.Init(titleLbl, panel1, true);

            if (isNew == true)
            {
                pictureContainerPanel = new Panel();
                pictureContainerPanel.BackgroundImageLayout = ImageLayout.Stretch;
                pictureContainerPanel.SetBounds(10, 10, 90, 90);
                pictureContainerPanel.BackgroundImage = global::IDCardManagement.Properties.Resources.avatar;
                ControlMover.Init(pictureContainerPanel);
                ControlResizer.Init(pictureContainerPanel);
                pictureContainerPanel.Tag = "IDpictureBox";
                panel1.Controls.Add(pictureContainerPanel);
            }


            //if (pictureBox1 == null)
            //{
            //    pictureBox1 = new PictureBox();
            //    pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            //    pictureBox1.SetBounds(10, 10, 90, 90);
            //    pictureBox1.BackgroundImage = global::IDCardManagement.Properties.Resources.avatar;
            //    panel1.Controls.Add(pictureBox1);

            //}
            //ControlMover.Init(pictureBox1);

            panel1.Visible = true;
            panel1.Size    = new Size(idcard.dimensions.Width * 10, idcard.dimensions.Height * 10);
            panel1.Left    = (((Width - panel1.Width) / 2) - 20) > 40 ? (((Width - panel1.Width) / 2) - 20) : 80;
            panel1.Top     = ((Height - panel1.Height) / 2 - 60) > 80 ? ((Height - panel1.Height) / 2 - 60) : 80;

            rectangleShape1.Visible = true;
            rectangleShape1.SetBounds(panel1.Left + 5, panel1.Top + 5, panel1.Width, panel1.Height);

            contextMenuStrip1.Items.Clear();
            foreach (String str in idcard.selectedFields)
            {
                ToolStripItem tmp = contextMenuStrip1.Items.Add(str);
                tmp.Click += tmpToolStripItem_Click;
            }
        }
Beispiel #2
0
        void openLoadFile()
        {
            isNew = false;
            //panel1.CreateGraphics().Transform;

            this.Text = filename + " - IDCard Designer";

            ArrayList fields         = new ArrayList();
            ArrayList selectedFields = new ArrayList();

            Image  backgroundImage = null;
            string connectionString = "", tableName = "", title = "", dataSourceType = "", primaryKey = "";

            Size dimensions = new Size();

            panel1.Controls.Clear();
            panel1.ContextMenuStrip = contextMenuStrip1;

            try
            {
                using (XmlTextReader reader = new XmlTextReader(filename))
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            #region
                            switch (reader.Name)
                            {
                            case "label":
                                Label tmp = new Label();
                                tmp.Text = reader.GetAttribute("text");
                                tmp.Top  = Convert.ToInt32(reader.GetAttribute("top"));
                                tmp.Left = Convert.ToInt32(reader.GetAttribute("left"));
                                panel1.Controls.Add(tmp);
                                tmp.MouseDown += tmplbl_MouseDown;
                                ControlMover.Init(tmp, panel1, true);
                                tmp.AutoSize  = true;
                                tmp.Font      = (Font)TypeDescriptor.GetConverter(typeof(Font)).ConvertFromString(reader.GetAttribute("font"));
                                tmp.BackColor = Color.FromArgb(Convert.ToInt32(reader.GetAttribute("backcolor")));
                                tmp.ForeColor = Color.FromArgb(Convert.ToInt32(reader.GetAttribute("forecolor")));
                                break;

                            case "IDpictureBox":

                                pictureContainerPanel                       = new Panel();
                                pictureContainerPanel.Tag                   = "IDpictureBox";
                                pictureContainerPanel.BackgroundImage       = global::IDCardManagement.Properties.Resources.avatar;
                                pictureContainerPanel.BackgroundImageLayout = ImageLayout.Stretch;
                                pictureContainerPanel.Left                  = Convert.ToInt32(reader.GetAttribute("left"));
                                pictureContainerPanel.Top                   = Convert.ToInt32(reader.GetAttribute("top"));
                                pictureContainerPanel.Height                = Convert.ToInt32(reader.GetAttribute("height"));
                                pictureContainerPanel.Width                 = Convert.ToInt32(reader.GetAttribute("width"));
                                panel1.Controls.Add(pictureContainerPanel);
                                ControlResizer.Init(pictureContainerPanel);
                                ControlMover.Init(pictureContainerPanel);
                                break;

                            case "barcode":
                                PictureBox barcodePicture = new PictureBox();
                                barcodePicture.Left   = Convert.ToInt32(reader.GetAttribute("left"));
                                barcodePicture.Top    = Convert.ToInt32(reader.GetAttribute("top"));
                                barcodePicture.Height = Convert.ToInt32(reader.GetAttribute("height"));
                                barcodePicture.Width  = Convert.ToInt32(reader.GetAttribute("width"));
                                panel1.Controls.Add(barcodePicture);
                                barcodePicture.BackgroundImageLayout = ImageLayout.Stretch;
                                barcodePicture.BackgroundImage       = new Bitmap(@"C:\Users\Archie\Documents\GitHub\IDCardManagement-Designer\IDCardManagement\IDCardManagement\Resources\barcodeImg.png");
                                ControlMover.Init(barcodePicture);
                                barcodeCount = 1;
                                break;

                            case "idCard":
                                dimensions.Height = Convert.ToInt32(reader.GetAttribute("height"));
                                dimensions.Width  = Convert.ToInt32(reader.GetAttribute("width"));
                                String base64String;
                                if ((base64String = reader.GetAttribute("backgroundImage")) != null)
                                {
                                    byte[]       imageBytes = Convert.FromBase64String(base64String);
                                    MemoryStream ms         = new MemoryStream(imageBytes, 0, imageBytes.Length);
                                    // Convert byte[] to Image
                                    ms.Write(imageBytes, 0, imageBytes.Length);
                                    backgroundImage = Image.FromStream(ms, true);
                                }
                                title            = reader.GetAttribute("title");
                                tableName        = reader.GetAttribute("tableName");
                                connectionString = reader.GetAttribute("connectionString");
                                dataSourceType   = reader.GetAttribute("dataSourceType");
                                primaryKey       = reader.GetAttribute("primaryKey");
                                extraTableName   = reader.GetAttribute("extraTableName");
                                break;

                            case "field":
                                fields.Add(reader.ReadString());
                                break;

                            case "selectedField":
                                selectedFields.Add(reader.ReadString());
                                break;
                            }

                            #endregion
                        }
                    }
                idcard = new IDCard(connectionString, dataSourceType, tableName, primaryKey, extraTableName, dimensions, backgroundImage, fields, selectedFields, title);
                Form2_LoadFile();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid file format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }