[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

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

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
PeteD
Asked:
PeteD
  • 5
  • 5
1 Solution
 
amebaCommented:
> 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
 
amebaCommented:
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
 
PeteDAuthor Commented:
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
Industry Leaders: 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!

 
PeteDAuthor Commented:
Oh and by the way:

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

does work! It doesnt have to be a string!
0
 
amebaCommented:
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
 
amebaCommented:
>does work
Thanks, I use Controls.Add a lot, but I didn't know that...
0
 
PeteDAuthor Commented:
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
 
PeteDAuthor Commented:
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
 
PeteDAuthor Commented:
Sorry about my poor attention to syntax! You get the idea though!
0
 
amebaCommented:
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

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!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now