예제 #1
0
        void AddFormatButtonClick(object sender, EventArgs e)
        {
            if (activeIconFile == null)
            {
                return;
            }
            using (PickFormatDialog dlg = new PickFormatDialog()) {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    int width           = dlg.IconWidth;
                    int height          = dlg.IconHeight;
                    int colorDepth      = dlg.ColorDepth;
                    var sameSizeEntries = activeIconFile.Icons.Where(entry => entry.Width == width && entry.Height == height);
                    if (sameSizeEntries.Any(entry => entry.ColorDepth == colorDepth))
                    {
                        MessageService.ShowMessage("This icon already contains an image with the specified format.", "Icon Editor");
                        return;
                    }
                    IconEntry sourceEntry = sameSizeEntries.OrderByDescending(entry => entry.ColorDepth).FirstOrDefault();
                    if (sourceEntry == null)
                    {
                        sourceEntry = (from entry in activeIconFile.Icons
                                       orderby entry.Width descending, entry.Height descending, entry.ColorDepth descending
                                       select entry).FirstOrDefault();
                    }
                    // sourceEntry can still be null if the icon is completely empty
                    Bitmap sourceBitmap = sourceEntry != null?sourceEntry.ExportArgbBitmap() : new Bitmap(width, height);

                    activeIconFile.AddEntry(new IconEntry(width, height, colorDepth, sourceBitmap));
                    if (IconWasEdited != null)
                    {
                        IconWasEdited(this, e);
                    }
                    ShowFile(activeIconFile);
                }
            }
        }
예제 #2
0
		void AddFormatButtonClick(object sender, EventArgs e)
		{
			if (activeIconFile == null)
				return;
			using (PickFormatDialog dlg = new PickFormatDialog()) {
				if (dlg.ShowDialog() == DialogResult.OK) {
					int width = dlg.IconWidth;
					int height = dlg.IconHeight;
					int colorDepth = dlg.ColorDepth;
					var sameSizeEntries = activeIconFile.Icons.Where(entry => entry.Width == width && entry.Height == height);
					if (sameSizeEntries.Any(entry => entry.ColorDepth == colorDepth)) {
						MessageService.ShowMessage("This icon already contains an image with the specified format.", "Icon Editor");
						return;
					}
					IconEntry sourceEntry = sameSizeEntries.OrderByDescending(entry => entry.ColorDepth).FirstOrDefault();
					if (sourceEntry == null) {
						sourceEntry = (from entry in activeIconFile.Icons
						               orderby entry.Width descending, entry.Height descending, entry.ColorDepth descending
						               select entry).FirstOrDefault();
					}
					// sourceEntry can still be null if the icon is completely empty
					Bitmap sourceBitmap = sourceEntry != null ? sourceEntry.ExportArgbBitmap() : new Bitmap(width, height);
					activeIconFile.AddEntry(new IconEntry(width, height, colorDepth, sourceBitmap));
					if (IconWasEdited != null)
						IconWasEdited(this, e);
					ShowFile(activeIconFile);
				}
			}
		}