Beispiel #1
0
 /// <summary>
 /// Event Handler for BtnBrowseForPictureFile.Click event.
 /// Browse for Picture file and set pictureBoxPhoto Image and Tag(byte array).
 /// </summary>
 /// <param name="sender">Sender of event</param>
 /// <param name="e">Event arguments</param>
 private void BtnBrowseForPictureFile_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         ofd.Multiselect = false;
         ofd.Title       = "Browse for a Picture File";
         // browse for the file
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 // get image from file
                 Image img = Image.FromFile(ofd.FileName);
                 // resize image so that height=100
                 pictureBoxPhoto.Image = ImageFunctions.ResizeImage(img, (int)(100.0m * img.Width / img.Height), 100);
                 // set tag to byte array of image in bitmap format
                 pictureBoxPhoto.Tag = ImageFunctions.GetByteArrayFromBitMapImage(pictureBoxPhoto.Image);
             }
             catch (Exception ex)
             {
                 LogFunctions.LogException(ex);
                 _ = MessageBox.Show("A problem occurred while loading the photo from the file.",
                                     "Invalid Photo File",
                                     MessageBoxButtons.OK);
             }
         }
     }
 }
Beispiel #2
0
        private Image constructIcons()
        {
            List <Image> iconImages = new List <Image>();

            if (pnlShortcuts.Controls.Count >= 4)
            {
                for (int i = 0; i < 4; i++)
                {
                    iconImages.Insert(0, ((ucProgramShortcut)pnlShortcuts.Controls[i]).logo);
                }
            }
            else
            {
                foreach (ucProgramShortcut controlItem in pnlShortcuts.Controls)
                {
                    iconImages.Insert(0, controlItem.logo);
                }
            }

            var image = new Bitmap(256, 256, PixelFormat.Format32bppArgb);

            using (var g = Graphics.FromImage(image))
            {
                g.Clear(Color.Transparent);

                PointF drawLocation = new PointF(0, 0);
                int    counter      = 0;

                foreach (Image iconImage in iconImages)
                {
                    if (counter == 2)
                    {
                        counter         = 0;
                        drawLocation.Y += 128;
                        drawLocation.X  = 0;
                    }

                    g.DrawImage(ImageFunctions.ResizeImage(iconImage, 128, 128), drawLocation);

                    drawLocation.X += 128;
                    counter        += 1;
                }
                g.Dispose();
            }
            return(image);
        }
Beispiel #3
0
        public void CreateConfig(Image groupImage)
        {
            string path     = @"config\" + this.Name;
            string filePath = path + @"\" + this.Name + "Group.exe";

            //
            // Directory and .exe
            //
            System.IO.Directory.CreateDirectory(@path);
            System.IO.File.Copy(@"config\config.exe", @filePath);
            //
            // XML config
            //
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Category));

            using (FileStream file = System.IO.File.Create(@path + @"\ObjectData.xml"))
                writer.Serialize(file, this);
            //
            // Create .ico
            //

            Image img = ImageFunctions.ResizeImage(groupImage, 1024, 1024); // Resize img if too big

            img.Save(path + @"\GroupImage.png");

            using (FileStream fs = new FileStream(path + @"\GroupIcon.ico", FileMode.Create))
                ImageFunctions.IconFromImage(img).Save(fs);  // saving as icon
                                                             //
                                                             // Create .lnk shortcut
                                                             //
            var wsh = new IWshShell_Class();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                path + "\\" + this.Name + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments        = "";
            shortcut.TargetPath       = Path.GetFullPath(@filePath);
            shortcut.WindowStyle      = 1;
            shortcut.Description      = path + " shortcut";
            shortcut.WorkingDirectory = Path.GetFullPath(@path);
            shortcut.IconLocation     = Path.GetFullPath(path + @"\GroupIcon.ico");
            shortcut.Save();
            System.IO.File.Move(@path + "\\" + this.Name + ".lnk",
                                Path.GetFullPath(@"Shortcuts\" + this.Name + ".lnk")); // moving .lnk to correct directory
        }