Results 1 to 16 of 16

Thread: [RESOLVED] Drawing a Color Border around TextBox - Need modification

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Resolved [RESOLVED] Drawing a Color Border around TextBox - Need modification

    Dears,

    I have downloaded the code to draw color border around text box, it is working fine if text boxes are placed on Form, the code is not working if text boxes are placed in Frame Control. I need help to make it possible.
    The code is as under

    In Module
    Code:
    Public ctl As Control
    
    Public Sub drawborder(cntl As Control, inout)
        createborder cntl.Parent, cntl.Top - 30, cntl.Left - 30, cntl.Top + cntl.Height + 15, cntl.Left + cntl.Width + 15, inout
    End Sub
    
    Public Sub eraseborder(cntl As Control)
        createborder cntl.Parent, cntl.Top - 30, cntl.Left - 30, cntl.Top + cntl.Height + 15, cntl.Left + cntl.Width + 15, 2
    End Sub
    
    Public Sub createborder(formf As Form, topf, leftf, bottf, rightf, inout)
    If inout = 0 Then
        Dim clr1 As Long, clr2 As Long, au As Long
        clr1& = RGB(66, 158, 238) ''QBColor(8)
        clr2& = RGB(66, 158, 238) ''QBColor(15)
        
        End If
        au& = formf.AutoRedraw
        formf.AutoRedraw = True
        formf.Line (leftf, topf)-(rightf, topf), clr1
        formf.Line (leftf, topf)-(leftf, bottf), clr1
        formf.Line (leftf, bottf)-(rightf + 15, bottf), clr2
        formf.Line (rightf, topf)-(rightf, bottf + 15), clr2
        formf.AutoRedraw = au&
    End Sub
    
    
    Public Sub GoDraw(frm As Form)
        For Each ctl In frm.Controls
            If TypeOf ctl Is TextBox _
            Or TypeOf ctl Is CommandButton Then
                
                drawborder ctl, 0
            End If
        Next
    In Form
    Code:
    Private Sub Form_Load()
        GoDraw Me
    End Sub

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Drawing a Color Border around TextBox - Need modification

    Put your TextBox inside a PictureBox and place the PictureBox inside the Frame. Make sure the ScaleMode property of the PictureBox is the same as the Form's. Call the PictureBox's Line method instead of the Form's.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Drawing a Color Border around TextBox - Need modification

    Hafiz

    Perhaps if you also set .Zorder 0 for each of the Lines in your Sub createborder,
    it might work, such as

    formf.Line.Zorder 0

    Spoo

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Drawing a Color Border around TextBox - Need modification

    Dear Bonnie West,
    I have done as suggested but it is giving error "Type Mismatch" and highlighting the below
    Code:
    Public Sub drawborder(cntl As Control, inout)
        createborder cntl.Parent, cntl.Top - 30, cntl.Left - 30, cntl.Top + cntl.Height + 15, cntl.Left + cntl.Width + 15, inout
    End Sub

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Drawing a Color Border around TextBox - Need modification

    You'll have to modify createborder's formf As Form parameter to formf As Object. The reason your code isn't working with the Frame control is because graphics output (Line, Circle, etc.) on the Form is always behind any control. Thus, if you want to see the color border, you'll have to draw it to a control which supports graphics output, such as the PictureBox. Of course, that complicates things. Therefore, you'll have to make some adjustments to your code so it knows when to draw to either the Form or the PictureBox. You'll also have to take into consideration the different coordinates of both Form and PictureBox.

    BTW, you should give most of your Sub's parameters proper data types, such as Single. Right now, most of them are all Variants, which is inefficient. Also, if you haven't done so, turn on Option Explicit.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Drawing a Color Border around TextBox - Need modification

    Done, but not effecting text box placed in picture box
    Code look like this
    Code:
    Public Sub createborder(formf As Object, topf As Single, leftf As Single, bottf As Single, rightf As Single, inout)
    If inout = 0 Then
        Dim clr1 As Long, clr2 As Long, au As Long
        clr1& = RGB(66, 158, 238)
        clr2& = RGB(66, 158, 238)
        
        End If
        au& = formf.AutoRedraw
        formf.AutoRedraw = True
        formf.Line (leftf, topf)-(rightf, topf), clr1
        formf.Line (leftf, topf)-(leftf, bottf), clr1
        formf.Line (leftf, bottf)-(rightf + 15, bottf), clr2
        formf.Line (rightf, topf)-(rightf, bottf + 15), clr2
        formf.AutoRedraw = au&
    End Sub
    if its wrong, then please send the modified code which will clear my concepts

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Drawing a Color Border around TextBox - Need modification

    Perhaps it might be helpful if you posted a screenshot of your Form. Or better yet, attach your project. Because like I said, things will get complicated once you have 2 or more "canvasses" to draw to.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Drawing a Color Border around TextBox - Need modification

    Please find the attached file.
    Attached Files Attached Files

  9. #9
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Drawing a Color Border around TextBox - Need modification

    Here is a small code, will need adjustement if you put DrawWidth higher!
    Code:
    Dim Ctrl As Object
    For Each Ctrl In Me
      If TypeOf Ctrl Is CommandButton Or TypeOf Ctrl Is TextBox Then
        DrawWidth = 1
        Line (Ctrl.Left - 15, Ctrl.Top - 15)-(Ctrl.Left + Ctrl.Width, Ctrl.Top - 15), vbRed                       'Top Border Line
        Line (Ctrl.Left - 15, Ctrl.Top)-(Ctrl.Left - 15, Ctrl.Top + Ctrl.Height), vbRed                           'Right Border Line
        Line (Ctrl.Left - 15, Ctrl.Top + Ctrl.Height)-(Ctrl.Left + Ctrl.Width, Ctrl.Top + Ctrl.Height), vbRed     'Bottom Boder Line
        Line (Ctrl.Left + Ctrl.Width, Ctrl.Top - 15)-(Ctrl.Left + Ctrl.Width, Ctrl.Top + Ctrl.Height + 15), vbRed 'Right Border Line
      End If
    Next Ctrl

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Drawing a Color Border around TextBox - Need modification

    Dear Max,
    Thanks for the code,
    It is also not working if the text box is placed in Frame Control.

  11. #11
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Drawing a Color Border around TextBox - Need modification

    It will need to look if the control has a parent and if it does the line will have to be drawn in that parent.
    Also I dont think frame has a line function, so in this case maybe use a picturebox instead of a frame would be a start.
    The PictureBox had a line function. Also you can do the same with a PictureBox as with a Frame.
    You will have to modify the DrawWidth to PictureBox.DrawWidth and Line to PictureBox.Line

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    852

    Re: Drawing a Color Border around TextBox - Need modification

    Done, Its is working Fine in picture box which is placed in frame. Thanks

  13. #13
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Drawing a Color Border around TextBox - Need modification

    Max

    Hey, you're right .. Frame control does not support the Line Method.
    My earlier ZOrder suggestion was doomed to failure from the get-go.

    Spoo

  14. #14
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Drawing a Color Border around TextBox - Need modification

    Spoo

    I thought maybe of using Line control instead of the function but some controls the line cannot go infront. The line function will not go infront either but is a bit easier to use, less code.

    I did not check if frame did have Line function but I knew it didn't because I had never drawn on a frame, I would always ise Picturebox. Picturebox can be the same as a frame, if you really need a frame.

  15. #15
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: [RESOLVED] Drawing a Color Border around TextBox - Need modification

    What I have done in the past is use a Shape control.
    You can play with it's properties, until the border is what you want.
    If you have multiple Textboxes you can use a control array of shapes.
    You can manually position and size them 'around' (cough) your textboxes, in the IDE.
    or
    Just have code in the Form Load event to position them, and resize them.
    If you are using the latter, you can even just have one shape with it's left at -999 (off the visible screen), and it's index set to 0. Then you can add copies to the control array via code, and then position and resize them.

    Rob

  16. #16
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Drawing a Color Border around TextBox - Need modification

    Why not just put the textbox inside of a picturebox, set picturebox's backcolor to the color of the border and resize the picturebox and move the textbox to get the desired border width around the textbox.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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