Alex Alex - 9 months ago 62 Question

VB.NET Create a to a form attached Preview window

I want to create a little window which gets visible when I press a button and is attached to the main Form (like shwon below). I want to use this window to show preview of Images (I gonna have a Listbox and depending on which entry is selected, a picture is shown) How can I do this? And how can I be sure that the window will always be attached to the main Form (not depending on resolution). I tried to do it with a second form, but I can't fix it in the correct position.



Assuming your preview form class is frmPreview and you open it this way:

Private mPreviewForm As frmPreview Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click mPreviewForm = New frmPreview mPreviewForm.Show() AttachPreviewForm() End Sub

Then you must reposition it every time the main form is changing size or location:

Private Sub AttachPreviewForm()
    If mPreviewForm IsNot Nothing Then
    End If
End Sub
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
End Sub
Private Sub Form1_LocationChanged(sender As Object, e As EventArgs) Handles Me.LocationChanged
End Sub

And in the frmPreview:

Public Sub AttachForm(parent As Form)
    Location = New Point(parent.Left + parent.Width, parent.Top)
    Size = New Size(200, parent.Height)
End Sub