473,395 Members | 1,571 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.

Line on graphic object is not drawn from origin i've choosen.

Hi

Graphics pea = e.Graphics;
Point [] ptTable = { pictureBox1.Location , new
Point(pictureBox1.Location.X +
pictureBox1.Width,pictureBox1.Location.Y + pictureBox1.Height) };

pea.DrawLines(new Pen(Brushes.Black, 1), ptTable);

Line is simply drawn not from the 0,0 where control has it's
origin....
Does anyone know why this happens?
same situation is when i try to use pea.DrawImage

Pixels in left column and upper row are shorter than other pixels...

Aug 20 '07 #1
3 1386
Piotrekk wrote:
Graphics pea = e.Graphics;
Point [] ptTable = { pictureBox1.Location , new
Point(pictureBox1.Location.X +
pictureBox1.Width,pictureBox1.Location.Y + pictureBox1.Height) };

pea.DrawLines(new Pen(Brushes.Black, 1), ptTable);

Line is simply drawn not from the 0,0 where control has it's
origin....
Does anyone know why this happens?
In what class does your code exist? What is that class's relationship
to the pictureBox1 instance?

And is there a good reason you're using DrawLines() instead of DrawLine()?

Finally, you are leaking pens. Not that it has anything to do with your
question, but you need to dispose Pen objects if you create them. A
better approach would be to simply use the built-in black pen
(Pens.Black), since you aren't using a non-default size for the pen.

Undoubtedly, the line is getting drawn exactly where you are telling
DrawLines() to draw it. The only question is why are you mistaken about
what you are telling DrawLines() to do. I suspect the answer has
something to do with how the Location property of the pictureBox1 class
relates to the control in which you're actually doing the drawing, but
you didn't post enough code to adequately show that.

If you post a concise-but-complete example of code that reliably
reproduces the problem, you may get more specific advice.

Pete
Aug 20 '07 #2
If you post a concise-but-complete example of code that reliably
reproduces the problem, you may get more specific advice.

Pete
Ok
Here how it goes:

void Panel2_Paint(object sender, PaintEventArgs e)
{
Graphics pea = e.Graphics;

Rectangle rect = new Rectangle(0, 0, 600,600);
pea.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.Nearest Neighbor;
pea.DrawImage(this.image, rect);
}

this.Image is 15x15.
Panel2 is rightmost panel in splitter.

Problem is shown in this picture:
http://mion.elka.pw.edu.pl/~pkolodzi/aaa.JPG
Aug 20 '07 #3
Piotrekk wrote:
I see no sense in putting Designer generated Code.
I'm sorry that even after being told that a complete example of code is
necessary, you don't believe that to be true.

The fact is, the code you've posted so far does nothing to tell us how
the various controls are related to each other. As I've already
mentioned, I'm sure that the line is being drawn exactly where you tell
it to be drawn. The only question is why you think you're telling it to
be drawn somewhere else.

I think the most likely answer is that the Location property of the
pictureBox1 control is relative to a different control than the one in
which you are drawing. But you refuse to post enough code to verify
that, and there's no way to know for sure that that's actually the problem.

So, you are without an answer.

I'm sorry, but I've offered as much information as I can at this point.

Pete
Aug 20 '07 #4

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

Similar topics

3
by: pacemkr | last post by:
Is it possible to force a control to paint to a Graphics object (or Device Context, or a bitmap, anywhere aside from the form) that I provide. I am writing a windows form class that supports...
6
by: Peter Oliphant | last post by:
I'm working with Graphics transforms (i.e., RotateTranform, TranslateTransform and ScaleTransform ). Are these applied to the WORLD (graphics container) before drawing into that world (graphics...
1
by: ray well | last post by:
hi, i need to give the user the ability to extract a rectangular area of their choice from a graphic displayed in a picture box to the clipboard, so they can use it elsewhere. say the graphic...
5
by: Simon Friso | last post by:
Hello, I'm looking for a graphic control I can use in .NET. I need the following features: - drawing shapes - filling shapes with color, gradient or texture - drawing splines, arcs and...
6
by: randy1200 | last post by:
I'm using Visual Studio 2005 and C#. I need to print a WinForm used for data entry as a graphic. In other words, I need to print the exact WinForm the user sees on the screen. I searched through...
1
by: icepick72 | last post by:
On an academic note, I want to copy a Graphic to an Image (Bitmap). I have the Graphic object but not the origin image from which it originates; this is because I'm overriding the PrintDocument...
2
blazedaces
by: blazedaces | last post by:
Hey, I have an application that draws a polyline with Graphics': g.drawPolyline(getXPoints(),getYPoints(),nPoints); It's drawn onto a background image and so the background image is so many...
9
by: koschwitz | last post by:
Hi, I hope you guys can help me make this simple application work. I'm trying to create a form displaying 3 circles, which independently change colors 3 times after a random time period has...
1
by: nt5515 | last post by:
hey Im trying to make a game of pairs (the memory game) i have set up a grid which displays a graphic for the card back. im trying to link the edit menu to choose the graphic to be displayed. i've...
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.