Solved

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

Posted on 2002-03-14
10
293 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

895 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

14 Experts available now in Live!

Get 1:1 Help Now