B
Bruce
Hello All,
I am creating an image browsing function within an application. As such, I
created a Thumbpanel control (shown below) which displays a collection of
thumbnails. Each thumbnail on that panel is also a custom control ( of a
class called Thumbnail) placed at a calculated location on the Thumbpanel.
It turns out to take 1+ seconds to construct and render each Thumbnail, so
in turn it takes MANY seconds to render the whole panel. Therefore I need
to force each Thumbnail to be rendered individually as they are constructed,
so that the user will not be confused by the frozen screen awaiting the
whole thing to render. I expected that the line:
thumb.Refresh();
.... would force the thumb object (of type Thumbnail) to be rendered upon
that call. But that didn't do the job.
Can someone give my guidance on how to force rendering of the individual
child controls (Thumbnails) in the order I specify?
Thanks,
-- Bruce
-------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace WTMWClient
{
/// <summary>
/// Summary description for ThumbPanel.
/// </summary>
public class ThumbPanel : System.Windows.Forms.Control
{
Assets m_Assets;
ArrayList m_Thumbnails;
bool m_Scrollable = false;
public delegate void ThumbPanelDoubleClickedHandler(object sender,
ThumbnailDoubleClickedEventArgs e);
public event ThumbPanelDoubleClickedHandler
ThumbPanelDoubleClickedEvent;
private System.ComponentModel.Container components = null;
public ThumbPanel()
{
InitializeComponent();
m_Assets = new Assets(); // Simply a default value so it will not
be null.
m_Thumbnails = new ArrayList();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
~ThumbPanel()
{
// ~base();
foreach (Thumbnail thumb in m_Thumbnails)
{
thumb.Dispose();
}
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// ThumbPanel
//
this.Dock = System.Windows.Forms.DockStyle.Fill;
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
// Calling the base class OnPaint
base.OnPaint(pe);
}
protected override void OnResize(EventArgs e)
{
base.OnResize (e);
PlaceThumbnails( false );
}
/// <summary>
/// Place each thumbnail in its proper position. Assumption is that
/// each thumbnail has already be constructed and placed in the
/// m_Thumbnails collection before this call.
/// </summary>
protected void PlaceThumbnails( bool isFirstDrawOfThisSetOfThumnails )
{
// Remove all the old ones. (But, dont "dispose" them, since they
// are still instantiated and held in m_Thumbnails.)
this.Controls.Clear();
// Place each one in proper position....
int x, y;
x = y = 0;
if ( isFirstDrawOfThisSetOfThumnails )
{
m_Thumbnails.Clear();
Thumbnail thumb;
foreach (Asset asset in m_Assets)
{
thumb = new Thumbnail( asset );
m_Thumbnails.Add( thumb );
thumb.ThumbnailDoubleClickedEvent +=
new WTMWClient.Thumbnail.ThumbnailDoubleClickedHandler(
thumb_ThumbnailDoubleClickedEvent);
thumb.Location = new Point(x, y);
this.Controls.Add(thumb);
thumb.Refresh(); // I expected this to force rendering
here. No luck!!
x += thumb.Width;
if ( x > this.Width-thumb.Width )
{
x = 0;
y += thumb.Height;
}
}
}
else
{
// no need to instantiate individual Thumbnails in this case.
// Rather, just grab each from the m_Thumbnails collection.
foreach (Thumbnail thumb in m_Thumbnails)
{
thumb.Location = new Point(x, y);
this.Controls.Add(thumb);
x += thumb.Width;
if ( x > this.Width-thumb.Width )
{
x = 0;
y += thumb.Height;
}
thumb.Refresh();
}
}
}
/// <summary>
/// Assign an Assets collection to be spanned via a set of thumbnails
on the panel...
/// </summary>
public Assets AssetsSource
{
set
{
m_Assets = value;
if (m_Assets.Count == 0) return;
PlaceThumbnails( true );
}
} // Property: AssetsSource
protected void thumb_ThumbnailDoubleClickedEvent( object sender,
ThumbnailDoubleClickedEventArgs e)
{
// MessageBox.Show( "clicked on: " + e.Asset.FileName );
if ( ThumbPanelDoubleClickedEvent != null)
{
ThumbPanelDoubleClickedEvent( sender, e );
}
}
}
}
I am creating an image browsing function within an application. As such, I
created a Thumbpanel control (shown below) which displays a collection of
thumbnails. Each thumbnail on that panel is also a custom control ( of a
class called Thumbnail) placed at a calculated location on the Thumbpanel.
It turns out to take 1+ seconds to construct and render each Thumbnail, so
in turn it takes MANY seconds to render the whole panel. Therefore I need
to force each Thumbnail to be rendered individually as they are constructed,
so that the user will not be confused by the frozen screen awaiting the
whole thing to render. I expected that the line:
thumb.Refresh();
.... would force the thumb object (of type Thumbnail) to be rendered upon
that call. But that didn't do the job.
Can someone give my guidance on how to force rendering of the individual
child controls (Thumbnails) in the order I specify?
Thanks,
-- Bruce
-------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace WTMWClient
{
/// <summary>
/// Summary description for ThumbPanel.
/// </summary>
public class ThumbPanel : System.Windows.Forms.Control
{
Assets m_Assets;
ArrayList m_Thumbnails;
bool m_Scrollable = false;
public delegate void ThumbPanelDoubleClickedHandler(object sender,
ThumbnailDoubleClickedEventArgs e);
public event ThumbPanelDoubleClickedHandler
ThumbPanelDoubleClickedEvent;
private System.ComponentModel.Container components = null;
public ThumbPanel()
{
InitializeComponent();
m_Assets = new Assets(); // Simply a default value so it will not
be null.
m_Thumbnails = new ArrayList();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
~ThumbPanel()
{
// ~base();
foreach (Thumbnail thumb in m_Thumbnails)
{
thumb.Dispose();
}
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// ThumbPanel
//
this.Dock = System.Windows.Forms.DockStyle.Fill;
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
// Calling the base class OnPaint
base.OnPaint(pe);
}
protected override void OnResize(EventArgs e)
{
base.OnResize (e);
PlaceThumbnails( false );
}
/// <summary>
/// Place each thumbnail in its proper position. Assumption is that
/// each thumbnail has already be constructed and placed in the
/// m_Thumbnails collection before this call.
/// </summary>
protected void PlaceThumbnails( bool isFirstDrawOfThisSetOfThumnails )
{
// Remove all the old ones. (But, dont "dispose" them, since they
// are still instantiated and held in m_Thumbnails.)
this.Controls.Clear();
// Place each one in proper position....
int x, y;
x = y = 0;
if ( isFirstDrawOfThisSetOfThumnails )
{
m_Thumbnails.Clear();
Thumbnail thumb;
foreach (Asset asset in m_Assets)
{
thumb = new Thumbnail( asset );
m_Thumbnails.Add( thumb );
thumb.ThumbnailDoubleClickedEvent +=
new WTMWClient.Thumbnail.ThumbnailDoubleClickedHandler(
thumb_ThumbnailDoubleClickedEvent);
thumb.Location = new Point(x, y);
this.Controls.Add(thumb);
thumb.Refresh(); // I expected this to force rendering
here. No luck!!
x += thumb.Width;
if ( x > this.Width-thumb.Width )
{
x = 0;
y += thumb.Height;
}
}
}
else
{
// no need to instantiate individual Thumbnails in this case.
// Rather, just grab each from the m_Thumbnails collection.
foreach (Thumbnail thumb in m_Thumbnails)
{
thumb.Location = new Point(x, y);
this.Controls.Add(thumb);
x += thumb.Width;
if ( x > this.Width-thumb.Width )
{
x = 0;
y += thumb.Height;
}
thumb.Refresh();
}
}
}
/// <summary>
/// Assign an Assets collection to be spanned via a set of thumbnails
on the panel...
/// </summary>
public Assets AssetsSource
{
set
{
m_Assets = value;
if (m_Assets.Count == 0) return;
PlaceThumbnails( true );
}
} // Property: AssetsSource
protected void thumb_ThumbnailDoubleClickedEvent( object sender,
ThumbnailDoubleClickedEventArgs e)
{
// MessageBox.Show( "clicked on: " + e.Asset.FileName );
if ( ThumbPanelDoubleClickedEvent != null)
{
ThumbPanelDoubleClickedEvent( sender, e );
}
}
}
}