Tabcontrol: resize problem after tab is deleted

Started by Wilko Verweij, August 12, 2013, 07:44:42 AM

Previous topic - Next topic

Wilko Verweij

I have weird problem with a tabcontrol and listview that I don't understand. The tabcontrol has 6 tabs. On tab 1, 2 and 6 there is a form with one label and one listview (Tabcontrolchild and  TabcontrolchildAutoSize set to True). If a user resizes the window with the tabcontrol, the tabcontrol is resized to fill the entire window (_WM_size event of the form). That works fine. In the tabcontrol_WM_SIZE event, the label and listview are resized for each child form. That also works fine.
In some cases I do not need 6 tabs. That can be determined only at run time, depending on user  input. In such a case one of the tabs is deleted. After that, the resize event of tab 6 is never fired anymore. Tabs 1 and 2 resize event works as normal.

I use the window handles that FF generates, so there is no direct reference to the number of the current tab.

Any ideas how I can get this working?

Paul Squires

Hi Wilko,

Can you post the code that you are using to "delete the tab". I just made a 5 tab sample project using autoresize for the child tab pages and after deleting the second tab, the WM_SIZE seems to still fire for all of the other child forms.

I also assume that you are using the latest FireFly version, right?
Paul Squires
PlanetSquires Software

Wilko Verweij

#2
Hi Paul,
This is the code:

  If Len(GridTitle(GridNum)) = 0 Then
    'no title so no contents; delete tab
    FF_TabControl_RemoveTab(HWND_FRMOTHERINFO_TAB, GridNum - 1)
  End If


The code is called in a sub which in turn is called from the WM_CREATE function of the form containing the tab control.

And I'm using 3.62, indeed.

Thanks so far,
Wilko

Paul Squires

Hi Wilko,

I have been able to reproduce the problem. It occurs if more than one tab is removed at run time. This is because FireFly generates static code generation that assumes that the number of tabs does not change at runtime. Give me a bit to see if I can come up with a way to fix the way FF handles the tab indexes and associated TCITEM structures during runtime.
Paul Squires
PlanetSquires Software

Wilko Verweij

OK, would be great. There's no need to hurry...
Regards,
Wilko

Paul Squires

Hi Wilko,

Please see the attached project. After working on this for a while I realized that the problem was not the code, but rather with the tab indexes that I was asking FF_TabControl_RemoveTab to remove.

For example, if you want to remove Tab #3 and Tab #4, you *would not* do this:
FF_Control_RemoveTab hWndControl, 2    ' zero based index
FF_Control_RemoveTab hWndControl, 3    ' zero based index

Instead, you need to do this:
FF_Control_RemoveTab hWndControl, 2    ' zero based index
FF_Control_RemoveTab hWndControl, 2    ' zero based index

This is because the index numbers are adjusted when Tab #3 is removed. At that time, Tab #4 becomes Tab #3. This is similar to the logic you see when trying to remove columns in a ListView. Check out the code in the attached project.

I also created a new function in the project called FF_TabControl_DeleteTab because it is not enough to simply remove the Tab from the Tab Control. You also need to close the child tab form that is associated with that Tab. Here is the code for that function:


'--------------------------------------------------------------------------------
Function FF_TabControl_DeleteTab( ByVal hWndControl As Dword, _
                                  ByVal nTabIndex   As Long _        ' zero based index
                                  ) As Long
                                   
    Local FLY_TCITEM As TC_ITEM
   
    ' Removing the Tab does not kill the child tab form that is loaded (but not shown)
    ' when the tab control is first created. We must manually unload that form. We
    ' must retrieve the Windows handle for the form that will be unloaded. That handle
    ' is stored in the lParam of the TC_ITEM structure.
    FLY_TCITEM.Mask = %TCIF_PARAM
    TabCtrl_GetItem hWndControl, nTabIndex, FLY_TCITEM   
    FF_CloseForm FLY_TCITEM.lParam
   
    ' Remove the tab from the tab control
    FF_TabControl_RemoveTab hWndControl, nTabIndex   

End Function

   
Hopefully, this makes sense. Try the project and let me know if you agree.




Paul Squires
PlanetSquires Software

Wilko Verweij

OK, I will try tomorrow. In my case the problem also occurred after removing one tab. Maybe that is because I recognized the complication that could arise in your example and therefore counted down from 6 to 1. If you then remove let's say 3, and later 2, the 2 refers to the correct tab.
I will let you know tomorrow.
Wilko

Wilko Verweij

I tried and it didn't work... When I thought this over I thought of another possible reason for this failure. Since I am currently adding the forms to the tabcontrol one by one (but not from one to six), tab 4 and 5 are still empty (no child forms assigned yet). So I created (empty) child forms, added them to tab 4 and 5 and now the resize works fine, even without implementing this new DeleteTab function. So this is solved. Actually I later added the DeleteTab 'cause it seems to make sense anyway. Paul, thanks! Wilko

Paul Squires

:-)   Cool - happy to hear that you were able to find the solution!
Paul Squires
PlanetSquires Software