I toying with a project where I can position objects runtime on the screen. I also have an small "preview"-window, where I want to see the outline of the objects.
I have an object array who have size and location on the "scene". Now I want to loop through my scene-objects and create one picturebox in the preview-window for each object in the "scene".
So, I have the size of the "Scene" and an array of the objects that are visible on the scene. Every object have an size and location mapped to the scene.
I also have a preview window that have an dynamic size. How do I create a preview that scales down to the preview window? To make it easy, I loop through the scene objects in the scene and create a picturebox on the preview-form for each object, that uses the preview-forms size to do the scaling.
SceneSize=new size(800,600)
PreviewSize=new size(80,60)
For each obj as SceneObject in Scene
dim p as new picturebox
p.size=?? scaling here (we have obj.size and obj.location)
p.location=?? scaling here (we have obj.size and obj.location)
previewWindow.controls.add (p)
next
Any example in .Net would be nice.
Thanks.
This did the trick, it wasn't harder than that.
Function GetPreviewRectangleForObject(ByVal ScreenSize As Size, ByVal PreviewSize As Size, ByVal OriginalRect As Rectangle) As Rectangle
Dim xFactor As Integer = ScreenSize.Width / PreviewSize.Width
Dim yFactor As Integer = ScreenSize.Height / PreviewSize.Height
With OriginalRect
Return New Rectangle(.X / xFactor, .Y / yFactor, .Width / xFactor, .Height / yFactor)
End With
End Function