Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shape in front of textboxes?

Status
Not open for further replies.

BirdieNamNam

Programmer
Feb 12, 2004
52
0
0
SE
Hello dear friends!

I am programming in VB6. There, I want a shape (an transparant oval) to be placed on top of a grid of textboxes, to indicate the textbox selected. It seems like there is no way to place the shape in front of the boxes. Can it be like this?

Bring to front, and z-order does not affect it.

Strange?

/Sebastian.
 
From help on Zorder:

Three graphical layers are associated with forms and containers. The back layer is the drawing space where the results of the graphics methods are displayed. Next is the middle layer where graphical objects and Label controls are displayed. The front layer is where all nongraphical controls like CommandButton, CheckBox, or ListBox are displayed. Anything contained in a layer closer to the front covers anything contained in the layer(s) behind it. ZOrder arranges objects only within the layer where the object is displayed.

Since shape is a graphical object, the text will superceed it. There may be other ways to do what you want - maybe thru a user-drawn control.

BTW, does your handle refer to something in a Peter Seller's movie? :)


"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Ok, bugger...

Do you have a hint on these user-drawn controls?

/Sebastian.
 
See User-Drawn controls in VB help to see if that will work for you. It's got a fairly detailed explanation.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
OK, I did look there... I need a quick solution, and it does not seem to be that. Thanks anyway for your efforts!

/Sebastian.
 
How about using the backcolor to indicate the selected item?

You need a subroutine to change the color, and code in the textboxes' GetFocus and LostFocus events.
If the text boxes are arrays, you will type less code.

Heres the example:
Put two textboxes on a form, and paste this code in
When you tab about, the selected textbox will go yellow until it loses the focus again.

Code:
Private Sub ChangeColor(t As TextBox, bHasFocus As Boolean)
'bSelected is used to tell the sub
'whether the control has the focus.
If bHasFocus Then
    t.BackColor = vbYellow
Else
    t.BackColor = vbWhite
End If

End Sub

Private Sub Text1_GotFocus()
ChangeColor Text1, True
End Sub

Private Sub Text1_LostFocus()
ChangeColor Text1, False
End Sub

Private Sub Text2_GotFocus()
ChangeColor Text2, True
End Sub

Private Sub Text2_LostFocus()
ChangeColor Text2, False
End Sub
 
Hello Jeff!

I apriciate your suggestion, but it doesn't really work for me. I used already different colors to signal different types of bookings...

Well, I created another nice way, as I think, to visualize the selection. the boxes are aligned as a normal grid, next to each other in both axis. When a box is selected, I let i grow a little, so it looks like it is in front of the others. Works fine! I send you the relevant code, if interested:

Code:
txtSlot(index).Top = txtSlot(index).Top - (GrowSize / 2)
txtSlot(index).Left = txtSlot(index).Left - (GrowSize / 2)
txtSlot(index).Width = txtSlot(index).Width + GrowSize
txtSlot(index).Height = txtSlot(index).Height + GrowSize
txtSlot(index).ZOrder 0

And of course, with opposit signs, when de-selected.

Thanks for your efforts, Sebastian.
 
Fine. Same idea, different visual indicator.
Pity the text box does not have borderwidth property, eh?

You could also have had the textboxes Flat by default, and 3D when selected, which would mean you did not have to resort to even the amount of code above.
 
Hi again Jeff!

I tried that, but I didn't make it. I thought it was because the 3D/flat propertie could only be set in design stage. Or is there a way around that as well?

Anyway, I think my growing boxes showed up really well, so I'll stick to them. Thanks again.

/Sebastian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top