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 / Windows Forms / WinForm General / March 2008

Tip: Looking for answers? Try searching our database.

Drawing Lines in a Picturebox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Tuersley - 18 Mar 2008 08:02 GMT
Hi,

I have a series of x, y coordinates that I am trying to draw in a
picturebox. I am able to draw lines okay - the problem is trying to draw the
overall shape to the extents of the picturebox. My "image" comes in way too
small. What am I missing? Below are out takes of my code that should show
what I have so far:

       Dim width As Integer = PicBox1.Width
       Dim height As Integer = PicBox1.Height
       Dim bmp As New Bitmap(width, height)
       Dim g As Graphics = Graphics.FromImage(bmp)
       ' set up the drawing surface to draw in the picturebox
       g.PageUnit = GraphicsUnit.Point
       g.PageScale = 4
       _myPen = New Pen(_myForeColor, 1)

       g.DrawLine(_myPen, _
           _myContour.Vertices.Item(iCntr).PtX, _
           _myContour.Vertices.Item(iCntr).PtY, _
           _myContour.Vertices.Item(0).PtX, _
           _myContour.Vertices.Item(0).PtY)

      PicBox1.Image = bmp

   Public Structure Contour
       Dim Vertices As List(Of Vertex)
   End Structure

   Public Structure Vertex
       Dim PtX As Single
       Dim PtY As Single
       Public Sub New(ByVal X As Single, ByVal Y As Single)
           Me.PtX = X
           Me.PtY = Y
       End Sub
   End Structure
Morten Wennevik [C# MVP] - 18 Mar 2008 10:42 GMT
Hi Mike,

That's not easy to say because you aren't showing us how you calculate the
_contour, but most likely this is due to you setting PageUnit to Point and
PageScale to 4, which basically makes the bitmap to appear zoomed in on the
upper left corner.

Signature

Happy Coding!
Morten Wennevik [C# MVP]

> Hi,
>
[quoted text clipped - 33 lines]
>         End Sub
>     End Structure
Mike Tuersley - 18 Mar 2008 14:20 GMT
Thanks Morten,

The _contour is not calculated - it's a list of x,y values that are kicked
out of a spreadsheet. I'm not sure I follow on the PageUnit and PageScale -
what should they be?

> Hi Mike,
>
[quoted text clipped - 40 lines]
> >         End Sub
> >     End Structure
Morten Wennevik [C# MVP] - 18 Mar 2008 14:53 GMT
> Thanks Morten,
>
> The _contour is not calculated - it's a list of x,y values that are kicked
> out of a spreadsheet. I'm not sure I follow on the PageUnit and PageScale -
> what should they be?

The default values for PageUnit is Pixel, and PageScale is 1.0.  If you are
unsure if you need them otherwise I would leave them out altogether.  
Changing PageScale up or down will cause any drawing using that graphics
object to be scaled up or down relative to 1. The PageUnit property is used
for drawing on various "surfaces" where one unit might not be equal to a
single pixel.

Signature

Happy Coding!
Morten Wennevik [C# MVP]


Rate this thread:







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.