473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Drawing text on a panel

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
1 3387
vekipeki
229 Expert 100+
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

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

Similar topics

2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
3
by: Alberto | last post by:
I'm drawing an image in a panel control with this sentence in the Paint method: e.Graphics.DrawImageUnscaled(Image, panelImage.AutoScrollPosition); The problem is that I only want to paint a...
5
by: BluDog | last post by:
Hi I am trying to draw text in a panel. I want the width of the panel to be fixed but the height to be determined by the number of lines the text needs to cover in the panel. I also want to be...
1
by: Niels Jensen | last post by:
Hi guys, I have the following code which is supposed to draw a grid in a panel consisting of a specified number of squares. I can get it to draw the grid and activate the autoscroll feature,...
11
by: dongarbage | last post by:
Hi there, I'm very much a C# novice. How do you do freehand drawing on a panel with a mouse in c#? Thanks, Don
12
by: Matt Bitten | last post by:
I've got a wxPython program that needs to do some drawing on a DC on a regular basis, whether or not a paint event happens. I know how to make a ClientDC to do the drawing in, and I know what...
4
by: RobinS | last post by:
I am drawing a rectangle on a picture that has already been drawn on the graphics area (a user control). It works something like this: //in the MouseDown event m_isDragging = true; m_oldX =...
4
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I've windows form, in this form i've a panel. I want to draw lines inside the panel using the panel coordinates( meaing that the left upper corner of the panel is 0,0), how can i do it? ...
1
by: YouPoP | last post by:
I am doing an app (C# 2.0) where you can draw in a panel with your mouse in "real time". I actually have 2 problems; 1- it does not really is "real time", if your mouse move fast or very fast the...
0
by: BarryM | last post by:
Iv got a panel on the main form which is set to auto scroll. In the panel there is a picture box that i draw lines in. the lines work perfectly fine until the scroll bar comes up. The picture box...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.