![]() |
Desktop Development »
Miscellaneous »
Miscellaneous Controls
Intermediate
Simple FilmStrip ControlBy rahulpartheAn article on writing your own simple FilmStrip control |
VC7.1, C# 1.0, Windows, .NET 1.1, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Some time ago I was looking for a quick reference for a FilmStrip Control as seen in Windows XP. I was amazed to see that there was not a single article. At that time I decided I will write one article to at least give a general idea about implementing it. So I wrote this short and simple article explaining how to write your own FilmStrip control using the .NET framework. In this article I will be making a custom control and a test application which will use it. I have also added some custom events and properties do some basic operations. Since this is just a beginning step readers can add logic and make this control more versatile.
public bool AddPicture(string ImagePath) { Bitmap bm = new Bitmap(ImagePath); Label lb = new Label(); int width=0,height=0; height = this.Height-50; width = height; string[] folderparts= ImagePath.Split('\\'); PictureBox pb = new PictureBox(); pb.Name = pictureBoxNumber .ToString(); pb.BorderStyle = BorderStyle.FixedSingle; pb.Size = new Size(width,height); pb.Location = new Point(pictureBoxOffset,5); pb.SizeMode = PictureBoxSizeMode.CenterImage; lb.Text = folderparts[folderparts.GetLength(0)-1]; lb.Size = new Size(width,15); lb.Location = new Point(pictureBoxOffset,height+2); if(bm.Height>bm.Width) { pb.Image = (Image)bm.GetThumbnailImage( Convert.ToInt32(((float)height/(float)bm.Height)*bm.Width), height,null,IntPtr.Zero); } else { pb.Image = (Image)bm.GetThumbnailImage(width, Convert.ToInt32(((float)height/ (float)bm.Height)*bm.Height), null,IntPtr.Zero); } pb.Click +=new EventHandler(Image_Click); pictureBoxOffset = pictureBoxOffset + width + 21; this.FilmStripPanel.Controls.Add(pb); this.FilmStripPanel.Controls.Add(lb); pictureBoxNumber++; return true; }As you can see we add the picturebox and the label each time you will call the
AddPicture function. We use the pictureBoxNumber global counter to keep track of how many pictureboxes we have added. private void FilmStrip_Resize(object sender, System.EventArgs e) { this.FilmStripPanel.Size = new System.Drawing.Size(this.Width, this.Height); this.FilmStripPanel.AutoScroll = true; }
protected void Image_Click(object sender,EventArgs e) { int PictureBoxNumber=0; PictureBox pb= (PictureBox)sender; PictureBoxNumber =Convert.ToInt32(pb.Name); if(OnImageClicked!=null) { OnImageClicked((object)pb.Name,e); } }It can be seen that the event returns the picturebox name that was clicked which is the string representation of the picturebox number.
public bool RemoveAllPictures() { ControlCollection controlCollection = this.FilmStripPanel.Controls; Control pb; for(int i=pictureBoxNumber-1;i>-1;i--) { pb = (Control)controlCollection[i*2]; controlCollection.Remove(pb); pb = (Control)controlCollection[i*2]; controlCollection.Remove(pb); } return true; }
string dirpath = @"C:\Test\Images1"; DirectoryInfo dirinfo = new DirectoryInfo(dirpath); FileInfo[] fileList = dirinfo.GetFiles("*.jpg"); foreach (FileInfo f in fileList) { filmStrip1.AddPicture(f.FullName); Application.DoEvents(); }
this.filmStrip1.OnImageClicked += new System.EventHandler(filmStrip1_OnImageClicked); public void filmStrip1_OnImageClicked(object sender, EventArgs e) { MessageBox.Show("ImageBox " + (string)sender + " Clicked"); }
As can be seen, I have just implemented the code to display a MessageBox displaying the picturebox number that was clicked.
Please download the zip files and feel free to modify it. As mentioned earlier this is a very basic filmstrip control. It is good for less than 50 images at a time. So you can add logic to handle more images and add other required properties and events. I am now working on another filmstrip control which will utilize the GDI+ to display images and can handle more images. It will also be faster than this filmstrip control. Check back for the new control.
Please feel free to contact me for clarifications and I would also appreciate suggestions to make this control faster and to make it capable of handling more images.
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 31 Jul 2006 Editor: Chris Maunder |
Copyright 2006 by rahulparthe Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |