listbox & custome bg color

Started by Paul D. Elliott, June 05, 2006, 06:46:59 PM

Previous topic - Next topic

Paul D. Elliott

I've got a listbox that I only want to have active when a button is pressed. then let the user select an item, hide the listbox and update
the form with data based on the selection. the problem is that after I
set a custom backcolor, the underlying fields show thru the listbox.
this even happens in design mode. in the program, I set the size & location
of the listbox after the form is created then hide it.
I also tested this with a listview and the same thing happens.

Seems like some flag or property is getting set that relates to z-order
( or some such thing ) but I can't see any reason for it.

How do I get things back to normal? short of deleting the listbox and
re-adding it back and NOT changing the backcolor.
:?:

Paul D. Elliott

it might not be the custom bg color. it might be something to do with
the WindowStyles. I just added another listbox and changed the bg
color 3 different times and nothing bad happened. when I started
comparing the windowstyles between the 2 THEN the new listbox
showed the same habit of letting the other fields show thru when I
moved it over the form. all this is in design mode.

still looks like something being set wrong to me.

TechSupport

I think that I understand what you mean. In design mode, you can select the menu option to "Bring to Front" the ListBox. That will set the zorder in front of the other controls on the Form.

In runtime, you should probably set the zorder of the ListBox when you go to show it. I would use the SetWindowPos api for this. Try something like the following:

' Show the ListBox
SetWindowPos HWND_FORM1_LIST1, %HWND_TOP, 0, 0, 0, 0, %SWP_NOSIZE Or %SWP_NOMOVE Or %SWP_SHOWWINDOW



' Hide the ListBox
SetWindowPos HWND_FORM1_LIST1, %HWND_TOP, 0, 0, 0, 0, %SWP_NOSIZE Or %SWP_NOMOVE Or %SWP_HIDEWINDOW

Paul D. Elliott

Okay, at quick test, that seems to work. I'll do more testing in the
next few days to see if it stays fixed.

But WHY does going into the WindowsStyle options ( without changing
anything ) change the zorder? Where do you generate code to change
the zorder?

Paul D. Elliott

well then again, nope. the menu item fixes it in the designer but the
real program still shows the problem ( even with the api call to show
the field ). guess I'll just have to move on to other parts of the program
and come back to this later.

is any of this code being modified in v3? not that I really want to wait
for v3 but I'm not under any pressure to get this program done. I just
have the time now and thought I'd put it to good use.

TechSupport

Quote from: Paul D. ElliottBut WHY does going into the WindowsStyle options ( without changing anything ) change the zorder? Where do you generate code to change the zorder?
I don't have the source code in front of me, but I think that the control may be getting destroyed/recreated after the WindowStyles is closed (especially if a style is changed - maybe even if the styles are not changed...). When the new control is created it would be placed at the top of the zorder.

Paul D. Elliott

So..... Does that place it on TOP of the other controls or UNDERNEATH
them?

Paul D. Elliott

Does it make any difference that the form I'm talking about is a tab
on a tab-control?

I just noticed that when the list-box is active and I scroll it, the buttons
and edit fields that fall within its borders  also scroll.  but the labels are
hidden.

I dislike the thought of having to make some new pop-up window ( or
form ) to do the work that should be able to be done by a simple
listbox. Plus I deleted the listbox then added a new one and renamed
it to my original name. could there be some settings that are not getting
reset within FF?

think I'll take a couple hours and create a new simple project to see if
I can duplicate the problem. I'll be back.

TechSupport

I am creating a sample program as well..... I will report back soon.

TechSupport

I see the problem.... now to find a solution.  :)

TechSupport

OK, looks like there is some sort of sequence problem in the redrawing of the controls when the ListBox is shown on top of the other controls. The simpliest solution is to force the ListBox to be the last drawn control and then refresh the ListBox by redrawing it.

In order for the ListBox to draw last, you need to specify the %WS_EX_TRANSPARENT extended window style.


  ' Show or hide the List1 ListBox on Form2 (TabControl Child Form)
  SetWindowPos HWND_FORM2_LIST1, %HWND_TOP, 0, 0, 0, 0, _
               %SWP_NOMOVE Or %SWP_NOSIZE Or _
               IIf&( IsWindowVisible(HWND_FORM2_LIST1), %SWP_HIDEWINDOW, %SWP_SHOWWINDOW)
 
  FF_Control_Redraw HWND_FORM2_LIST1

Paul D. Elliott

Thanks but I've still got a small problem. The vertical scrollbars don't
draw until you actually scroll ( so no indication that there are more
items than shown ) and the top & bottom parts never do draw.

This is starting to get ridiculous and time-consuming. Maybe it will be
easier and more stable if I change over to a new pop-up form with
just a listbox on it. Any opinions?

TechSupport

Hi Paul,

This is certainly a very interesting problem. I don't have the scrollbar problem with the sample program that I wrote. At what point do you load the ListBox? When the Form loads (WM_CREATE) or just prior to showing the ListBox?

Maybe you could add the %SWP_DRAWFRAME flag to the SetWindowPos function call to see if the non-client areas of the ListBox get repainted.

Paul D. Elliott

I load it on WM_Create. Just tried adding that flag but it didn't make
any difference.

Since this is starting to sound like one of those "odd-ball problems that
have no simple easy-to-fix solutions because no one else has seen it",
I'm going to code up the other way ( which is to make a new form with
only the list-box ). That way I'm pretty sure that things will work without
having to remember to add multiple flags in different places and use
API calls with certain flags instead of the normal FF function calls. I might
not remember all the hoops I had to jump thru to get things to work when
I have to make modifications in the far future.

Thanks for your help.