Results 1 to 9 of 9

Thread: Using OCX in C#

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    14

    Using OCX in C#

    Hello Expoerts...

    I can build and use ocx in visual basic 6. OCX made by visual basic6 can be use in C# form? Plz help me for this purpose.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Using OCX in C#

    You can add your ActiveX controls and COM components to the Toolbox by right-clicking and selecting Add/Remove Items. If your OCX file is not listed on the COM Components tab you can press the Browse button and navigate to it. You then check the objects you want to include in the Toolbox and press OK. You can then add your controls to a form like you would any other, which will add the required references to yuor project automatically. I've never developed for COM or ActiveX myself so I'm not sure, but I would imagine that you would have to register the controls in order to use them.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Using OCX in C#

    totally not sure about what I'm saying but try this
    right click somewhere on the Toolbar and click on Add/Remove Items
    click on the COM Components tab and then browse for your OCX

    maybe that'd work?



    edit: ah 1 minute too late
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    14

    Re: Using OCX in C#

    jmcilhinney and MrPolite

    My special Thanks Goes to you. I can add OCX file C# form. My question was OCX which i made in VB will work in C# perfectly?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Using OCX in C#

    C# cares nothing of the language used to create the classes it uses. It only cares about the interface that is exposed to it. In short, yes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    14

    Re: Using OCX in C#

    jmcilhinney ....Thanksyou Very Much For ur Quick Reply.Take care

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    14

    Re: Using OCX in C#

    jmcilhinney ....Thankyou Very Much For ur Quick Reply.Take care

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Using OCX in C#

    ok I have one question in the same context too...
    I've heard it's a "bad" idea to use COM components anymore? why do they say that? is it because they fear your app would not be so portable if you use COM? (If so, who cares. There's only MONO for linux so far..)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  9. #9
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Using OCX in C#

    There's more complexity with using an ActiveX control from within C# (or VB.NET) that just using a .NET control.

    When you add a reference to a COM object, Visual Studio automatically creates a Runtime Callable Wrapper (RCW). This (duh) is a wrapper around the COM object - your code actually calls the wrapper methods and not the COM object directly.

    There have been some issues (well, one that I know of) with some ActiveX vendors where the automatically generated RCW did not work properly, so the vendor needed to create their own RCW and ship with the ActiveX control.

    I'd prefer to use .NET components over COM objects if possible, as I've seen some things I don't like. Not sure if it's the architecture or just the nature of COM objects, but a lot of times there won't be superclasses/interfaces etc. Also, when trying to figure out the type of object at runtime, I've seen where sometimes the right type is returned, other times, it's named "__ComObject".

    I have an app where the best solution was an ActiveX control, so I use COM objects if necessary, but I'd rather not if there's a good alternative.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width