<%-- 最新动态 Begin --%>
|
|
|
|
|
|
<%-- 最新动态 End --%>
|
<%-- 最新动态 Begin --%>
|
|
|
|
|
|
<%-- 最新动态 End --%>
|
<%-- 最新动态 Begin --%>
|
|
|
|
|
|
<%-- 最新动态 End --%>
|
|
 |
|
 |
本文由中国C#技术学习中心整理 如果你对本文有不明之处请到技术论坛讨论!
我想用vc做一activex控件对初始编程的人来说可能不是一件容易的事吧,在.net出现之后,有更简单的技术来替代它,那就是winform control,它可以把做好的winform control直接嵌入到IE中,对于访问本地磁盘和注册表的winform control,可能要重新设置安全策略。我们就拿多文件上传为例,进行讲述。
(一) 做一winform control
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Net;
using System.IO;
namespace MultiFileUpload
  {
 /**////
/// UserControl1 的摘要说明。
///
public class Demo : System.Windows.Forms.UserControl
 {
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Splitter splitter2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
public WebClient wc=new WebClient();
private string filestr="";
private string[] FileListArr;
private System.Windows.Forms.Splitter splitter3;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Splitter splitter4;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.ListBox listBox1;
private string uri="http://10.126.65.96/WebApplication2";//根据自己的情况设置
private string serverfolder="usercontrols";//根据自己的情况设置
 /**////
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;

public Demo()
 {
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();

// TODO: 在 InitComponent 调用后添加任何初始化

}

 /**////
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
 {
if( disposing )
 {
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
public string Uri
 {
set
 {
this.uri=value;
}
get
 {
return this.uri;
}
}
public string ServerFolder
 {
set
 {
this.serverfolder=value;
}
get
 {
return this.serverfolder;
}
}
 组件设计器生成的代码#region 组件设计器生成的代码
 /**////
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
private void InitializeComponent()
 {
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Demo));
this.panel1 = new System.Windows.Forms.Panel();
this.splitter3 = new System.Windows.Forms.Splitter();
this.panel2 = new System.Windows.Forms.Panel();
this.button2 = new System.Windows.Forms.Button();
this.splitter2 = new System.Windows.Forms.Splitter();
this.button1 = new System.Windows.Forms.Button();
this.splitter1 = new System.Windows.Forms.Splitter();
this.label1 = new System.Windows.Forms.Label();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.splitter4 = new System.Windows.Forms.Splitter();
this.panel3 = new System.Windows.Forms.Panel();
this.listBox1 = new System.Windows.Forms.ListBox();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.panel3.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.panel3);
this.panel1.Controls.Add(this.splitter4);
this.panel1.Controls.Add(this.progressBar1);
this.panel1.Controls.Add(this.splitter3);
this.panel1.Controls.Add(this.panel2);
this.panel1.Controls.Add(this.splitter1);
this.panel1.Controls.Add(this.label1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(568, 376);
this.panel1.TabIndex = 0;
//
// splitter3
//
this.splitter3.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter3.Location = new System.Drawing.Point(72, 43);
this.splitter3.Name = "splitter3";
this.splitter3.Size = new System.Drawing.Size(494, 3);
this.splitter3.TabIndex = 4;
this.splitter3.TabStop = false;
//
// panel2
//
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Controls.Add(this.button2);
this.panel2.Controls.Add(this.splitter2);
this.panel2.Controls.Add(this.button1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
this.panel2.Location = new System.Drawing.Point(0, 43);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(72, 331);
this.panel2.TabIndex = 2;
//
// button2
//
this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(0, 155);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(70, 174);
this.button2.TabIndex = 2;
this.button2.Text = "上传文件";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// splitter2
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter2.Location = new System.Drawing.Point(0, 152);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(70, 3);
this.splitter2.TabIndex = 1;
this.splitter2.TabStop = false;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button1.Location = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(70, 152);
this.button1.TabIndex = 0;
this.button1.Text = "选择文件";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter1.Location = new System.Drawing.Point(0, 40);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(566, 3);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label1.Dock = System.Windows.Forms.DockStyle.Top;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(566, 40);
this.label1.TabIndex = 0;
this.label1.Text = "多文件上传";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// progressBar1
//
this.progressBar1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.progressBar1.Location = new System.Drawing.Point(72, 351);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(494, 23);
this.progressBar1.TabIndex = 5;
//
// splitter4
//
this.splitter4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter4.Location = new System.Drawing.Point(72, 349);
this.splitter4.Name = "splitter4";
this.splitter4.Size = new System.Drawing.Size(494, 2);
this.splitter4.TabIndex = 6;
this.splitter4.TabStop = false;
//
// panel3
//
this.panel3.Controls.Add(this.listBox1);
this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel3.Location = new System.Drawing.Point(72, 46);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(494, 303);
this.panel3.TabIndex = 7;
//
// listBox1
//
this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(0, 0);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(494, 292);
this.listBox1.TabIndex = 0;
//
// Demo
//
this.Controls.Add(this.panel1);
this.Name = "Demo";
this.Size = new System.Drawing.Size(568, 376);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
 | |