[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
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.
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
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
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.
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
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.
1 Attachment(s)
Re: Drawing a Color Border around TextBox - Need modification
Please find the attached file.
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
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.
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
Re: Drawing a Color Border around TextBox - Need modification
Done, Its is working Fine in picture box which is placed in frame. Thanks
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
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.
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
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.