Link to home
Start Free TrialLog in
Avatar of mujanad
mujanad

asked on

making the background colour of a form transparent

Hi

I have put some code in my forms on load such that the background color changes at runtime.  
The problem is that there are frames on the forms.  I want the frames to be transparent so
that I can see the background color on the form.  Is this possible  or is it  easier to change
the background colour of the frame at runtime to the one i want?

The piece of code below is what i use to change the colour of the form at runtime and i want
to apply this to a frame if it's not possible to make the frame transparent.   I have tried
changing the background color of the frame at run time but have failed.  

Please let me know if it's possible to meke the frame transparent or change this piece of code
so that it applies to a frame.

Thanx
'**********
Sub ShadeForm1(Frm As Form)

Dim NumberOfRects As Integer
Dim GradColor As Long
Dim GradValue As Integer
   
   Frm.ScaleMode = 3
   Frm.DrawStyle = 6
   Frm.DrawWidth = 2
   Frm.AutoRedraw = True
   
   NumberOfRects = 64
   
   For i% = 1 To 64
   
      GradValue = 255 - (i% * 4 - 1)
      GradColor = RGB(62, GradValue, 255)
      Frm.Line (0, Frm.ScaleHeight * (i% - 1) / 64)-(Frm.ScaleWidth, Frm.ScaleHeight * i% / 64), GradColor, BF
   Next i%

   Frm.Refresh
End Sub


SOLUTION
Avatar of MapleTreeJoyce
MapleTreeJoyce

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mujanad
mujanad

ASKER

I think your idea is quite good
If i understand you well, I first get the background color of the form and then the frame takes
the color of the form as defined by the case statements?
Can you please explain this line
Select Case FrPairData(nr).bkgColorE
...if they are to be hte same colors, why can't you just say:
Frame1.BackColor = Form1.BackColor
About this line of code:
Select Case FrPairData(nr).bkgColorE

I just copied the sub from a portion of my program, and this is part of a USD that sets the background color variable string to either "blue", "purple," or "green."  I have a lot of things going on at once in this program, and one of those things is the background color scheme.  Other properties of FrPairData(nr) are coordinated with this background color.  When (nr) changes, all the properties change with it.

In this example, the form background color is set at the same time as the frame background colors.

If you want to set the frame background color after the form background color is set, I think RavenOfThought's example is quicker.  If you want to set the background colors at the same time, you could use something like I've given.  
In the above, when I typed USD, I meant UDT (User Defined Type).
'Put this in a form, and it will change every frame's backcolor to the form's backcolor
    Dim Fr As Frame
    For Each Fr In Controls
        On Error Resume Next
        Fr.BackColor = Me.BackColor
    Next Fr
Avatar of Richie_Simonetti
hearing...
I'm learning from you, RavenOfThought.  Out of curiosity, what kinds of errors might your last code raise?
Joyce
I don't exactly know. It gave me the error "Type Mismatch" on the line that only said "Next" after all the frames were changed. Next shouldn't raise a type mismatch! For whatever reason it may be, I included that line to skip it.
Oh, I know why it gave me an error. I added a control to the form dynamically, for another answer, and used the same form. Apparently, using Controls.Add doesn't allow you to test it when looping throuygh Controls. You do not need to include the "On Error Resume Next" line. Sorry.
I tried your code with a simple form and 2 frames.  I set the form background color at design time, and tried your code in Form_Load.  I also got a Type Mismatch error on the For line.  So I moved On Error Resume Next above the For line, and it worked.  Then I commented out the code in Form_Load, and put the code behind a command button.  It works there, too.

Thanks.  I can save some time the next time I'm working with several frames on a form.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Looping through the Controls collection can be very useful for allowing the user to change the color of your app, and to make it all the same color. You would declare a variable As either an Object, Variant, Control, or you don't even need to declare it As anything at all. However, some controls may not have a BackColor property, so you would need to skip over every possible error, using a resume next:
Dim Thinger
For Each Thinger In Controls
    On Error Resume Next
    Thinger.BackColor = Me.BackColor
Next
Any timers, scrollbars, etc. would have their errors skipped. Remember to keep one of these Resume statements INSIDE the loop, as it only skips one error, and breaks on the second. :)
Thanks again.  You are helping me.  I hope our discussion is helping mujanad, too.