Find container BackColor

A

ALESSANDRO Baraldi

Hi.

I need to find Control(parent) backcolor, the control was Image control.

If parent was Form i use Control Section property:

GetParentBackColor =Me.Section(objControl.Section).BackColor

If my control was located on TabControl i presume i've to test BackStyle
property =Trasparent(this was OK).
In this case i get TabControl Section BackClor... may be right.

but if BackStyle was not Trasparent... how can i find SystemColor used for
TabControl or real color show by system...?

I Loop trought all 24 SystemBrushcolor, but i can't find the real color i
need...

Any suggest will be precious.

tnx
 
S

Stephen Lebans

Here is a previous post of mine on this subject. You will havew to adapt it
for your particular situation.
It works for System Color Constants(ex. vbButtonFace), COM color values and
standard RGB values as well.

Open your Form in Design view.
Open the Properties window and go to the Events Tab
For the OnLoad event click on the little arrow and select Event
Procedure
Next to the little arrow you just clicked is three small dots. Click on
these.
YOu are now looking at the class module behind the Form

1) At the very top of the Form just under these two lines add the API
declaration:
Option Compare Database
Option Explicit


Private Declare Function OleTranslateColor Lib "oleaut32.dll" _
(ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As
Long


Now back in the Load event sub add the code to change the backcolor
property


Private Sub Form_Load()
' Save the control's original dimensions
Dim lngColor As Long
Dim lngRet As Long
lngRet = OleTranslateColor(Me.Section(acDetail).BackColor, 0&,lngColor)
Me.customerdatasheet.Form.DatasheetBackColor = lngColor
End Sub


That's it!



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
A

ALESSANDRO Baraldi

Stephen Lebans said:
Here is a previous post of mine on this subject. You will havew to adapt it
for your particular situation.
It works for System Color Constants(ex. vbButtonFace), COM color values and
standard RGB values as well.

Open your Form in Design view.
Open the Properties window and go to the Events Tab
For the OnLoad event click on the little arrow and select Event
Procedure
Next to the little arrow you just clicked is three small dots. Click on
these.
YOu are now looking at the class module behind the Form

1) At the very top of the Form just under these two lines add the API
declaration:
Option Compare Database
Option Explicit


Private Declare Function OleTranslateColor Lib "oleaut32.dll" _
(ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As
Long


Now back in the Load event sub add the code to change the backcolor
property


Private Sub Form_Load()
' Save the control's original dimensions
Dim lngColor As Long
Dim lngRet As Long
lngRet = OleTranslateColor(Me.Section(acDetail).BackColor, 0&,lngColor)
Me.customerdatasheet.Form.DatasheetBackColor = lngColor
End Sub


That's it!


Hi Stephen.
My request was different unfortunatly... was not the same as in the private
mail, and this solution you give me
change Control(Datasheet) Back Color not Gray Area... ;-)

For this truble i try to give more info, with my bad english... ;-)

I use a Image(control) to draw a personal Graphic Button:
1) I create an hDC_Tmp
2) I draw graphic button with Icon and RoundedRect XP_Style with gradient
ecc....
3) With your code on(pictureBox Demo) i convert hDC trought DIB on
PictureData so i have my XP_BUTTON

In my opinion is a nice demo.

If the Image control was located on Form(every section) work very fine, i
detect Section BackColor
to give to Button trasparent aspect on Border.

Here you can find this demo, much part of it are Lebans made.

http://www.alessandrobaraldi.it/DettaglioFaq.asp?IdFAQ=290

My prboblem occur when the control is located on TabControl(not trasparent)
or over Shape(rectancle widh color).
In this case i need to find the Graphical BackColor(around the image
control) to set it into hDC_Tmp and
obtain trasparency of Corner, because my Graphical button have rounded one
as i said...!

I have no idea, so i try to capture the area around the Image control on hDC
and get Pixel color, but unforunatly this solution work good only if the
Form was just painted(it's normal)... but i need to get the color on LOAD...

Public Function GetBackColor() as Long
' m_hWndSection it's the hWnd of Image(Control) Section
Dim hDC_S As Long
Dim hDC_Tmp As Long
Dim rct As RECT
Call GetWindowRect(m_hWndSection, rct)
With rct

hDC_S = GetDC(m_hWndSection)
hDC_Tmp = GetDC(0)

' I need only ONE PIXEL NEAR IMAGE
.Left = .Left + fTwipsToPixels(m_ImgBtn.Left, 1) - 1
.Right = .Left + 1
.Top = .Top + fTwipsToPixels(m_ImgBtn.Top, 0) - 1
.Bottom = .Top + 1

Call BitBlt(hDC_Tmp, .Left, .Top, 1, 1, hDC_S, 0, 0, SRCCOPY)
GetBackColor= GetPixel(hDC_Tmp, .Left, .Top)
Debug.Print GetBackColor
End With

Call ReleaseDC(m_hWndSection, hDC_S)
Call DeleteDC(hDC_Tmp)
End Function

This is what i try to do... and work only if i execute it after form was
painted.

Probably it's a bad code... but i don't know how to solve.

I Hope is better then the first exemple of my truble.

Thanks
 
S

Stephen Lebans

Sorry about the misunderstanding Alessandro.
Just to be clear, are you looking for the color of the background of the TAB
control? COLOR_BTNFACE?

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
A

ALESSANDRO Baraldi

Sorry about the misunderstanding Alessandro.
Just to be clear, are you looking for the color of the background of the TAB
control? COLOR_BTNFACE?

HTH
Stephen Lebans

Don't warry for misunderstanding, i know that my EN is quite bad.

This look liks works bun not in all case.
On W2000 work correctly on TAB control, but on W_XP(with XP style activated)
i had some difference.

In any case i'll have the same truble if the user put a Rectangle in the
form
with yellow BackCround, and over there put my Image control...
In this case i can't detect yellow ...
So I thought of taking the hDC area around imagecontrol and get PIXELS...
with the other problem on Loading.

Thanks Sthepen, good WeekEnd to you and Family.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top