如何在没有.net的机器上运行C#程序?

dogdogdog 2002-12-19 07:01:39
我用C#编了个很简单的程序,使用了WebBrowser控件。
在安装了VS.net的机器上都可以运行。
但是在没有安装VS.net的机器上,即使安装了dotnetfx.exe也无法运行。
显示找不到AxInteropSHDoc文件。
可是dll就在同一个目录下啊。
请问该怎么办?
...全文
103 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
TheAres 2002-12-26
  • 打赏
  • 举报
回复
把全部的代码贴上来,或者发到cxli@qingdaonews.com,说不定会帮上什么忙.
dogdogdog 2002-12-26
  • 打赏
  • 举报
回复
全部代码如下:

//Main.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace WebClick
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtUrl;
private System.Windows.Forms.Label lblUrl;
private System.Windows.Forms.Label lblNumber;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.NumericUpDown numVisit;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public frmMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtUrl = new System.Windows.Forms.TextBox();
this.lblUrl = new System.Windows.Forms.Label();
this.numVisit = new System.Windows.Forms.NumericUpDown();
this.lblNumber = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numVisit)).BeginInit();
this.SuspendLayout();
//
// txtUrl
//
this.txtUrl.Location = new System.Drawing.Point(80, 40);
this.txtUrl.Name = "txtUrl";
this.txtUrl.Size = new System.Drawing.Size(312, 21);
this.txtUrl.TabIndex = 0;
this.txtUrl.Text = "";
//
// lblUrl
//
this.lblUrl.Location = new System.Drawing.Point(32, 40);
this.lblUrl.Name = "lblUrl";
this.lblUrl.Size = new System.Drawing.Size(32, 23);
this.lblUrl.TabIndex = 1;
this.lblUrl.Text = "Url";
//
// numVisit
//
this.numVisit.Location = new System.Drawing.Point(80, 96);
this.numVisit.Name = "numVisit";
this.numVisit.Size = new System.Drawing.Size(56, 21);
this.numVisit.TabIndex = 2;
//
// lblNumber
//
this.lblNumber.Location = new System.Drawing.Point(24, 96);
this.lblNumber.Name = "lblNumber";
this.lblNumber.Size = new System.Drawing.Size(48, 16);
this.lblNumber.TabIndex = 3;
this.lblNumber.Text = "Number";
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(304, 160);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 4;
this.btnOK.Text = "确定";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(408, 206);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnOK,
this.lblNumber,
this.numVisit,
this.lblUrl,
this.txtUrl});
this.Name = "frmMain";
this.Text = "设置";
this.Load += new System.EventHandler(this.frmMain_Load);
((System.ComponentModel.ISupportInitialize)(this.numVisit)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}

private void btnOK_Click(object sender, System.EventArgs e)
{
if(txtUrl.Text !="")
{
for(int i=0;i<numVisit.Value;i++)
VisitWeb(txtUrl.Text );
}
}


private void VisitWeb(string sUrl)
{
//建立一个线程访问网页
frmWeb frmweb=new frmWeb();
frmweb.Url =sUrl ;
ThreadStart myWeb=new ThreadStart(frmweb.Show);
Thread myVisit = new Thread(myWeb);
myVisit.Start();
}

private void frmMain_Load(object sender, System.EventArgs e)
{

}
}
}

//frmWeb:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//using System.Threading;

namespace WebClick
{
/// <summary>
/// frmWeb 的摘要说明。
/// </summary>
public class frmWeb : System.Windows.Forms.Form
{
private AxSHDocVw.AxWebBrowser axWebBrowser1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public string Url;

public frmWeb()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmWeb));
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
this.SuspendLayout();
//
// axWebBrowser1
//
this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(292, 266);
this.axWebBrowser1.TabIndex = 0;
//
// frmWeb
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.axWebBrowser1});
this.Name = "frmWeb";
this.Text = "frmWeb";
this.Load += new System.EventHandler(this.frmWeb_Load);
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
this.ResumeLayout(false);

}
#endregion

private void frmWeb_Load(object sender, System.EventArgs e)
{
Object refmissing = System.Reflection.Missing.Value;

axWebBrowser1.Navigate(Url,ref refmissing,ref refmissing,ref refmissing,ref refmissing);
}
}
}
yarshray 2002-12-25
  • 打赏
  • 举报
回复
http://www.aspcool.com/lanmu/browse1.asp?ID=995&bbsuser=csharp
dogdogdog 2002-12-25
  • 打赏
  • 举报
回复
确实在同一目录下
hfayga 2002-12-25
  • 打赏
  • 举报
回复
1.要看编译成的EXE的属性是不是中间语言,如果是,要安装Frame
2.要把引用的dll与EXE放在同一个目录(也可配置)
TheAres 2002-12-24
  • 打赏
  • 举报
回复
不需要.
你把bin目录下的文件dir一下,列上来,看看Interop.SHDocVw.dll和AxInterop.SHDocVw.dll是否在那个目录下.
dogdogdog 2002-12-23
  • 打赏
  • 举报
回复
dll和exe已经在同一个目录下了。

是否需要注册这两个dll?
TheAres 2002-12-21
  • 打赏
  • 举报
回复
要把.Net IDE将Com控件转换的那两个dll一起带上才可以,要和exe文件在一个目录.

关于这两个文件的作用和如何转换来的,看看微软中国上面的文章:
http://chs.gotdotnet.com/quickstart/winforms/doc/WinFormsAxHosting.aspx
echevil 2002-12-21
  • 打赏
  • 举报
回复
是一个COM控件吧,必须注册了才能用的。
echevil 2002-12-21
  • 打赏
  • 举报
回复
会不会是WebBrowser控件的问题?我怎么没见到这个控件?

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧