Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Container control with sub containers

Posted on 2002-06-18
10
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 100 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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