Results 1 to 2 of 2
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code: fmrHeader - changing the colours

    Here's the code to make use of the COLOURS button. COLOURS was one of four buttons (Colours, Captions, Fonts, Icons) which were loaded somewhat messily onto the form. They're still large and very visible - just as we want them at this stage.


    My original "initialize" code was set up because I was designing forms and colour-coding groups of controls during development (the Module Manager generated tabbed forms on the fly and dis all sorts of weird things). Rather than go back and painfully reset each colour to a standard value once the GUI form was completed (View, Properties, one-by-one click on a control, browse the colour pallette ...) I realized that it would be faster to write VBA code to visit each control. Hence the Initialize routine of yesterday.

    Once I'd done that, I realized that I didn't know what RGB codes would be suitable, so I wrote a TINY piece of code to loop through all values, all 256*256*256 of them. It was VERY late at night. Two minutes later I introduced randomizing and a call to strPP to save the "best" combination. The client thought that this was the best aprt of the form (doesn't say much for the rest of it), so I developed Captions to demonstarte that I could change languages on the pop-up help baloons on-the-fly, and then in a fit of boredom, did the GUI form fonts and mouse pointers too.

    Hence the four buttons.

    So, today is the Colours button. Tomorrow the Captions button.




    When you double-click on the Colours button, you'll be taken into the VBE and you'll have a chance to complete the click event button as shown here:

    <pre>Private Sub cmdColours_Click()
    Call U.cmd_ColoursClick(Me)
    End Sub
    </pre>



    You'll need to paste the "cmd_ColoursClick" function into your U module. Don'r be put off. It's really just a linear block of code calculating integer values and storing them in a string which we'll save to the INI file via the strPP function.


    <pre>Public Sub cmd_ColoursClick(frmMe As UserForm)
    ' Procedure : cmd_ColoursClick
    ' Description: Change the colors on all buttons to a new standard combination.
    ' Copyright: Chris Greaves Inc.
    ' Inputs: A Word97 GUI form.
    ' Returns: None.
    ' Assumes: None.
    ' Side Effects: None.
    ' Tested: By a call from the user.

    ' Re-seed the randomizer (probably from the system clock)
    Randomize

    ' Will accumulate a new string of colours. See cmd_UserFormInitialize
    Dim strColours As String
    ' We start with a null, the delimiter character, the base (usually 256)
    ' and another delimiter.
    strColours = str(0) & strcINIFileDelimiter & str(intcBase) & strcINIFileDelimiter

    ' Values for Background Colour Red (Blue and Green)
    Dim intBCR As Integer, intBCB As Integer, intBCG As Integer

    ' Background RED code
    While InStr(strColours, str(intBCR)) ' loop until a unique colour is made.
    intBCR = Rnd * intcBase ' generate a fresh colour.
    Wend
    strColours = strColours & str(intBCR) & strcINIFileDelimiter ' append to colours string
    ' Background BLUE code
    While InStr(strColours, str(intBCB)) ' loop until a unique colour is made.
    intBCB = Rnd * intcBase ' generate a fresh colour.
    Wend
    strColours = strColours & str(intBCB) & strcINIFileDelimiter ' append to colours string
    ' Background GREEN code
    While InStr(strColours, str(intBCG)) ' loop until a unique colour is made.
    intBCG = Rnd * intcBase ' generate a fresh colour.
    Wend
    strColours = strColours & str(intBCG) & strcINIFileDelimiter ' append to colours string

    ' Values for Foreground Colour Red (Blue and Green)
    Dim intFCR As Integer, intFCB As Integer, intFCG As Integer
    ' Foreground RED code
    intFCR = Rnd * intcBase ' generate a fresh colour.
    strColours = strColours & str(intFCR) & strcINIFileDelimiter ' append to colours string
    ' Foreground BLUE code
    intFCB = Rnd * intcBase ' generate a fresh colour.
    strColours = strColours & str(intFCB) & strcINIFileDelimiter ' append to colours string
    ' Foreground GREEN code
    intFCG = Rnd * intcBase ' generate a fresh colour.
    strColours = strColours & str(intFCG) & strcINIFileDelimiter ' append to colours string

    ' Now make use of the colours to set the Background and Foreground colours.
    Dim myControl As Control
    For Each myControl In frmMe.Controls
    myControl.BackColor = RGB(intBCR, intBCB, intBCG)
    myControl.ForeColor = RGB(intFCR, intFCB, intFCG)
    Next myControl

    ' Values for Background Screen Red (Blue and Green)
    Dim intBSR As Integer, intBSB As Integer, intBSG As Integer
    While InStr(strColours, str(intBSR)) ' loop until a unique colour is made.
    intBSR = Rnd * intcBase ' generate a fresh colour.
    Wend
    strColours = strColours & str(intBSR) & strcINIFileDelimiter ' append to colours string
    While InStr(strColours, str(intBSB)) ' loop until a unique colour is made.
    intBSB = Rnd * intcBase ' generate a fresh colour.
    Wend
    strColours = strColours & str(intBSB) & strcINIFileDelimiter ' append to colours string
    While InStr(strColours, str(intBSG)) ' loop until a unique colour is made.
    intBSG = Rnd * intcBase ' generate a fresh colour.
    Wend
    strColours = strColours & str(intBSG) & strcINIFileDelimiter ' append to colours string

    ' Now make use of the colours to set the Form colours.
    frmMe.BackColor = RGB(intBSR, intBSB, intBSG)

    ' Preserve these settings in the application INI file
    Call strPP(strcApplication, strcColours, strColours, strcApplication)

    ' We no longer trace/log the colour change
    ' Call ERL("0013", intcErrorInform, strColours)

    ' I don't know why I repaint at this point.
    frmMe.Repaint
    End Sub
    </pre>




    That's it. Fire up the form (F5 function key) and click repeatedly on the Colors button. Inspect your INI file from time to time. Note that the Colours key value changes.

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Code: fmrHeader - changing the colours

    Here's a PKZip file of sample.dot.

    If you fire up this interim template you should see a toolbar with cmd_GUI on it.
    Attached Files Attached Files

Posting Permissions

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