private void Form1_Load(object sender, EventArgs e) { // load all animated gifs from resources int row = 1; int col = 1; Assembly a = Assembly.GetExecutingAssembly(); foreach (string s in a.GetManifestResourceNames()) { if (s.EndsWith(".gif")) { try { // load gif, add to list Image img = Image.FromStream(a.GetManifestResourceStream(s)); AnimatedGif gif = new AnimatedGif(img); _gifs.Add(gif); // show gif in grid cell c1FlexGrid1[row, col] = s; c1FlexGrid1.SetCellImage(row, col + 1, gif.Image); // update row/col indices if (col == 1) { col = 3; } else { col = 1; row++; } } catch { Console.WriteLine("failed to load {0}", s); } } } // initialize grid c1FlexGrid1.AutoSizeCols(); c1FlexGrid1.AutoSizeRows(); c1FlexGrid1.Styles.Normal.ImageAlign = ImageAlignEnum.CenterCenter; // build list of cells that contain gifs, enable timer BuildRangeList(); timer1.Interval = 100; timer1.Enabled = true; }
// build a list of all ranges that contain animated gifs private void BuildRangeList() { _gifRanges.Clear(); for (int r = 0; r < this.c1FlexGrid1.Rows.Count; r++) { for (int c = 0; c < this.c1FlexGrid1.Cols.Count; c++) { Image img = this.c1FlexGrid1.GetCellImage(r, c); if (img != null) { AnimatedGif gif = new AnimatedGif(img); if (gif.IsAnimated) { _gifRanges.Add(this.c1FlexGrid1.GetCellRange(r, c)); } } } } }