Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

VS 2010 How to grab bitmap from usercontrol?

$
0
0
Hi,

I made a usercontrol which will become a kind of chart. I want to draw a ruler (vertical line on the chart, where the mouse pointer is) when the mouse is moved around over my usercontrol.
I manage to draw the ruler, but I still need a method to grab the bitmap under the ruler (I mean not the whole bitmap, just the line under the ruler), so I can place it back whenever the ruler's position changes.

this is my code:

Code:

Public Class UserControl1

    Private Sub ShapeContainer1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ShapeContainer1.MouseMove
        ' Draw the ruler
        ShapeContainer1.CreateGraphics.DrawLine(New Pen(Color.FromArgb(255, 255, 0), 1), e.X, 1, e.X, ShapeContainer1.Height - 2)
    End Sub

    Private Sub ShapeContainer1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShapeContainer1.Resize
        Border.Width = ShapeContainer1.Width - 1
        Border.Height = ShapeContainer1.Height - 1
    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.ShapeContainer1.BackColor = Color.Black
        Me.Border.Left = 0
        Me.Border.Top = 0
        Me.Border.Width = ShapeContainer1.Width - 1
        Me.Border.Height = ShapeContainer1.Height - 1
        Me.BackColor = Color.Black
    End Sub
End Class

I would like to use a bitmap that is available as long as the instance of my usercontrol exists.

Running the code above results in continuous drawing of rulers wherever the mouse comes, until the whole control is filled with rulers.

How should I do this?

Viewing all articles
Browse latest Browse all 42220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>