reseting the text in a textbox

Post

Posted
Rating:
#1 (In Topic #521)
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
Is there a way to reset the text of a text box to the text assigned in the properties

Code (gambas)

  1. For Each oObj In dataaray.Children
  2.          oObj.text = ""   '  I would like this to reset to the text in the properties text
  3.     Next
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’
My only suggestion is that you use the .Tag property.

At the start of your program copy initial text to Tag, something like:-

Code (gambas)

  1. For Each oObj In dataaray.Children
  2.          oObj.Tag = oObj.Text  '  store initial properties text
  3.     Next

Then you can get it back:-

Code (gambas)

  1. For Each oObj In dataaray.Children
  2.          oObj.Text = oObj.Tag  '  restore the text in the properties text
  3.     Next
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
Thanks that worked !

I have a lot to learn  ;)
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’
 The Tag property is often under-used (or over-looked) but its great for poking things away that you might need later.
It often saves you creating a Public variable, and as its a Variant, its very flexible.
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
It looks like this will  also do the same thing. I needed to use "Try" because dataaray has both text and value boxes.
This will leave Tag for other uses  ;)

Code (gambas)

  1.         For Each oObj In dataaray.Children
  2.          Try oObj.Placeholder = oObj.Text
  3.     Next

Code (gambas)

  1.  For Each oObj In dataaray.Children
  2.         Try oObj.Clear
  3.     Next

TextBox.Placeholder (gb.qt4)

Property Placeholder As String

Return or set the placeholder text, i.e. the text displayed when the Text property is void.
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
This is a routine that I use to prepare the controls on a form for validation.
The passed container is normally a panel or frame which contains all the 'maintenance' controls.
{text boxes, text areas, combo boxes, checkboxes etc…}
It will then recursivity search for controls and then set their chosen parameters to whatever it is that I need using the
Object.SetProperty & Object.getProperty commands.
This allows you to overcome the limited set of parameters exposed when you examine the child controls.

The main one is to Trim the text input areas as this overcomes a common problem with user input.
The InColour is used to return the display colour of a control back to a standard. In most cases this is black.
As part of a validation routine, I turn the label for the control red if an error is detected to assist the user in
quickly identifying where the error is.

Code (gambas)

  1. Public Sub FormPrepareForValidation(InControl As Object, InColor As Integer)
  2.  
  3.   Dim ControlElement As Control
  4.  
  5.   For Each ControlElement In InControl.Children
  6.     If ControlElement Is Frame Then FormPrepareForValidation(ControlElement, InColor) ' It may have children so do a recursive search"
  7.     If ControlElement Is Panel Then FormPrepareForValidation(ControlElement, InColor) ' It may have children so do a recursive search"
  8.     If ControlElement Is Label Then Object.SetProperty(ControlElement, "ForeGround", InColor)
  9.     If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
  10.     If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", Trim(Object.getProperty(ControlElement, "Text")))
  11.     If ControlElement Is RadioButton Then Object.SetProperty(ControlElement, "ForeGround", InColor)
  12.     If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "ForeGround", InColor)
  13.     If ControlElement Is TabPanel Then Object.SetProperty(ControlElement, "ForeGround", InColor)
  14.     If ControlElement Is TabStrip Then Object.SetProperty(ControlElement, "ForeGround", InColor)
  15.   Next
  16.  
  17.  

This subroutine uses the same concepts to Reset a container's controls, ready to accept new input.

Code (gambas)

  1. Public Sub FormResetControls(InControl As Container)
  2.  
  3.   Dim ControlElement As Control
  4.   Dim ChildControl As Control
  5.   Dim TmpInt As Integer
  6.   Dim TPanel As TabPanel
  7.   Dim TStrip As TabStrip
  8.  
  9.  For Each ControlElement In InControl.Children
  10.     If ControlElement Is Frame Then FormResetControls(ControlElement) ' It may have children so do a recursive search
  11.     If ControlElement Is Panel Then FormResetControls(ControlElement) ' It may have children so do a recursive search
  12.     If ControlElement Is TabPanel Then
  13.       TPanel = ControlElement
  14.       For TmpInt = 0 To TPanel.Count - 1
  15.         FormResetControls(Tpanel[TmpInt]) ' It may have children so do a recursive search
  16.       Next
  17.     Endif
  18.     If ControlElement Is TabStrip Then
  19.       TStrip = ControlElement
  20.       For TmpInt = 0 To TPanel.Count - 1
  21.         FormResetControls(TStrip[TmpInt]) ' It may have children so do a recursive search
  22.       Next
  23.     Endif
  24.     If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Text", "")
  25.     If ControlElement Is TextBox Then Object.SetProperty(ControlElement, "Background", Color.White)
  26.     If ControlElement Is TextArea Then Object.SetProperty(ControlElement, "Text", "")
  27.     If ControlElement Is TextEditor Then Object.SetProperty(ControlElement, "Text", "")
  28.     If ControlElement Is ComboBox Then Object.SetProperty(ControlElement, "Index", 0)
  29.     If ControlElement Is ValueBox Then Object.SetProperty(ControlElement, "value", Null)
  30.     If ControlElement Is CheckBox Then Object.SetProperty(ControlElement, "value", 0)
  31.     If ControlElement Is SpinBox Then Object.SetProperty(ControlElement, "Value", Object.GetProperty(ControlElement, "MinValue"))
  32.    
  33.   Next

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
Technopeasant is in the usergroup ‘Regular’

stevedee said

The Tag property is often under-used (or over-looked) but its great for poking things away that you might need later.
It often saves you creating a Public variable, and as its a Variant, its very flexible.

I had a bad habit of using it to store information that should be have been delineated as part of its own class file though. Like for game logic values. :lol:
Online now: No Back to the top
1 guest and 0 members have just viewed this.