July 29 2010




 
Search Blog Entries:



What is this?

Code Details
 
Painting on a tab page

Description: The relation between a TabControl and its TabPages is not always clear. Here is a little sample how to paint on a particular TabPage, making use of a Paint event handler. By just adding a new event handler, it is included in the chain of paint event handlers. It is a good practise to remove the paint handler again after we are done with it. In the example we already install a Paint event handler when the form hosting the TabControl is loaded and we remove the handler when the form is closed.

In this simple sample we install a paint handler that simply draws a line on a tabpage.

Code:

private void tabPage1_Paint(object sender, PaintEventArgs pe)
{
  Graphics gfx = pe.Graphics;
  gfx.DrawLine(new Pen(Color.Gold), 10, 10, 100, 100);
}
private void Form1_Load(object sender, System.EventArgs e)
{
  tabPage1.Paint += new PaintEventHandler(tabPage1_Paint);
}
private void Form1_Closing(object sender, 
System.ComponentModel.CancelEventArgs e)
{
  tabPage1.Paint -= new PaintEventHandler(tabPage1_Paint);
}






Send us your solutions, code, or advice. We might put it here on the site!
 
Back








SpiralFX Web Development
www.spiralfx.com


Do you want to learn developing a full blown Windows Mobile Application? This article and accompanying multimedia content will help you to do so. It will be extended over the upcoming weeks / months, so check back regularly.
 
Read Full Article