Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

Container control with sub containers

I have a project where I want to create a control that allows part of the control to be a container control is this posible?


Imagine this... A single control with 2 frames in it. One frame (left) contains text data and the other frame (right) the user can add their own controls to.

But I don't want the user to be able to add their controls outside of the right frame. Is this posible? If so how?


If someone can help me make this work I will increase the points on this question.
0
schworak
Asked:
schworak
  • 4
  • 3
  • 2
  • +1
1 Solution
 
TimCotteeHead of Software ServicesCommented:
If you are using a frame control then you can use the add method of the controls collection to add controls directly into this frame.

Dim t As Textbox
Set t = Me.Controls.Add("VB.Textbox","txtNew","Frame1")
With t
  .Visible = True
  .Top = 100
  .Left = 100
  .Text = "Here I Am"
End With
0
 
SirNickCommented:
Hi Tim

I know that this isn't my question, but I just tried your code and it gave me an error message in the second line saying 'object doesn't support this method or property'.

Do I have to make some kind of reference before it will work?
0
 
TimCotteeHead of Software ServicesCommented:

Dim t As Textbox
Set t = Me.Controls.Add("VB.Textbox","txtNew",Frame1)
With t
 .Visible = True
 .Top = 100
 .Left = 100
 .Text = "Here I Am"
End With

The Frame1 parameter doesn't need to be in quotes.

You shouldn't be getting that error message, based on the above I would not have been surprised at a type mismatch error.

You shouldn't need any sort of reference, however if you are using VB5 then this doesn't work I am afraid.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
SirNickCommented:
Yes, it worked without the quotes around Frame1.  Thanks for clearing that up...
0
 
SirNickCommented:
P.S  I got that error in VB5 but tried the second time with VB6, and as you pointed out I got a type mismatch error.
0
 
schworakAuthor Commented:
Maybe I am not grasping the function of the answer. How does that help?

That dynamically adds the textbox (or what ever) the the frame which is great, but I am trying to control the process at design time when a user uses my control (the one with 2 frames) and trys to drop a new object into my container control.

If I can catch (or detect) where they are dropping their control I can record the information somehow. I can then make sure the control lands and then stays within the second frame area.

Much like if you create a picture box then put two frames in it. I only want stuff to be dropped on the frame on the right not on the left.
0
 
TigerZhaoCommented:
This Sample can help you
#Step1. Create a user control
'Name = "UserControl1"
'Left Frame is "Frame1"
'Right Frame is "Frame2"

Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Public Sub DropControl(ByVal SubControl As Control)
    SetParent SubControl.hWnd, Frame2.hWnd
    SubControl.Move 120, 240
End Sub

#Step2. Add a UserControl1 to From1
'Name = "UserControl11"

Private Sub UserControl11_DragDrop(Source As Control, X As Single, Y As Single)
    UserControl11.DropControl Source
End Sub

#Step3. Add a Picture to Form1
'Name = "Picture1"
'DragMode = "1 - Automatic"

#Run it
If you drag picture1 and drop to UserControl11, Picture1 Will Show in Frame2
0
 
schworakAuthor Commented:
Took me a minute to realize this but that only works at run time. Which is great but switching the parent at that time isn't much value.

I am trying to do it at design time.

Control11 is all compiled and ready.

Form1 is in design mode.


I am having some success with a timer checking for a change in child controls. I disable the timer when the control is in usermode.

I tried the SetParent and it blew up in design mode. Works fine in run mode though.

I am also experimenting with adding Frame2 to the VBE when the control first initializes to see if that will help. Then I can simply reject any controls that are dropped outside the frame2. This is proving to be harder than expected though.

0
 
schworakAuthor Commented:
Apperently from all the documents I have read so far, it is not posible to do what I am looking for. There is no code method to add or remove or change the parent/child relations of contained controls within a control. A little frustrating, but I will live.

I have a couple other ways to make this project work. I will just make the two sections completely different controls and use them together
0
 
schworakAuthor Commented:
Not the answer I was looking for but since it proved useful for something else I am crediting it.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now