|
-
Dec 13th, 2010, 07:24 AM
#1
Thread Starter
Hyperactive Member
Class to Component?
Heyy guys 
I have created a class and want to distribute it without giving off my code/create it as an application.
I am aware that components are nearly no longer used and their disadvantages.
I dont need to draw anything on the ui. (I know basically components are used for this aim but I just need to try this :] )
My question is:
My class uses a webbrowser because webclient and web request don't work for me. When I start vs 2010 and select new project - Class Library and include the namespace System.Windows.Forms it doesnt find it. So first of all should I select class library to create a component and how could I include the webbrowser object?
Thanks in advance ( Ps I know the webbrowser is not ideal but please I still wanna use it )
-
Dec 13th, 2010, 08:03 AM
#2
Re: Class to Component?
You mean the following does not work . What is the error ?
vb Code:
Imports System.Windows.Forms
Public Class Class1
Dim wb As WebBrowser
End Class
-
Dec 13th, 2010, 08:23 AM
#3
Thread Starter
Hyperactive Member
Re: Class to Component?
For: Imports System.Windows.Forms
Nope It doesnt.
That Namespace doesnt exist. (highlighted with green line giving no help)
-
Dec 13th, 2010, 08:26 AM
#4
Re: Class to Component?
You need to add a reference to System.Windows.Forms too, you can't import namespaces from assemblies you haven't referenced.
-
Dec 13th, 2010, 08:36 AM
#5
Re: Class to Component?
 Originally Posted by Skatebone
For: Imports System.Windows.Forms
Nope It doesnt.
That Namespace doesnt exist. (highlighted with green line giving no help)
Add reference to System.Windows.Forms
-
Dec 13th, 2010, 08:53 AM
#6
Thread Starter
Hyperactive Member
Re: Class to Component?
Thanks and how should I compile it as a component?
Thanks alot : )
-
Dec 13th, 2010, 09:02 AM
#7
Re: Class to Component?
Use
Code:
implements IComponent
and add code to the methods.
-
Dec 13th, 2010, 09:04 AM
#8
Re: Class to Component?
Just inherit Component, no need to implement IComponent manually.
-
Dec 13th, 2010, 09:15 AM
#9
Thread Starter
Hyperactive Member
Re: Class to Component?
Therefore I add:
Code:
Imports System.ComponentModel
And What? I programm everything normally? How can I add properties ect to my component and test it?
Thanks
-
Dec 13th, 2010, 09:53 AM
#10
Re: Class to Component?
A Component is no different to any other class, except that it can be designed visually. You add members to your component the same way you add members to any other class. You test your component by using it in an application, just as you use any other component.
Generally speaking, you should create a solution with two projects: one that compiles to a DLL and contains your component and another that compiles to an EXE that you use as a test rig. Any time you make changes to the DLL, you build the solution and run the application project to test.
-
Dec 13th, 2010, 10:25 AM
#11
Thread Starter
Hyperactive Member
Re: Class to Component?
 Originally Posted by jmcilhinney
A Component is no different to any other class, except that it can be designed visually. You add members to your component the same way you add members to any other class. You test your component by using it in an application, just as you use any other component.
Generally speaking, you should create a solution with two projects: one that compiles to a DLL and contains your component and another that compiles to an EXE that you use as a test rig. Any time you make changes to the DLL, you build the solution and run the application project to test.
Ahh so I put my design code in here right?:
Code:
Interface IComponent
End Interface
This looks cool thanks alot
-
Dec 13th, 2010, 10:50 AM
#12
Re: Class to Component?
No, not at all. That would be when you were writing an interface. If you are implementing an interface, you use
Code:
Public Class <name>
Implements IComponent
'members that implement IComponent members
End Class
But as I said, I don't see any reason for you to implement IComponent manually, as you can just inherit Component. Then you don't have to write any of the IComponent methods yourself.
Component is the default implementation of IComponent and serves as the base class for all components in the common language runtime.
-
Dec 13th, 2010, 06:36 PM
#13
Re: Class to Component?
I'm not sure if VB Express offers the option but, in VS, you don't even have to inherit Component manually. You simply add an item to your project as you usually do, i.e. use the Project menu or right-click the project in the Solution Explorer and select Add. You then just select Component instead of Class or Windows Form or whatever.
Also, if you intend to use WinForms functionality in a DLL then start by creating a Windows Control Library project rather than a Class Library. It already has the appropriate references and imports. Again, I'm not 100% sure VB Express offers that template.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|