0

I am drawing items on a bitmap and want to set the PB_Visualizer picturebox to the size needed to fit all the drawn items. I first set the bitmap and PB_Visualizer to a known size and reset the overdrawn offset NEG and POS values to 0. PB_Visualizer and BB_VIS top and left are the same location.

    PB_Visualizer.Width = 5
    PB_Visualizer.Height = 5


    BB_Vis = New Bitmap(PB_Visualizer.Width, PB_Visualizer.Height)

    Offset_POS_Last = New Point(0, 0)       '// Reset
    Offset_NEG_Last = New Point(0, 0)

I then test all the points PixleVisualizerPoint and if they exceed width and height then add the amount they exceeded to the offset. I do this for both X and Y and test for negative.

If PixleVisualizerPoint(ArrString_Nodes_Array(StringNumbertouse)(Row)).X + int_VisGridSpace > PB_Visualizer.Width Then
                        bln_Colision = True
                        Offset_Temp.X = PB_Visualizer.Width - PixleVisualizerPoint(ArrString_Nodes_Array(StringNumbertouse)(Row)).X + int_VisGridSpace
                        Offset_POS.X = PB_Visualizer.Width - PixleVisualizerPoint(ArrString_Nodes_Array(StringNumbertouse)(Row)).X + int_VisGridSpace

If Offset_POS.X < 0 Then
Offset_POS.X = (Offset_POS.X * -1)
End If
If Offset_POS_Last.X < Offset_POS.X Then
Offset_POS_Last.X = Offset_POS.X
Console.WriteLine("POS X   " & Offset_POS_Last.X)
End If

I then take the exceed offset POS and NEG values and add them to the known start values and set the PB_Visualizer. The size is half of the needed width and height needed. The Offset_POS are always negative numbers where I assume they would all be positive since they always exceed to points beyond width and height. Am I missing something?

PB_Visualizer.Height = PB_Visualizer.Height+ (Offset_NEG_Last.Y + Offset_POS_Last.Y)
PB_Visualizer.Width =  PB_Visualizer.Width+(Offset_NEG_Last.X + Offset_POS_Last.X)
AAA
  • 3,520
  • 1
  • 15
  • 31
Bobby
  • 659
  • 2
  • 13
  • 26

1 Answers1

0

This is the new code I am using. Just checking all the point and getting the most right and most bottom to set the window size. It works fine.

Private Sub SetLayoutSize()

    Dim Offset_POS_Last As Point
    Offset_POS_Last = New Point(0, 0)       '// REset

    For i = 0 To intSoftware_Total_Pixels
        If PixleVisualizerPoint(i).X > Offset_POS_Last.X Then
            Offset_POS_Last.X = PixleVisualizerPoint(i).X
        End If

        If PixleVisualizerPoint(i).Y > Offset_POS_Last.Y Then
            Offset_POS_Last.Y = PixleVisualizerPoint(i).Y
        End If
    Next
    '// Check size if less then increase
    If PB_Visualizer.Height < Offset_POS_Last.Y + int_VisGridSpace Then
        PB_Visualizer.Height = Offset_POS_Last.Y + int_VisGridSpace
        bln_Resize = True

    End If

    If PB_Visualizer.Width < Offset_POS_Last.X + int_VisGridSpace Then
        PB_Visualizer.Width = Offset_POS_Last.X + int_VisGridSpace
        bln_Resize = True
    End If

    Center_of_Drawing.X = PB_Visualizer.Width / 2
    Center_of_Drawing.Y = PB_Visualizer.Height / 2

End Sub
Bobby
  • 659
  • 2
  • 13
  • 26