Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27355

Scale Graphics to Image or create custom co-ordinates?

$
0
0
Hey,

I am currently working on drawing out wire diagrams , I get all the co-ordinates from another program and simply draw them out in a picture box.

vb.net Code:
  1. Private Sub test(Optional mark As Boolean = False)
  2.  
  3.         Dim Img As New Bitmap(PictureBox1.Width, PictureBox1.Height)
  4.  
  5.         Dim g As Graphics = Graphics.FromImage(Img)
  6.  
  7.         g.Clear(Color.White)
  8.  
  9.         Dim graphiccounter As Integer = 0
  10.      
  11.         Dim result As Object
  12.         'Needed to get co-ordinates
  13.         Dim x() As Object
  14.         Dim y() As Object
  15.         Dim z() As Object
  16.         Dim results As Object
  17.  
  18.         'Will take in x and y values from objects above
  19.         Dim x_loc(0) As Integer
  20.         Dim y_loc(0) As Integer
  21.  
  22.  
  23.          _Paths.Clear()
  24.         namepath.Clear()
  25.  
  26.         For Each row As DataGridViewRow In DataGridView2.Rows
  27.  
  28.             If row.Visible = True Then
  29.                 'sets variables to nothing, needed in order to run certain commands
  30.                 results = Nothing
  31.                 x = Nothing
  32.                 y = Nothing
  33.                 z = Nothing
  34.  
  35.              
  36.  
  37.                 'get the co-ordinates and stores them in x,y,z. results will contain the number of co-ordinates stored.
  38.                 result = cor.GetPath(x, y, z)
  39.                
  40.                 're declares variables based on how many co-ordinates
  41.                 ReDim x_loc(result)
  42.                 ReDim y_loc(result)
  43.  
  44.  
  45.          
  46.                 counter = 1
  47.  
  48.                 _Paths.Add(New GraphicsPath)
  49.                 namepath.Add(New NamedPath)
  50.                 For k = 1 To result - 1
  51.  
  52.                     x_loc(k) = (x(k))
  53.                     y_loc(k) = PictureBox1.Height - (y(k))
  54.                     x_loc(k + 1) = (x(k + 1))
  55.                     y_loc(k + 1) = PictureBox1.Height - (y(k + 1))
  56.                     spacer += 5
  57.  
  58.                    
  59.                         _Paths(graphiccounter).AddLine(x_loc(k), y_loc(k), x_loc(k + 1), y_loc(k + 1))
  60.                         namepath(graphiccounter).Name = row.Cells("Core_Id").Value
  61.                         namepath(graphiccounter).Path = _Paths(graphiccounter)
  62.                         'g.FillEllipse(Brushes.Black, x_loc(k + 1) - 4, y_loc(k + 1) - 4, 8, 8)
  63.  
  64.                         counter = counter + 1
  65.          
  66.  
  67.                 Next
  68.  
  69.  
  70.                 _Pen = New Pen(Brushes.HotPink, 5)
  71.                 g.DrawPath(_Pen, namepath(graphiccounter).Path)
  72.                 graphiccounter += 1
  73.  
  74.  
  75.                 '  Console.WriteLine("New Line")
  76.             End If
  77.         Next
  78.      
  79.         PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
  80.         PictureBox1.Image = Img
  81.  
  82.     End Sub

So that is my code, some of the code may look funky, but that is because I am using a COM object and Windows Script Host Model.

The results I get back in x and y and co-ordinates based on the other program's co-ordinates. Ofcourse it is easy for me to adjust the co-ordinates so that it works on my screen but how would I go about drawing it so that the image automatically redraws to size based on the window?

Is it possible to set the co-ordinate system of the GDI graphics? For example a setting to tell windows that every 10 points is just 1.

so for the picture box of height 100x100. The co-ordinates start at 0 and go to 400, making each point in the picturebox actually 0.25.

I am looking around for answer but any suggestions is appreciated :)

Viewing all articles
Browse latest Browse all 27355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>