Alpha Video Training
Results 1 to 14 of 14

Thread: change form background colour

  1. #1
    Jeremy Packman
    Guest

    Default change form background colour

    I have set up a 'rolodex' name and address file. Nothing fancy. I want to be able to make the form background white for 'cash' customers and blue for 'credit' customers.I know I have to set up a field/variable being cash or credit. But how do I incorporate this into automatically changing the form background dependent on the field contents?

    Thanks in anticipation

    Jeremy Packman

  2. #2
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default RE: change form background colour

    Put some code in the OnFetch event of the form. I don't know the syntax off the top of my head, but something to the effect of:

    If Customer.value = "Cash"
    this.background = "white"
    Else if Customer.value = "Credit"
    this.background = "blue"
    end if

    Assuming that the Customer Field OBJECT name is "Customer".
    In the code editor look at the Xbasic Explore objects/windows/your form name/properties/...

  3. #3
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,649

    Default RE: change form background colour

    Oh yeah. You might have to end the script with:

    this.refresh()

    It may or may not be necessary.

  4. #4
    Jeremy Packman
    Guest

    Default RE: change form background colour

    Thanks Peter
    I tried it and if I did it right, I got an 'Action Program Error' when going into the form. It said:
    Trapped error in action command:(1)
    Command: Inline Xbasic
    Error: Object does not support requested interface.

    followed by Abort/Retry/Ignore


    Any suggestions????

    Jeremy

  5. #5
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,173

    Default RE: change form background colour

    Instead of this.background = "white" try

    parentform.fill.forecolor = "white"

    Worked for me on a test form and parentform will make it portable for any form regardless of name.

    Jerry

  6. #6
    Jeremy Packman
    Guest

    Default RE: change form background colour

    I've tried all the above, but still get error message when entering the form saying:
    Action Program Error
    Trapped error in action command(1)
    Command:inlinebasic
    Error: Object does not support requested interface.

    Can someone explain what this means and perhaps talk me through what I need to do step-by-step from the beginning.I presume it is a form object..onfetch command I need. Maybe i'm not creating the xbasic properly since i copied the script lines exactly and checked for accuracy.

    Your help would be much appreciated.

    Jeremy

  7. #7
    Jim Rowlen
    Guest

    Default RE: change form background colour

    In the form's onSave() event I use
    :Ords_Rapid_Field_Results.fill.forecolor = "DARK RED"
    to let the user know not to do anything while the computer is running a large script, and
    :Ords_Rapid_Field_Results.fill.forecolor = "DARK BLUE"
    to let the user know it's ok to continue (usually just flashes on fast systems).

    Using the form (or other object's) name with the command it always works (until you save the form with a different name). For some reason I've always had problems using "this" and parentform" commands. I found that explicitly naming the object works. Since A5 puts underscores where there are spaces between parts of an object's name, (and since I forget syntax once in a while) I try to use A5's Xbasic Explorer.

    On the menu bar in the code editor there is a little wrench. If you click this you get a box to select various things from. Select
    Objects
    Windows
    (whatever your form's name is)
    Properties
    Fill
    and then highlight Forecolor
    Click/drag forecolor to your script and release the mouse button where you want it. A5 will fill out the entire command, you just add specifics such as color. One thing to watch is to make sure you don't release the dragged method or property in the middle of another xbasic statement. It can get a little messy if you do. I always release it in a blank line.


  8. #8
    Jeremy Packman
    Guest

    Default RE: change form background colour

    Thanks I'll give it a go. However will it work with what i want, which is to have the form show one of two different background colours for each record, depending on the content of a field. In other words if field 'PAYMENT_TYPE' shows CASH, then the background would be white, but if in another record the field was entered as CREDIT, the background of the form would be blue.

    Thanks in anticipation

    Jeremy

  9. #9
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,173

    Default RE: change form background colour

    Jeremy
    I have attached a little test app that has a form that does what you want. The table has one table, payment.dbf, with one field, payments. There are a number of test records with either Cash or Credit as the saved value. There is one form. I placed a small script on the OnFetch event

    tbl = table.current()
    if alltrim(tbl.payment) = "Credit"
    parentform.fill.forecolor = "Blue"
    else
    parentform.fill.forecolor = "white"
    end if

    This script changes the background color based on the fetched value of the field payments. Incidentally, I usually use xbasic scripting for simple scripts rather than action scripting.

    Jerry

  10. #10
    Former Alpha Employee JerryBrightbill's Avatar
    Real Name
    Jerry Brightbill
    Join Date
    Apr 2000
    Posts
    5,173

    Default RE: change form background colour

    Jim
    I agree that expressly stating the form name is more stable than using "this" and "parentform", but I am lazy and like to create one script for many forms and operations. I avoid using the "this" reference as I never seem to know what has focus, but "parentform" usually worked ok except in cases where there are subforms and similar complications. I have had good luck using "topparent" in some cases.

    On perculiarity, "parentform" and "topparent" don't seem to work reliably in action scripting and inline xbasic, but never seem to give problems in a straight xbasic script. Since I use xbasic most of the time, I haven't had many problems.

    Jerry

  11. #11
    Jeremy Packman
    Guest

    Default RE: change form background colour

    Thanks Jerry and Jim, its much appreciated

    Jerry

  12. #12
    Jeremy Packman
    Guest

    Default RE: change form background colour

    And of course not forgetting Peter who originally replied to my problem. Thanks to you all

    Jeremy/Jerry

  13. #13
    Jeremy Packman
    Guest

    Default RE: change form background colour

    Jerry
    Your formcolorscript.zip worked a treat. But I want my form to have a tabbed object on it so that all of the tabbed pages as well as the main form background will be white or blue depending on the contents of the field.
    What extra do I have to do to achieve this? I've played around a bit with your script but can't seem to do it, the tabed pages stick to being grey regardless!!

    Thanks in anticipation

    Jeremy

  14. #14
    Jeremy Packman
    Guest

    Default RE: change form background colour

    Jerry
    Your formcolor.zip worked a treat. But I want my form to have a tabbed object on it so that all of the tabbed pages as well as the main form background will be white or blue depending on the contents of the field.
    What extra do I have to do to achieve this? I've played around a bit with your script but can't seem to do it, the tabed pages stick to being grey regardless!!

    Thanks in anticipation

    Jeremy

Similar Threads

  1. change font color and background
    By Romy Huang in forum Alpha Five Version 5
    Replies: 8
    Last Post: 12-17-2004, 08:03 AM
  2. font colour change
    By Ian_Edwards in forum Alpha Five Version 6
    Replies: 3
    Last Post: 10-30-2004, 11:59 PM
  3. Form background colors
    By Annita Merriweather in forum Upgrading to Alpha Five from Alpha Four
    Replies: 1
    Last Post: 12-26-2003, 07:08 PM
  4. Tabbed page background colour
    By Jeremy Packman in forum Alpha Five Version 4
    Replies: 1
    Last Post: 08-28-2000, 05:31 AM
  5. Can't change background color of text object
    By Carol Whaley in forum Alpha Five Version 4
    Replies: 6
    Last Post: 05-08-2000, 03:40 PM

Bookmarks

Posting Permissions

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