Solved

Container control with sub containers

Posted on 2002-06-18
10
160 Views
Last Modified: 2010-05-02
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
Comment
Question by:schworak
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7089174
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
 
LVL 3

Expert Comment

by:SirNick
ID: 7089484
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
 
LVL 43

Expert Comment

by:TimCottee
ID: 7089532

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
 
LVL 3

Expert Comment

by:SirNick
ID: 7089606
Yes, it worked without the quotes around Frame1.  Thanks for clearing that up...
0
 
LVL 3

Expert Comment

by:SirNick
ID: 7089640
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Author Comment

by:schworak
ID: 7090759
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
 
LVL 4

Accepted Solution

by:
TigerZhao earned 50 total points
ID: 7091635
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
 
LVL 3

Author Comment

by:schworak
ID: 7093028
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
 
LVL 3

Author Comment

by:schworak
ID: 7096286
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
 
LVL 3

Author Comment

by:schworak
ID: 7099396
Not the answer I was looking for but since it proved useful for something else I am crediting it.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now