By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,326 Members | 2,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,326 IT Pros & Developers. It's quick & easy.

Drawing text on a panel

P: 1
I am trying to manually draw a rectangle with text inside of a panel. I have the code to do this but for some reason nothing is being drawn on the panel. It draws just fine on the main form but when I try to draw on the panel, nothing shows up.

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void panel1_Paint(object sender, PaintEventArgs e)
  3.         {
  4.                  Rectangle rec = new Rectangle(ITEM_PADDING, currentYPosition, (m_maxItemWidth - ITEM_PADDING), Height);
  5.  
  6.                  e.Graphics.DrawRectangle(blackPen, rec);
  7.  
  8.         }

Any help is greatly appreciated. Thank you.
Jan 12 '09 #1
Share this Question
Share on Google+
1 Reply


vekipeki
Expert 100+
P: 229
It should work, just check that your coordinates are ok and that blackPen is non-null. Try with some fixed coordinates first:

Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.     public Form1()
  4.     {
  5.         InitializeComponent();
  6.         this.panel1.Paint += new PaintEventHandler(panel1_Paint);
  7.     }
  8.  
  9.     void panel1_Paint(object sender, PaintEventArgs e)
  10.     {
  11.         e.Graphics.DrawRectangle(SystemPens.ControlDark, new Rectangle(0, 0, 20, 20));
  12.     }
  13. }
Jan 12 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.