473,394 Members | 1,935 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,394 software developers and data experts.

Drawing on a panel

Here's a starter for 10 - I have the following simple code:

private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Color.Blue),
this.panel1.ClientRectangle);
}

Where a panel is on a form. I've always had to alter the 'rect'
variable as it doesn't draw the border correctly, the right and bottom
lines aren't in view. Any ideas why this is?

Mar 23 '06 #1
2 12934

Chris S. wrote:
Here's a starter for 10 - I have the following simple code:

private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Color.Blue),
this.panel1.ClientRectangle);
}

Where a panel is on a form. I've always had to alter the 'rect'
variable as it doesn't draw the border correctly, the right and bottom
lines aren't in view. Any ideas why this is?


It looks like there's a difference in meaning between the Rectangles.
This is easier to see if you draw very small controls and look at them
magnified in Paint or such.

- If you have a Panel with Size (2,2) then it does actually have a size
of 2 pixels by 2 pixels

- But if you do a DrawRectangle with a new Rectangle(0, 0, 2, 2) what
you actually get is what I would call a *three by three* rectangle. I
_guess_ this is because the 'zeroth' pixel is counted as well.

So you receive from ClientRectangle the first kind of Rectangle, which
then gets drawn 'one bigger' by DrawRectangle. Whether this is by
design or bug, I couldn't say. The comically auto-generated help is
no... um... help.

--
Larry Lard
Replies to group please

Mar 23 '06 #2
I'm not sure why the rectangle would be off, but I have noticed that
too. But you can minimize it by setting the pen's alignment to inset:

private void panel1_Paint(object sender, PaintEventArge e)
{
Pen p = new Pen(Color.Blue);
p.Alignment = PenAlignment.Inset;
e.Graphics.DrawRectangle(p, panel1.ClientRectangle);

//Be sure the dispose of the pen
p.Dispose();
}

You can experiement with other values of the Alignment property of the
pen.

Hope this helps

Mar 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Skidmore | last post by:
I am building an application that will fade one panel to another panel. Both panels will have picture boxes in them (thumbnails). This is what I have tried: private void...
2
by: Millennium Falcon | last post by:
Hi! In my application, I have a panel in the middle of the form, which I'll be using as a drawing panel. I would like to update the drawing panel each time when it is required, without updating...
13
by: Martin Ho | last post by:
I know this must be trivial for many of you. But I am playing with this and can't figure it out. I have a form, on that form is one panel which has 3 textboxes, when I run my program and...
6
by: QT | last post by:
Dear sirs, I want to create panel or label field for each database records. I am using following codes for each database row to create panel field. 'Panel ' i = 1
4
by: Sarika | last post by:
I migrated a VB6.0 application to VB.NET. This app has a drawing area, which is a panel. The user can drag and drop several objects on this drawing area and can also draw lines, boxes etc. The app...
7
by: Sharon | last post by:
I’m using the Panel control that contains a PictureBox control (for implementing the http://www.codeproject.com/cs/miscctrl/PictureBox.asp). The Panel is set to AutoScroll = true. I wish to...
3
by: Robert W. | last post by:
In my WinForms app I'd long ago implemented a drag & drop mechanism just like is used in PowerPoint when one wants to rearrange the order of the slides. Specifically, a thin black line is shown...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
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
3
by: zaklamp | last post by:
Hello, I am searching for a panel that allows me to pan and zoom but i still have to be able to select a object like a Button (so not a pure drawing panel). If anyone have an idee how to handle...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.