private void SetFilters_LostFocus(object sender, EventArgs e) { SetFilters.Text = SetFilters.Text.Trim(); if (!SetFilters.AutoCompleteCustomSource.Contains(SetFilters.Text)) { SetFilters.AutoCompleteCustomSource.Add(SetFilters.Text); } if (SetFilters.Text != pattern) { pattern = SetFilters.Text; Clear.Enabled = SetFilters.Text.Length > 0; Filter.Checked = SetFilters.Text.Length > 0; // Comma separated array of keyword groups which are in turn space separated arrays of keywords. var filter = Array.ConvertAll(pattern.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries), search => search.Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); var names = new string[imageMso.Names.Count]; imageMso.Names.CopyTo(names, 0); Icons.BeginUpdate(); Icons.Items.Clear(); // Find all names where there exists a keyword group in the filter such that the name contains // all the keywords in the group, convert all names found to listview items and add as a range. if (filter.Length > 0) { Icons.Items.AddRange(Array.ConvertAll(Array.FindAll(names, name => Array.Exists(filter, group => Array.TrueForAll(group, keyword => name.ToLowerInvariant().Contains(keyword.ToLowerInvariant().Trim())))), name => new ListViewItem(name, Array.IndexOf(names, name)))); } else { Icons.Items.AddRange(Array.ConvertAll(names, name => new ListViewItem(name, Array.IndexOf(names, name)))); } if (Icons.Items.Count > 0) { Icons.FocusedItem = Icons.Items[0]; } Icons.EndUpdate(); } }
private string pattern = string.Empty; // Holds the filter pattern between GotFocus and LostFocus events. /// <summary>Initializes a new instance of the ImageMso.Gallery class.</summary> public Gallery() { InitializeComponent(); GalleryMenu.Renderer = new HotkeyMenuStripRenderer(); if (Default == null) { Default = this; } Icons.SmallImageList = new ImageList(); Icons.LargeImageList = new ImageList(); Icons.SmallImageList.ImageSize = new Size(16, 16); Icons.LargeImageList.ImageSize = new Size(32, 32); Icons.SmallImageList.ColorDepth = ColorDepth.Depth32Bit; Icons.LargeImageList.ColorDepth = ColorDepth.Depth32Bit; var names = new string[imageMso.Names.Count]; imageMso.Names.CopyTo(names, 0); Icons.BeginUpdate(); var smallImages = Array.ConvertAll(names, name => imageMso[name, 16, 16]).Where(img => img != null).ToArray(); var largeImages = Array.ConvertAll(names, name => imageMso[name, 32, 32]).Where(img => img != null).ToArray(); Icons.SmallImageList.Images.AddRange(smallImages); Icons.LargeImageList.Images.AddRange(largeImages); Icons.Items.AddRange(Array.ConvertAll(names, name => new ListViewItem(name, Array.IndexOf(names, name)))); Icons.EndUpdate(); Small.Checked = Icons.View == View.List; Large.Checked = Icons.View == View.LargeIcon; using (var image = imageMso["DesignAccentsGallery", 32, 32] ?? imageMso["GroupSmartArtQuickStyles", 32, 32]) if (image != null) { Icon = Icon.FromHandle(image.GetHicon()); } ViewSize.Image = imageMso["ListView", 16, 16]; Large.Image = imageMso["LargeIcons", 16, 16] ?? imageMso["SmartArtLargerShape", 16, 16]; Small.Image = imageMso["SmallIcons", 16, 16] ?? imageMso["SmartArtSmallerShape", 16, 16]; Filter.Image = imageMso["FiltersMenu", 16, 16]; Clear.Image = imageMso["FilterClearAllFilters", 16, 16]; CopyPicture.Image = imageMso["CopyPicture", 16, 16]; CopyText.Image = imageMso["Copy", 16, 16]; SelectAll.Image = imageMso["SelectAll", 16, 16]; Dimensions.Image = imageMso["PicturePropertiesSize", 16, 16] ?? imageMso["SizeAndPositionWindow", 16, 16]; SaveAs.Image = imageMso["PictureFormatDialog", 16, 16]; Save.Image = imageMso["FileSave", 16, 16]; Bmp.Image = imageMso["SaveAsBmp", 16, 16]; Gif.Image = imageMso["SaveAsGif", 16, 16]; Jpg.Image = imageMso["SaveAsJpg", 16, 16]; Png.Image = imageMso["SaveAsPng", 16, 16]; Tif.Image = imageMso["SaveAsTiff", 16, 16]; Ico.Image = imageMso["InsertImageHtmlTag", 16, 16]; Background.Image = imageMso["FontColorCycle", 16, 16]; ExportAs.Image = imageMso["SlideShowResolutionGallery", 16, 16]; Export.Image = imageMso["ArrangeBySize", 16, 16]; Support.Image = imageMso["Help", 16, 16]; Information.Image = imageMso["Info", 16, 16]; Background.Text = string.Format(Background.Text, Palette.Color.Name); }