locked
Lines in Picture Box

    General discussion

  •  

    No matter how I try, I can't get a line shape to show on top of a picture box. When I drag the shape onto the control, it shows, but immediately upon release it goes behing. I have several pictureboxes, and simply telling them to go to the back does not work as they have to be at different levels... I've tried to set the top one to the back, first, then the next and the next to try to get them in order, but the line shape still goes to the back. If only there was a right click on them to adjust the %^&&#*$ order.
    Sunday, September 23, 2007 11:25 PM

All replies

  • The line and shape controls are designed, just like their VB6 predecessors, to be at the bottom of the z-order.

     

    If you which to draw a line on a picture box you could do this at runtime with code similar to the following example that draws an orange line horizontally across the middle of a picturebox control:

     

    Dim intY As Integer = PictureBox1.Height / 2

     

            PictureBox1.CreateGraphics.DrawLine(Pens.Orange, PictureBox1.ClientRectangle.Left, intY, PictureBox1.ClientRectangle.Right, intY)

     

    Monday, September 24, 2007 6:28 PM
  • Thanks, now how to erase.

     I am using a verticle line that moves across the picturebox, but using your example, I would delay a little, and try to erase the line. But inplace of Pens.Orange, I would want to use the Picturebox1.BackColor . How does one convert that to a pens color or something legal in the first parameter of DrawLine?

    Barry

     

    Tuesday, September 25, 2007 2:27 AM
  • To use the same color as the PictureBox.BackColor all you need to do is create a new pen.

     

    For example:

     

    Dim intY As Integer = PictureBox1.Height / 2

    Dim p As New System.Drawing.Pen(PictureBox1.BackColor)

    PictureBox1.CreateGraphics.DrawLine(p, PictureBox1.ClientRectangle.Left, intY, PictureBox1.ClientRectangle.Right, intY)

     

     

    To remove the line simply call:

     

    PictureBox1.Refresh

    Tuesday, September 25, 2007 7:35 PM
  •  berick wrote:

    Thanks, now how to erase.

     I am using a verticle line that moves across the picturebox, but using your example, I would delay a little, and try to erase the line. But inplace of Pens.Orange, I would want to use the Picturebox1.BackColor . How does one convert that to a pens color or something legal in the first parameter of DrawLine?

    Barry

     

     

    Hi,

     

    Do you want to move the line once across the picturebox or continuosly from say left to right or right to left or bounce the line between the sides like a scanning-line-effect?

     

     

     

    Regards,

     

    John

     

    Monday, October 01, 2007 12:58 PM
  • Hi berick,

     

    Are you after doing something like this? >>>>

     

    Add'

    • 1 Timer and
    • 1 PictureBox

     

    to a FORM >>

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Timer1.Interval = 5
            Timer1.Enabled = True
            Timer1.Start()
            PictureBox1.BackColor = Color.Black
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
            Dim pen1 As New Pen(Color.White, 1)
            Dim pen2 As New Pen(Color.Black, 1)
            Dim picTop As Integer = PictureBox1.ClientRectangle.Top
            Dim picBottom As Integer = PictureBox1.ClientRectangle.Bottom
            Static position As Integer = 1
    
            PictureBox1.CreateGraphics.DrawLine(pen2, position - 1, picTop, position - 1, picBottom)
            PictureBox1.CreateGraphics.DrawLine(pen1, position, picTop, position, picBottom)
            If position = PictureBox1.Right Then position = 0
            position += 1
    
        End Sub
    
    End Class
    

     

    Regards,

    John

     

    • Edited by John Anthony Oliver Saturday, July 25, 2009 6:07 AM Updated post from the old forum 'CODE BLOCK'
    Wednesday, October 03, 2007 2:25 AM
  • This line should be able to move in either direction and also be dragged. This is an audio scope, such as used in a audio editor.

     

    Thursday, October 04, 2007 11:45 AM
  • Using the draw line code up above, is it  possible to set coordinates? as i want to create a line that goes between two cartesian coordinate points.


    If you're not living on the edge, you're taking up too much room
    Wednesday, July 22, 2009 12:34 PM
  • Using the draw line code up above, is it  possible to set coordinates? as i want to create a line that goes between two cartesian coordinate points.


    If you're not living on the edge, you're taking up too much room

    Hi Miller_a,

    Yes of course.

    Option Strict On
    
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim point1 As New Point(20, 50)
            Dim point2 As New Point(160, 70)
    
            Dim MyPen As New Pen(Color.Blue, 1)
            Me.CreateGraphics.DrawLine(MyPen, point1, point2)
    
        End Sub
    End Class
    


    Regards,

    John
    Saturday, July 25, 2009 1:24 AM
  • This line should be able to move in either direction and also be dragged. This is an audio scope, such as used in a audio editor.

     


    Hi berick,

    Sorry for the delayed reply to your question, but I still do not know how to do that, sorry.

    I know what you mean though , in a similar fashion to the vertical line that can be dragged in an audio editor
     that would be a start or end marker for a section.


    Regards,

    John

    Saturday, July 25, 2009 6:53 AM