tags:

views:

678

answers:

3

I'm using the ssTab control (that's probably my entire problem) in a VB6 program, and I'm plotting data into a Picturebox located on Tab 0. When I redraw the graph (after a window resize, for example), the first thing I do is clear the box:

Picture2.Line (0, 0)-(Picture2.Width, Picture2.Height), RGB(255, 255, 255), BF

That works fine when Tab 0 is visible, but if this code is called when a different tab is visible, the background for the entire visible tab (as well as tab 0) gets painted white. Not just the area of Picture2, but the entire visible area of both tabs. Tabs besides 0 and the currently selected tab are not affected.

My first attempt to crudely fix this was adding changing the tab back to tab 0 immediately before the above Line command:

SSTab1.Tab = 0 ' Select tab containing PictureBox2
DoEvents

but that gets the same results - both the original and 0 tabs are now white (although it does change the visible tab back to tab 0).

I noticed that when the wallpainting occurs, the value of Picture2.Width is way larger than it should be. If Tab 0 is visible, Picture2.Width varies between 7180 and 21225 Twips as I resize the window. When I select Tab 1 and resize, Picture2.Width is on the order of 82180 (the height stays where it should be).

I know the SStab is a bit buggy, but does anyone know any workaraounds? I can probably kludge together a fix (repaint background on both tabs gray after a redraw), but I'd like to understand why Picture2.Width loses its mind...

+1  A: 

There's a small bell ringing about sstab and widths... but damn'd if I can recall what. Somehow I'm thinking it did strange things to controls on tabs not visible?

Yup... it moves them "off screen" (sets the "left" to a very large negative position). Or at least that's what my quick and dirty test shows.

I think (don't "know") that the PictureBox control often deals directly with the form's device context directly... so it doesn't surprise me that it doesn't like what sstab is doing to it.

What I'd recommend is only redrawing when you switch to that tab... if you know what I mean. Or maybe detecting that the picture box is off screen and skipping the refresh (will still need to do a refresh when the picture box is moved).

+3  A: 

The way SStab makes the controls on one tab visible while hiding the other controls is by making the Left property negative (basically "off-screen")

That shouldn't affect the width property - do you have custom re-size code??

DJ
Yep, I had custom re-size code. I just narrowed it down to what you and rbobby are saying - the .left property gets shifted to -70,000 or so.It's helpful to know the reason it's doing it - I should be able to make something work now...
Fred Hamilton
A: 

Once I understood the reason for the weird behavior (thanks to DJ: 'The way SStab makes the controls on one tab visible while hiding the other controls is by making the .Left property negative (basically "off-screen")'), I realized where my problem was.

As DJ said, the instant you select one of the tabs that does not contain the PictureBox, the PictureBox.Left property becomes very negative (like -74000). In my Form_Resize() code I had the following line:

Picture2.Width = MainForm.Width - (Picture2.Left + PictureBoxMargin)

Which makes Picture2.Width an even larger positive number (my big mistake).

Final solution was to create a public variable, Picture2LeftEdge, set it equal to Picture2.Left in the Form_Initialize() routine, and change the above resizing line to:

Picture2.Width = MainForm.Width - (Picture2LeftEdge + PictureBoxMargin)

Thanks for the super-quick responses, DJ and rbobby!

Fred Hamilton