I'm trying to dynamically add an ActiveX control to my application, without having to place it on a form.
However, when I do place the ActiveX control using the Visual Studio designer, initialization code is generation which contains a statement for setting for OcxState of the ActiveX control.
When an ActiveX control is added to a form using the designer, it seems like that the OcxState is serialized into a resources file, which is later retrieved at the initialization of the form.
Now I want to set that OcxState dynamically in code, so I can create some kind of wrapper class for the ActiveX for in my class library.
Anyone knows how to dynamically set the OcxState of an ActiveX control?
Thanks in advance!
Mathieu
i working in the same problem, the solution i got by now is working with a Worker form, that is not show, but where i can load the ocx and wrapper all the events and methods of the ocx to the outside.
In my library class i use the form like any other class instead of the ocx calls
I had the same problem while I was working on a .NET project that requires an ActiveX control for data manipulation. I had to put the ActiveX control on a form, load it with the application and use it with a public property. Otherwise if I just create an instance of the control I loose some of the functionality.
The form does not require to be visible all the time but it provides a container where the ActiveX control can live.
The another way is UserControl,
You can create a user control with your ActiveX Control. Now you can load the user control at wherever you want dynamically at runtime.
Related
I have a c# .net 2.0 winforms application which consists basically of one form A.
I am building another form B with a tabcontrol on it.
From the form B, I would like to be able to create one or more instances of this application.
Each form A I would like to be placed on tabpages on form B's tabcontrol.
Each instance is a different process that is running on a separated folder.
How could I achieve this?
Another way to put this is, how I could dock a form from another running instance into the current application instance's form.
Look at this codeproject article. It is what you are searching for.
I think the best way to do this would be to have to versions of your app. One is the executable and the other is a component that you could add dynamically. I have an app that I do this with tool controls. Each tool represents a separate set of functionality that can be added to a workspace (tab) depending on the user's need for it. For example, I have a tool for logging particular items that's called "logger" and a user can create a new instance of it which essentially adds it as a new tab in the main window. Just a thought. I think docking two running instances of the same application would have to be handled by Windows through the app docking interface.
If you don't control the source code for both of these applications then I don't think you can accomplish your objective.
If you DO control the source code, then I would recommend that you isolate the Form A functionality in a usercontrol in a separate library and reference this from the form in AppA and from the tab control in App B
Is it possible to have a single project which allow to include a custom custom control within another custom control ?
Update: of course I'm not asking about how to put a custom control on a winform!!! But if I can create put a CUSTOM user CONTROL inside ANOTHER CUSTOM user CONTROL within the SAME PROJECT.
Sure, you're able to do this. In fact you're able to put a custom control inside another custom control the same way you'd do it on a form (it's essentially the same while editing). You might as well base your custom control off another class (or custom control), but not all will support the built in gui editor (so you might just see an error message but the code will still work).
I new to c# and windows form programming. Here is the problem i am trying to solve.
I have to write an application that uses an multiple instance of an ActiveX control. Therefore, I dragged as many control as necessary to my Form. Now my problem is that i'd like to add some personalised methods to this activeX. The logical solution I thought was to create my own class derived from that aciveX and add some more members and methods to that class so it would work as desired. Now my problem is that the newly generated class doesn't exists as a control that can be inserted into the form.
So How can a class become a control and then inserted into a form ?
If you look at the Designer.CS file that corresponds to your form, you should see, in the #region Windows Form Designer generated code, the code that was generated when you dragged the ActiveX control onto the form.
This code is similar to what your code needs to look like.
My guess would be that you should wrap this activex into your own control, and add funcionality that lacks into that wrapper.
Pros: you'l have .net control and will be able to extend it and use it anyway you like.
Cons: if you want to access original methods, you'll have to generate pass-through method wrappers.
How:
- create a control class
- drop activex you have onto it
- set activex dock to 'fill'
- either set control to public, create get wrapper for it, or create method wrappers you desire
- compile that and use it on the form.
This is the code I am using:
tabPage1.Controls.Add(AXViewer1);
where AXViewer1 is a third party ActiveX control (non .NET) that I want to add to my tab page.
Is it wrong to do it the way I did, since it has not added it to the tab page with that code?
Your ActiveX control probably cannot be reparented at runtime.
You need to create a new instance of the class at runtime by writing new AXViewer().
Try setting the Visible property to True. Also try calling the CreateHandle method.
If none of this works, you are best off contacting the developer of the ActiveX control for support.
Warning: I'm new to GUI building in C# (come from a long history in Java with Swing and SWT.)
Using VS2008, When I create a new class, and extend System.Windows.Forms.Form, the WinForms Designer works really nicely. However; when I create a new class and extend System.Windows.Forms.Panel, the designer does not work nearly as elegantly - it simply shows some kind of abstract, list-type view of the components contained in the Panel (as opposed to showing the actual layout of the Controls in the Panel.)
Is there a way to get the Designer to work more nicely with a Panel?
Or is there some workaround so that I can build a Form with the designer, and then use it as if it were only a Panel?
What I'm really looking for is some UI 'element' I can build with the designer, and then dynamically (read: programmatically) add/remove that 'element' to a larger UI.
I think what you're looking for is a UserControl. You can inherit directly from that, and you should be able to use the designer to drag and drop stuff on it.
To make it even easier, you can just right click on your project and click Add -> User Control. That will create the .cs file for you as well as a partial .cs file for the designer generated code.