Link to home
Start Free TrialLog in
Avatar of therealmongoose
therealmongooseFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB 2005 - image/graphics on user control



I have a user control on which a bitmap image is painted using a graphics object (i.e. not a background image). I need to be able to capture a section of the bitmap in the mouse move event so as mouse moves, rectangle section (rct.x = e.x, rct.y = e.y, rct.width = 100, rct.height = 100) of the existing graphic is captured to an image object variable, and then transferred as the texture of a new brush object which is used to paint a copy of the defined section on a different area of the user control.

Any code examples of how to do this much appreciated...
Avatar of therealmongoose
therealmongoose
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Here's the code I need help with....
Imports System.Drawing
 
Public Class UserControl1
 
    Dim rectCopy As Rectangle
    Dim imgCopy As Image
    Dim bBrushCopy As TextureBrush
    Dim rctPaintTo As New Rectangle(5, 70, 50, 50)
 
    Sub drawrect()
 
        Dim rect As New Rectangle(5, 5, 300, 50)
        Dim bBrush As New TextureBrush(My.Resources.Image1)
 
        Using g As Graphics = Me.CreateGraphics
 
            g.FillRectangle(bBrush, rect)
 
        End Using
 
    End Sub
 
    Private Sub UserControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
 
        rectCopy.X = e.X
        rectCopy.Y = e.Y
        rectCopy.Width = 50
        rectCopy.Width = 50
 
        'capture screen section to imgCopy - size and location of rectCopy
        '=======================
        ' How do I copy a section of the screen to the image control?
        '
        imgCopy = ????
        '=======================
 
        bBrushCopy = New TextureBrush(imgCopy)
 
        Using g As Graphics = Me.CreateGraphics
 
            g.FillRectangle(bBrushCopy, rctPaintTo)
 
        End Using
 
 
    End Sub
 
 
    Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
 
        drawrect()
 
    End Sub
 
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bruce_1975
Bruce_1975

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cool - thanks Bruce - just enough to let me solve it...

Dim pt As Point = Me.PointToScreen(New Point(e.X, e.Y))
(Point pt = this.PointToScreen(new Point(e.X, e.Y));)
 Was the bit I was missing - thanks for your time...