Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Piotrekk - 20 Aug 2007 19:37 GMT
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...
Peter Duniho - 20 Aug 2007 19:46 GMT
> Graphics pea = e.Graphics;
>
[quoted text clipped - 7 lines]
> 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
Piotrekk - 20 Aug 2007 20:01 GMT
> 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
Peter Duniho - 20 Aug 2007 23:16 GMT
>> If you post a concise-but-complete example of code that reliably
>> reproduces the problem, you may get more specific advice.
[quoted text clipped - 13 lines]
>             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
Piotrekk - 20 Aug 2007 23:24 GMT
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)

> 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
[quoted text clipped - 7 lines]
>
> Pete
Peter Duniho - 21 Aug 2007 00:41 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.