Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a ActiveX control which is controlling a specific machine.
For recycling this ActiveX control, our machine vendor uses winform in C#

If I attach this ActiveX control to Winform in C#, it is well operated
and also easy job.

Please refer below code

private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.traceView = new AxHxTraceViewLib.AxHxTraceView();
            this.runControl = new AxHXHSLRUNCONTROL2Lib.AxHxHSLRunControl();
            this.button1 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.traceView)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.runControl)).BeginInit();
            this.SuspendLayout();
            // 
            // traceView
            // 
            this.traceView.Enabled = true;
            this.traceView.Location = new System.Drawing.Point(156, 18);
            this.traceView.Name = "traceView";
            this.traceView.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("traceView.OcxState")));
            this.traceView.Size = new System.Drawing.Size(638, 249);
            this.traceView.TabIndex = 3;
            // 
            // runControl
            // 
            this.runControl.Enabled = true;
            this.runControl.Location = new System.Drawing.Point(26, 12);
            this.runControl.Name = "runControl";
            this.runControl.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("runControl.OcxState")));
            this.runControl.Size = new System.Drawing.Size(96, 198);
            this.runControl.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(652, 273);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(142, 21);
            this.button1.TabIndex = 4;
            this.button1.Text = "Load Method";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(806, 306);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.traceView);
            this.Controls.Add(this.runControl);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.traceView)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.runControl)).EndInit();
            this.ResumeLayout(false);
        }

Unfortunately It is not that I want to do.
As you know, Winform have UI element(it has form)
But I don't want to show UI element when I use this ActiveX Control.

I think it would be console code.

Are there anyone who knows a solution for this problem??

Detailed source is good.
But just simple keywords of technic or subject are OK.

Please Help me.
Posted

1 solution

I appreciate this question.

Really, why not using an ActiveX control without a UI?
This is a general problem, that there are too many components created as controls only to please the addicts of design-time developers, even though the functionality takes no space in the graphical layout.

You may or may not be able to use your control without UI; it depends on the features of the component you want to use. At least you can try. The idea is to make an interop ActiveX assembly (one can do it manually using AxImp tool) reference it in your project and instantiate the object(s) in a regular way, without making it a child of a form.

This overview can help: http://www.informit.com/articles/article.aspx?p=27219&seqNum=9[^].

I found similar question on StackOverflow; here is the answer:

http://stackoverflow.com/questions/1531512/c-activex-control-without-a-form[^].
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 16-Jan-11 22:39pm    
Whoever voted, I just wonder what's wrong in this answer? Perhaps you know better? Please share with us.
fjdiewornncalwe 16-Jan-11 22:54pm    
@SAKryukov: My guess is that if the OP was the voter, it was because you provided the "OK" answer, but not the "awesome, you gave me all the code answer". If it wasn't the OP, it is likely just someone jealous of you for posting a great answer first. (+5)
Sergey Alexandrovich Kryukov 16-Jan-11 23:05pm    
Thanks a lot, Marcus, that was my guess, too, but I cannot blame any particular person if I don't know for sure. It's all right.

Anyway, I started to privately blacklist some inquirers to avoid giving more answers if I don't like the response. I guess I have every right to do so...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900