Showing results 1 to 4 of 4

Thread: How to Update (Repaint or Refresh) screen after color change ?

  1. #1
    veselyd Gast

    Unglücklich How to Update (Repaint or Refresh) screen after color change ?

    Hello,
    I have a question which is connected with VBA. I want to change background color of button on a screen, when I click on that.

    First step is: Change Background - for example
    obElem.BackColor = RGB(100,100,100)

    Second step is: Update or repaint the new color of button. (To know which screen was selected).
    Could you please help me how to do it ? (Something like obElem.Update ? )

    Is there any function, or method ?

  2. #2

    Default Re: How to Update (Repaint or Refresh) screen after color change ?

    Sub change_color()
    Dim myElem As Element
    Dim myScrn As DynPicture
    Set myScrn = thisProject.DynPictures.Item("a")
    If Not myScrn Is Nothing Then
        Set myElem = myScrn.Elements.Item("aa")
        If Not myElem Is Nothing Then
            myElem.BackColor = RGB(89, 58, 12)
        End If
        myScrn.UpdateAll
    End If
    
    End Sub

    You can use the UpdateAll method to redraw the sreen. However this change will only last while the screen is open. After a reopen the button will show it's original color again.

    Generally I would recommend to use the dynamic background color through a variable, which can be configured in the editor, instead of doing this by VBA in the runtime.
    Last edited by markclemens : 22nd June 2010 at 00:12

  3. #3
    veselyd Gast

    Default Re: How to Update (Repaint or Refresh) screen after color change ?

    Thank you so much. I try it.

  4. #4
    josefm Gast

    Default Re: How to Update (Repaint or Refresh) screen after color change ?

    Hello everyone,

    I tried that solution and created a test project with a (hopeful enough) description.

    Feel free to also expand the project and upload your ideas, I would appreciate it.

    Following is the description that also can be found inside the project (Static Text Element on start screen).

    For understanding how the project works:
    ---------------------------------------- zenon Logic ----------------------------------------
    The zenon Logic (straton) project ist just creating random values.
    Once it creates 3 random values (0-255) for the each of the colors ..
    - red
    - green
    - blue
    .. but it also creates out of those three the according hexadecimal value with a # before looking like e.g. #AA55FF or #29A09C.
    As you can convert it back in VBA/VSTA/zenon Logic I thought it makes no sense to convert it back again in another module at the moment.
    -------------------------------------------- VBA --------------------------------------------
    The VBA does the main functionality in the project.
    There are two functions that can be performed. Once the function "change_color()" and once the functions "Project_Active()", "zOLV_VariableChange()" and "Project_Inactive()" that belong together because this is the way we use the online container.
    change_color()
    This function mainly grabs the actual values and executes the coloring of the element via the function "Element.Background = RGB(R, G, B)".
    It also has some mechanism that it should not crash if the screen or the element has the value "Nothing". At the end it updates all elements on the screen so that the new color is also displayed on the element.
    Project_Active()
    It creates the OnlineVariable container (OLC) and adds the three straton variables to the OLC. That the function works it also sets the global color variables to the initial value 0 (otherwise I would have errors on the first execution).
    zOLV_VariableChange()
    It's parameter is the changed variable. To make it easier to use more functionality it also uses the trigger variable (which is not nessecary). If the trigger equals 1 it does the coloring automatically otherwise it does not.
    It grabs the changed values and depending on which of those variables was changed, it recolors the element using the actual changed color and the other two global color values. If no one of the colors changed it returns to the debug screen "No color changed!".
    At the end it updates all elements on the screen so that the new color is also displayed on the element.
    Project_Inactive()
    Deactivates the "VariableChange" event and sets the OLC to nothing.
    --------------------------------------- zenon Project ---------------------------------------
    When you now start the zenon Runtime the zenon Logic project should start automatically.
    Depending on the value of the variable next to "Change BG automatically" the values will be changed everytime the values are set new.
    To make it happen faster/slow you have to change the "Timer" variable. The "RED", "GREEN", "BLUE" and "HEXVALUE" should usually just display the values, but you can also change them. On the "HEXVALUE" it won't take any effect but on "RED", "GREEN" and "BLUE" it will change the value and if you have the automatic mode "ON" then it also changes the color of the rectangle or if it is on "OFF" you have to click "Refresh Color".


    Best regards
    Attached Files Attached Files
    Last edited by josefm : 1st May 2013 at 21:38

Similar Threads

  1. Update von 6.22 SP1 auf 6.5 SP0
    By martin@bmw in forum zenon Supervisor
    Replies: 4
    Last Post: 2nd June 2010, 13:35
  2. CEL- text color
    By hoscillada in forum zenon Supervisor
    Replies: 1
    Last Post: 21st December 2009, 10:38
  3. Replies: 1
    Last Post: 14th December 2009, 02:23
  4. Option button background color wrong
    By russelldrown in forum VBA
    Replies: 19
    Last Post: 5th May 2009, 12:51
  5. Update pictures with VBA
    By fabios in forum VBA
    Replies: 5
    Last Post: 21st July 2008, 09:25

Posting Rules

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