Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have 2 forms. form1 and output form. output form is a video player and form1 monitors it through picturebox on form1. Theres also so many mini forms comes on top of output form like logos, watermark etc. This output form has to be displayed on second monitor(in future). I want to move forms that comes on top of output form from the picture box on form1. like a remote desktop.

What I have tried:

Public Class Form1
    Dim mouseDownLocation As Point
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        out.Show()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Try
            Dim bounds As Rectangle = Screen.PrimaryScreen.Bounds
            Dim screenshot As New Bitmap(bounds.Width, bounds.Height)
            Using g As Graphics = Graphics.FromImage(screenshot)
                g.CopyFromScreen(bounds.Location, Point.Empty, bounds.Size)
            End Using
            PictureBox1.Image = screenshot
        Catch s As Exception
            PictureBox1.Refresh()
        End Try
    End Sub

    Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = MouseButtons.Left Then
            mouseDownLocation = e.Location
        End If
    End Sub

    Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
        Try
            If e.Button = MouseButtons.Left Then
                out.Left += e.Location.X - mouseDownLocation.X
                out.Top += e.Location.Y - mouseDownLocation.Y
            End If
        Catch x As Exception
            PictureBox1.Refresh()
        End Try
    End Sub

    Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
        If e.Button = MouseButtons.Left Then
            mouseDownLocation = Point.Empty
        End If
    End Sub

End Class
Posted
Updated 19-Feb-23 0:45am
v2
Comments
OriginalGriff 19-Feb-23 6:28am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project.
Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.
Dave Kreskowiak 19-Feb-23 11:52am    
"form1 monitors it through picturebox on form1"

That makes no sense at all. A PictureBox control does one thing, displays an image. That's it. It doesn't "monitor", whatever that means, anything at all.
sharath Nandakumar 19-Feb-23 13:43pm    
please go through my code. you will get an idea :)
Dave Kreskowiak 19-Feb-23 13:54pm    
It looks like you're doing a remote desktop kind of thing, but doing it the hard way. It also will give you very slow frame rates as the amount of data you have to transfer per frame is quite large, depending on resolution, you're looking at upwards of 25MB PER FRAME.

Oh, and you're leaking resources too by not properly disposing each Bitmap object before you replace it.

sharath Nandakumar 20-Feb-23 1:59am    
yes. but remote desktop of same computer. i have acheied a bit further.

Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
For Each f As Form In Application.OpenForms
If f.Bounds.Contains(e.Location) Then
formBeingMoved = f
formOffset = New Point(e.Location.X - f.Left, e.Location.Y - f.Top)
Exit For
End If
Next
End Sub

Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If formBeingMoved IsNot Nothing Then
formBeingMoved.Left = e.X - formOffset.X
formBeingMoved.Top = e.Y - formOffset.Y
End If
End Sub

Private Sub PictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
formBeingMoved = Nothing
End Sub


but what happens now is i am able to move forms. but notclicking on exact position of form showing in picturebox

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900