Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Gurus :-)

I observe a very strange behaviour of my code and don't know what I might accidentially have done...

In my windows form I have a TabControl that holds 4 different TabPage elements, on each of which other controls are placed (buttons, datagridviews, etc.). Everything looks fine at design time – just as it did at runtime until yesterday :-( when I made many changes to the program. As far as I remember, there was nothing in the context of the tabs, but what happens at runtime now is somewhat inexplicable to me:

At it start, the main form shows TabPage1, which seems completely ok. Changing to the other tabs, however, shows weird results: The controls are jumbled, some are invisible (or covered by anything?) and others moved to seemingly random places on the tab (nothing is resized!). The tabPages show always identical, i.e. the probable offset to the controls doesn't change by activating/deactivating them 5 or 10 times and the "distorted" tabPage3 (as example) looks the same after each restart

Being only a hobby programmer, I unfortunately have no clue what to do... Can you probably provide me any hints on how I could detect which event handler pushes my controls around - or at least where I would start looking?

Thank you ever so much,
Mick

What I have tried:

I searched for every event handler that might - to my understanding - be involved in the selection of the tabPages. No suspicious code found.
Posted
Updated 11-Mar-21 8:17am
v4
Comments
Ralf Meier 11-Mar-21 12:42pm    
Have you used the Dock-Property of some or all of the Controls of the other TabPages ?
I suppose that you haven't a method which calculates the location for the Controls ?
What are the "many changes" you made to your Application ?
Sonhospa 11-Mar-21 13:54pm    
Hi again, Ralf,
it seems I was able to RESOLVE it "by accident", too :-) In a systematic approach I deactivated large parts of my code (set as comment) and uncommented parts stepwise. I now have a few lines left that I didn't find suspicious before, but they seem to have caused the problem!

It seems that my tabSelector.SelectedIndexChanged handler confused not only me but also the compiler:

Dim ctrl As TabControl = DirectCast(sender, TabControl)
Dim page As TabPage = ctrl.TabPages(ctrl.SelectedIndex)

If ctrl.SelectedIndex = 0 Then
'Stop
End If

Despite of the fact that the handler was actually doing nothing ("Stop" was also set as comment before), after deleting all of these statements I have my UI back as before!

Thank you, though, for trying to help – and have a nice evening!
Ralf Meier 11-Mar-21 14:00pm    
Excuse me ...
tabselector.SelectedIndexChanged ?
That Event normally should come from the TabControl itself ... what is "tabselector" to you ?
Sonhospa 11-Mar-21 14:20pm    
It's how I named the TabControl. Admittedly, this might be confusing :-)
Sonhospa 11-Mar-21 13:19pm    
Thank you for your response, Ralf. No I haven't used the dock property and I guess this would also show at design time. The form designer looks just as it should, and nothing in my code relocates any controls (purposely). The 'many changes' mainly involved read-/write methods etc, nothing I would relate with how the tabs are shown.

In one experiment I tried to select Tab3 at startup (if a condition has been matched), but deleted this piece of code shortly afterwards. Too sad I can't post a screenshot here in order to show what's presented.

BTW I'm using VS2019 Community on a Windows7 (64bit) system.

1 solution

Do you use language resource files for this form?

Did yo change the screen resolution or DPI settings on your pc?

I use always split containers and/or tablelayoutpanels to place the controls - this keeps them where they should be when the form size is changed.

Perhaps you moved a control before the tabcontrol?
My VS is in german so I do not know the menu item where you can see in a tree-like view how the structure of the controls on your form is.
There is the best place if you want to move controls to another container (another tab page or somewhere else).

If you have a backup of your last good version - it would be easier to restore the project and then start with your latest changes again.
 
Share this answer
 
Comments
Ralf Meier 11-Mar-21 13:51pm    
Thge OP (and me too) also come from Germany ...
Jo_vb.net 11-Mar-21 14:01pm    
On form designer select the form.

On VS 2019 Community You can see the structure on menu item
Ansicht > Weitere Fenster > Dokumentgliederung
or
Strg + Alt + T
or
Ctrl + Alt + T

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900