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

P

Piotrekk

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...
 
P

Peter Duniho

Piotrekk said:
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
 
P

Piotrekk

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.NearestNeighbor;
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
 
P

Peter Duniho

Piotrekk said:
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.NearestNeighbor;
pea.DrawImage(this.image, rect);
}

That is NOT a complete code example. You've only provided the Paint
handler, and not a single other thing. There's no way for anyone to see
exactly how that Paint event handler is being used.

You've also not answered any of the specific questions I asked.

You will get better assistance if you are willing to put in the effort
that's asked of you for the purpose of clarifying your question and
providing the details required in order to answer it.

Pete
 
P

Piotrekk

I see no sense in putting Designer generated Code. I can only put
constructor here:

public Form2(Image arg)
{
InitializeComponent();

image = arg;


splitContainer1.Panel2.Paint += new
PaintEventHandler(Panel2_Paint);
}

As i told : image is 15x15. Any errors connected with image are not
possible. Image is checked and tested.

In what class does your code exist? What is that class's relationship
to the pictureBox1 instance?

This is clear form : public partial class Form2 : Form

Instead of pictureBox1 I draw explicitly on Panel2 (RHS Panel of
splitter which is simply added from ToolBox)
 
P

Peter Duniho

Piotrekk said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top