Solved

Add control to a frame on a form at run-time

Posted on 2002-03-14
10
290 Views
Last Modified: 2008-02-01
I can add my own user control to a form at run-time using:

Dim ctl  As Control
Private oNetctl As QXControl.uc


    Set oNetctl = New QXControl.uc
    Set ctl = Me.Controls.Add(oNetctl, "ctl")
    ctl.Visible = True

But how do I add my control to a frame on the form?????
0
Comment
Question by:PeteD
  • 5
  • 5
10 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 6864475
> Set ctl = Me.Controls.Add(oNetctl, "ctl")
change to:
    Set ctl = Me.Controls.Add(oNetctl, "ctl", Frame1)

You can also change Container property:
    Set ctl.Container = Frame2


How's with VB.NET?  I'm looking for any feedback (positive or negative).  Thanks!
0
 
LVL 15

Accepted Solution

by:
ameba earned 75 total points
ID: 6864547
OOPS, I didn't check it all... First argument in Control.Add should be string which represents library.class name:
     Dim ctl As Control
     Set ctl = Me.Controls.Add("QXControl.uc", "ctl", Frame1)
     ctl.Visible = True
0
 
LVL 2

Author Comment

by:PeteD
ID: 6864724
Thanks ameba! Its alway annoyed me that there is no intellisense in vb6 on Me.Controls.Add!

When you said that there would be some suprises in store, you were very right! Even so, I still really like .net, and I've been enjoying learning it! The most frustrating things I'vee found so far:

a) Microsoft have dropped support to turn .net user controls into activeX controls. Were bound to using our parent comapy's MDI app which displays ocx controls that are saved into .ini files. We have to use the MDI's menus too, but other than that were deveoping a completely new app. Ive nearly solved this problem but its not been easy.

http://www.codeproject.com/netcomponents/exposingdotnetcontrols.asp  was of great use to me if your interested.

b) In order to interop with COM you have to get down and dirty at the command line, which (as vb6 was my 1st language) I don't think is very intuative. I am having trouble understanding why it works sometimes and then it doesnt work when you make changes and re-compile.

c) The MSDN is OK if you know what your looking for, but as normal, its pretty useless if you don't

d) My collegue has been trying to re-write a plotting control in .net, and has had to write much much more code to get it to work, and its much much slower than vb6 when plotting thousands of points.


Having said all that, I still would NOT want to go back to vb6 now I'm getting used to it. I think .NET is the future! It would be grat if there was a .NET zone at EE!

Pete
0
 
LVL 2

Author Comment

by:PeteD
ID: 6864851
Oh and by the way:

Set ctl = Me.Controls.Add(oNetctl, "ctl")

does work! It doesnt have to be a string!
0
 
LVL 15

Expert Comment

by:ameba
ID: 6864852
Thank you, again, for impressions and for the great info.

I'm still not brave enough to 'step on it' and I have fine tuned everything in VB6.   :-)
It seems we'll have to learn C#, as most samples are still not in VB.NET.
0
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

 
LVL 15

Expert Comment

by:ameba
ID: 6864868
>does work
Thanks, I use Controls.Add a lot, but I didn't know that...
0
 
LVL 2

Author Comment

by:PeteD
ID: 6864916
Go on ameba! Take the plunge!
vb.net and c# are so similar, once you start to get familiar with how vb.net works, there is no problem reading both. I like to think that I am learning c# for free

e.g from the example I suggested above here is one of the methdod in c#

[ComUnregisterFunction()]
          public static void UnregisterClass ( string     key     )
          {
               StringBuilder     sb = new StringBuilder ( key ) ;
               sb.Replace(@"HKEY_CLASSES_ROOT\","") ;

               // Open     HKCR\CLSID\{guid} for write     access
               RegistryKey     k =     Registry.ClassesRoot.OpenSubKey(sb.ToString(),true);

               // Delete the 'Control'     key, but don't throw an     exception if it     does not exist
               k.DeleteSubKey ( "Control" , false ) ;

               // Next     open up     InprocServer32
               RegistryKey     inprocServer32 = k.OpenSubKey (     "InprocServer32" , true     ) ;

               // And delete the CodeBase key,     again not throwing if missing
               k.DeleteSubKey ( "CodeBase"     , false     ) ;

               // Finally close the main key
               k.Close     ( )     ;
          }

It took me seconds to rewrite in vb.net:

    <ComRegisterFunction()> _
    Public Shared Sub RegisterClass(ByVal key As String)

        Dim sb As StringBuilder = New StringBuilder(key)

        sb.Replace("HKEY_CLASSES_ROOT\", "")

        Dim k As RegistryKey = Registry.ClassesRoot.OpenSubKey(sb.ToString(), True)


        Dim ctrl As RegistryKey = k.CreateSubKey("Control")
        ctrl.Close()

        Dim inprocServer32 As RegistryKey = k.OpenSubKey("InprocServer32", True)

        inprocServer32.SetValue("CodeBase", Reflection.Assembly.GetExecutingAssembly().CodeBase)
        inprocServer32.Close()

        k.Close()

    End Sub

0
 
LVL 2

Author Comment

by:PeteD
ID: 6864928
oops, I put the wron one in!

    <ComUnregisterFunction()> _
Public Shared Sub UnregisterClass(ByVal key As String)

        Dim sb As StringBuilder = New StringBuilder(key)
        sb.Replace("HKEY_CLASSES_ROOT\", "")
        Dim k As RegistryKey = Registry.ClassesRoot.OpenSubKey(sb.ToString(), True)

throw an     exception if it     does not exist
        k.DeleteSubKey("Control", False)

        Dim inprocServer32 As RegistryKey = k.OpenSubKey("InprocServer32", True)

        k.DeleteSubKey("CodeBase", False)

        k.Close()
    End Sub
0
 
LVL 2

Author Comment

by:PeteD
ID: 6864936
Sorry about my poor attention to syntax! You get the idea though!
0
 
LVL 15

Expert Comment

by:ameba
ID: 6865030
I see in VB topic area people using == in vb code
     If x == y Then
by mistake, so I guess many are learning it.

I'm reading some CSharp book, and I'm following discussion in some VB.NET newsgroups on devx server.
But, for VB6, I produced last app (software for casino) in two weeks using my wizard, and I know I won't have such productivity in .NET, so I'll finish current program (insurance) in VB6.
0

Featured Post

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!

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

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

20 Experts available now in Live!

Get 1:1 Help Now