PFRepeater.NET: Repeater-control Winforms
The PFRepeater-control is a container for repeating items with flexible rendering and display. In our Demo-Application in which we mimic
the Windows-8 Search-feature you can see the control in action:
The rendering is smooth, fast and flexible. Custom RepeaterItems can be derived to override drawing of text or images. This is the code for
searching files and displaying these as items with a file-image, filename and size in KB:
private void FillResults()
{
repeaterResults.Clear();
string searchString = filterTextBox1.Text;
string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
foreach (string file in Directory.GetFiles(dir))
{
FileInfo fi = new FileInfo(file);
int size = (int)fi.Length / 1024;
ItemInfo info = new ItemInfo(Path.GetFileName(file), size);
if (String.IsNullOrEmpty(searchString) || info.Name.ToLower().Contains(searchString.ToLower()))
{
RepeaterImageItem item = new RepeaterItemFile(info);
repeaterResults.Items.Add(item);
}
}
}
The RepeaterItemFile-object is derived from RepeaterImageItem, returns the images and the info of the found files and draws the content:
public RepeaterItemFile(ItemInfo info)
{
this.info = info;
this.Data = info;
this.Image = info.ItemImage;
this.SelectedImage = info.SelectedImage;
}
protected override void DrawContent(System.Drawing.Graphics g)
{
base.DrawContent(g);
StringFormat fm = new StringFormat();
fm.Trimming |= StringTrimming.EllipsisPath;
DrawTextLine(g, fm, this.Bounds.Top + 1, info.Name);
DrawTextLine(g, fm, this.Bounds.Top + 25, String.Format("{0:d} KB", info.Size));
}