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)