CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2000
    Location
    CA, USA
    Posts
    88

    Drawing lines in PictureBox and UserControls ( not working for me )

    Hello all,

    I am trying to create a UserControl (UC) and within the UC I wanted to draw my own border around it. The problem is trying to create the lines. If you use

    UserControl.Line (X1, Y1)-(X2,Y2), Color, BF




    or


    ' This is contain within the UserControl
    PictureBox.Line (X1, Y1)-(X2,Y2), Color, BF




    Both raise a compile error of ( Expect: = ). So I change the syntax around to the following


    ' This is contain within the UserControl
    PictureBox.Line X1,Y1, X2, Y2, Color, BF




    Ok, this doesn't give me a compile error, but it sure doesn't work correctly. So out of desperation I put a PictureBox and two Lables ( Text1 and Text2 ) within a form an added the following code to see if I can figure it out what in the world is going on.


    private m_X as Single
    private m_Y as Single

    private Sub Picture1_Click()
    With Picture1
    .DrawWidth = 1
    .DrawStyle = vbSolid
    .FillColor = vbRed
    .ForeColor = vbRed
    .CurrentX = 10
    .CurrentY = 10
    .Line 1, 1, m_X, m_Y, vbRed, 0
    End With

    End Sub

    private Sub Picture1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    Text1.Text = X
    m_X = X
    Text2.Text = Y
    m_Y = Y
    End Sub




    But this doesn't work. It seems that when I move the mouse vertically then click within the Picture box the ending x coordinate of the line moves, but no matter where I move the mouse on the horizontal plane does it affect the ending x coordinate. Please, what am I missing????? I am so confused. In addition, I don't want to fill create any boxes or fill anything, but if I leave off the BF it tells me the arugment is not optional. What is the deal here? This is also try for the Color aspect of the parameters being passed into the Line method. If you search the on-line by pressing F1 it list the standard


    object.Line [step] (x1, y1) [step] - (x2, y2), [color], [b][F]




    Which doesn't seem to apply for the the Line method for either the PictureBox or a UserControl.

    Mark


  2. #2
    Join Date
    Jul 2000
    Location
    CA, USA
    Posts
    88

    Re: Drawing lines in PictureBox and UserControls ( not working for me )

    Hello all,

    Ok, after working on this for another hour. I have found out some information, but it is only through trial and error. This is what I found out so far.


    .Line Style, Start_X, Start_Y, End_X, End_Y, Unknown




    This is what I have..

    Style = 0 Line starting where CurrentX and CurrentY are define, uses the color you define by .ForeColor

    Style = 2, 3, 6, 7 Same as style 0 - 1, but uses a black pen.

    Style = 16 Draws rect starting at CurrentX and CurrentY

    Style = 32 Draws rect starting at Current X and Y and fills it

    Style = 52 Draws rect starting at Start_X and Start_Y

    Style = 64 Same as style 0

    There are many variations to list. So I am guess this method is different than they list in the help when pressing F1 on .Line in the code window. Does anyone know the true definition of this method?

    Mark


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Drawing lines in PictureBox and UserControls ( not working for me )

    The following code works just fine for me. JUST MAKE SURE YOU HAVE AUTOREDRAW=TRUE for the picturebox

    private Sub Command1_Click()
    Dim wid, hght
    wid = 1000
    hght = 1000
    Picture1.Line (0, 0)-(wid, hght)
    End Sub



    AUtoredraw= True probably is needed for User Control also

    John G

  4. #4
    Join Date
    Jul 2000
    Location
    CA, USA
    Posts
    88

    Re: Drawing lines in PictureBox and UserControls ( not working for me )

    John,

    I found another little piece of my puzzle, not sure why this is. If I preceed the .line with the actual control name as in your sample code it will not give me a compile error, but if I use a With block it will generate the compile error. Something seems to be pointing somewhere else if you don't preceed the .Line with the actual control. Is this a bug?

    Mark


  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Drawing lines in PictureBox and UserControls ( not working for me )

    According to MSDN Help for the LINE METHOD Quote
    '
    "This Method cannot be used in an With..End block"

    John G

  6. #6
    Join Date
    Jul 2000
    Location
    CA, USA
    Posts
    88

    Re: Drawing lines in PictureBox and UserControls ( not working for me )

    John,

    Thanks, for the insight. I wonder why you can't use it in a WITH block? It must be calling some other function, but I wonder what that function is.

    Mark


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured