The situation is this - I have a tabbed page control on a main Windows Form which is used as the main workspace for my application. Each tabbed page,
which represents an open file, is created from a custom Container control which derives from a Windows Panel control. There is one tab for each open file.
Each Panel control has the following settings:
MyPanel.Anchor = System.Windows.Forms.AnchorStyles.None;
MyPanel.AutoScroll = true;
MyPanel.AutoSize = false;
I have a control that we purchased some time ago, which does derive from the Windows Form control. It uses the following settings:
MyChildForm.SizeGripStyle = SizeGripStyle.Hide;
MyChildForm.FormBorderStyle = FormBorderStyle.None;
MyChildForm.AutoScroll = false;
MyChildForm.Dock = DockStyle.Fill;
MyChildForm.AutoSize = false;
This Form control is then added to the control collection of the container MyPanel.
MyPanel.Controls.Add(MyChildForm);
It will not successfully add this Form control to the Panel's control collection unless the following is set:
MyChildForm.TopLevel = false;
I don't think this has anything to do with it, but mention it just in case it is affecting something.
This intermediate Panel control is used only for displaying scroll bars. Our purchased control has a problem properly displaying scroll bars under
certain conditions so the Panel control is used instead.
This purchased Form control now gets filled with a number of custom controls. The largest of these opened files has controls that are placed well
beyond the borders of this Form. When complete, a dummy button is placed on the Panel at the proper location so that the Panel will autoscroll. All
horizontal and verticle scroll calculations are done from MyPanel's perspective. Those values are then used to paint controls on the contained
Form so that it starts displaying controls at the right location. Debugging has shown that the MyPanel dimensions, after all controls are placed, to be
3660 pixels wide by 5320 pixels high.
The dimensions of the contained Form when created is approx one screen size worth of pixels. The actual size of the display window starts out at 769
pixels wide and 842 pixels high. What I assumed was that I would be able to draw the visible controls in the available Form display rectangle, based
on the scroll bar calculations. When the user scrolls the Panel, the horizontal and verticle scroll values are used to draw the controls in the region
of the contained Form that is visible. I override WndProc on MyPanel to call Invalidate() on the contained Form after the scroll message is received,
but prior to calling the base.WndProc()
What actually happens is the clip region that is to be painted with the new controls shrinks with the increasing scroll values. The width and height of
the Form Window paint region isn't big enough after scrolling. So what gets displayed is the new displayed controls, but only a part of them -
basically, any that exist in the retrieved clip region. For example. Say the user clicks to the right of the scroll bar to scroll to what should be
about one additional page of information. The control displayed in the upper left corner of the Form control is the correct control at the expected
location. The other visable controls around it also paint correctly, but only up to about the left two thirds of the page.
The size of the contained Form window when first displayed is 769 wide x 842 high, but the clipped region to be painted after the scroll right operation
occurs is now 532 wide X 842 high. Of course the controls that display are only the ones that fit into the now 532 pixel width region of the Form. The
rest of the view window between 532 and 769 is basically empty space. When I trapped mouse click events, the contained Form received clicks in the 532 x 842 window, but only MyPanel received the clicks in the empty space. This would indicate that
the Form ends at 532 pixels wide. If I scroll again the window size becomes 0 wide X 842 high and no elements display at all. A similar thing happens when vertically scrolling also.
One other piece of information. If I just use our purchased Form control, or for that matter a basic Windows Form, with no containing panel, the tabbed
page is now created from this Form directly instead of using MyPanel, and all scrolling occurs successfully when the scroll bars are displayed. The
Form paints the entire screen of new displayed controls after scrolling. The one big difference that I got from debugging is that the clip region
stays consistently at 769 wide x 842 high. It works this way no matter whether I set MyChildForm.TopLevel to true or false. I do, of course, have to
set MyChildForm.AutoScroll back to true for the Form. In OnPaint I have even tried .ResetClip() followed by recalculating the needed rectangle, and
then .SetClip(). This had no effect on the painted region. Maybe this is because I am not allowed to paint outside the client region?
Anyway, the problem with using just a basic Windows Form as described above, is drag and drop operations. Even with double-buffering on, and using
"Invalidate()" sparingly, it still creates an unacceptable flashing during drag and drop operations. The bought Form control has a very smooth
drag and drop, but as I said before under certain conditions, scroll bars do not appear at all. The scroll bars do not appear unless the theme of the
desktop is set to Windows Classic. Any other theme in XP or Windows 7 and the scroll bars disappear. That is the problem I am trying to solve by using
this container Panel - MyPanel. Lastly, I am stuck using this older bought control for now as I don't have time to write all my own double-buffering
methods due to the sheer number and type of custom controls that can be dragged and dropped.
I can't figure out why this is happening. I would really appreciate any help you can provide, as I have been beating my head against a wall for several
weeks without improving the situation any. Can someone explain what I am doing wrong, if this is supposed to be possible, or give me a clue as to what
is going on so that I can formulate some kind of workaround?