From: Andy on
"Steve Gerrard" wrote:

> I'm pretty sure that what you would have to do is make picHostWindow also be a
> control that has mfrmHostForm as its Parent, with the ucSizeableContainer as its
> container.

I've tried what you suggested (your code snippet repeated below for
reference) but with rather disappointing results.

> Public Sub SetMeUp(Frm As Form)
>
> Dim PicBox As PictureBox
>
> ' add a picture box to form, but make this UC its container
> Set PicBox = Frm.Controls.Add("VB.PictureBox", "picHost", Me)
> With PicBox
> .Left = 500
> .Top = 200
> .Width = 3000
> .Height = 2000
> .BorderStyle = 1
> .Visible = True
> End With
>
> ' add the test UC to the form, and make the PicBox its container
> Dim Ext As VBControlExtender
> Set Ext = Frm.Controls.Add("Project1.UCTest", "UCTest1", PicBox)
> With Ext
> .Left = 100
> .Top = 100
> .Visible = True
> .SetFocus
> End With
>
> End Sub

I no longer get the error message, so yes, the form now 'sees' picHost (aka
PicBox)and understands that it is a container. But picHost doesn't become
visible! A spot of debugging - a breakpoint on the line following

With picBox
...
...
.Visible = True
End With

This tells me that picBox.Visible hasn't been set to True even though I just
told it to be visible! What could cause that? Is it because the instance of
ucSizeableContainer isn't visible yet? I've worked this code into a Sub
called 'InitializeWith' in ucSizeableContainer, which does one or two other
things as well, including setting the object whose properties are going to be
displayed (and maybe edited) by the hosted UCs, then calling a sub (in a
standard module) which tells ucSizeableContainer to add the appropriate set
of hosted UCs. Instead of using Sub SetMeUp to pass the parent form as a
parameter, I have

Dim frmHostForm as frmHost
Set frmHostForm = UserControl.Parent

and after that I can use

Set picHost = oHost.Controls.Add("VB.PictureBox", "picHost", Me)

Well, my instance of frmHost doesn't Show itself until the line following
the call to InitializeWith, so maybe that's why the ucSizeableContainer's
picHost isn't visible yet? If that's the case, where do I have to put the
code you've given me? I don't want it to go in the Resize event, because
that means the hosted controls would get added again! (More likely, I would
get an error, if I try to add them a second time.)

Oh, yes - the menu on ucTest fails to appear as well.

One or two further questions which I think are pertinent to ask at this
stage...

I'm going to have more than one hosted control in ucSizeableContainer. If
the user clicks on node B in the TreeView, then (when node A was previously
selected), ucA is no longer visible, and nw ucB becomes visible. Is that
sufficient for ucA's menus to disappear and ucB's menus to appear?

Now that picHost is (also) added to the form dynamically, rather than being
a fixed constituent of ucSizeableContainer, I must also dynamically add three
other of its constituents. Previously, my two scrollbars were sited on
picHost. This was for purely cosmetic reasons. That way, the scrollbars
were inside picHost's 3D border - to be consistent with the way ListViews and
TreeViews show their scrollbars. I also had a further PictureBox named
picBlackout in picHost. This is a blank square to fill the gap where the
scrollbars meet, if both should both be visible. Otherwise I would get a
small square of the currently visible hosted UC visible there! I don't
really want the overhead of calculating the available area for displaying the
hosted UC, it's just easier to hide this square area by displaying
picBlackout. What other option might I have?
From: Steve Gerrard on

"Andy" <andrewjellis(a)hotmailnospam.com> wrote in message
news:240363C5-0E7B-4134-A867-305B0B7444C5(a)microsoft.com...
> "Steve Gerrard" wrote:
>
>
> I've tried what you suggested (your code snippet repeated below for
> reference) but with rather disappointing results.
>
>
> I'm going to have more than one hosted control in ucSizeableContainer. If
> the user clicks on node B in the TreeView, then (when node A was previously
> selected), ucA is no longer visible, and nw ucB becomes visible. Is that
> sufficient for ucA's menus to disappear and ucB's menus to appear?
>

In my tests, the usercontrol with focus sets the menu. If both ucA and ucB were
visible, the menu would change as you went back and forth between them.

> Now that picHost is (also) added to the form dynamically, rather than being
> a fixed constituent of ucSizeableContainer, I must also dynamically add three
> other of its constituents.

Sounds like picHost should be a user control... (sigh)

I think the idea in your other post, of just building the form as the
SizeableContainer, and working from there, makes sense. If you are only going to
have one form with ucSizeableContainer, and it itself doesn't do anything (I
thought it at least had the scrollbars), then it is just in the way.



First  |  Prev  | 
Pages: 1 2 3
Prev: COM-RPCServer - New Version
Next: Debug VB OCX and DLL