大致效果看起来如下_第1页
大致效果看起来如下_第2页
大致效果看起来如下_第3页
大致效果看起来如下_第4页
大致效果看起来如下_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、大致效果看起来如下点击浏览按钮,会弹出一个对话框,让我们选择一个文件夹选择某个文件夹之后,点击“确定”,此时会把该目录下面的图片文件读取出来一个列表。如下面所示 那么大致是怎么实现的呢?首先,让我们的那个类型继承System.Windows.Forms.UserControl类型其次,在这个UserControl上面设计一些子控件我们在拖拽控件的时候,设计器会帮助生成一个方法:InitializeComponent,类似下面这样 private void InitializeComponent() ponents = new System.ComponentModel.Contain

2、er(); this.listView1 = new System.Windows.Forms.ListView(); this.imageList1 = new System.Windows.Forms.ImageList(ponents); this.btBrowser = new System.Windows.Forms.Button(); this.btUpload = new System.Windows.Forms.Button(); this.SuspendLayout(); / / listView1 / this.listView1.Anchor = (System.Wind

3、ows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); this.listView1.LargeImageList = this.imageList1; this.listView1.Location = new System.Drawing.Point(8, 5); t

4、his.listView1.Name = "listView1" this.listView1.Size = new System.Drawing.Size(790, 195); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; / / imageList1 / this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1.ImageSize

5、= new System.Drawing.Size(64, 64); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; / / btBrowser / this.btBrowser.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left); this.btBrowser.Location = new System

6、.Drawing.Point(5, 206); this.btBrowser.Name = "btBrowser" this.btBrowser.Size = new System.Drawing.Size(76, 23); this.btBrowser.TabIndex = 1; this.btBrowser.Text = "浏览." this.btBrowser.UseVisualStyleBackColor = true; this.btBrowser.Click += new System.EventHandler(this.btBrowser_

7、Click); / / btUpload / this.btUpload.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left); this.btUpload.Location = new System.Drawing.Point(86, 206); this.btUpload.Name = "btUpload" this.btUpload.Size = new System.

8、Drawing.Size(75, 23); this.btUpload.TabIndex = 2; this.btUpload.Text = "上传." this.btUpload.UseVisualStyleBackColor = true; / / MyActiveXControl / this.BackColor = System.Drawing.Color.White; this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.Controls.Add(this.btUpload);

9、this.Controls.Add(this.btBrowser); this.Controls.Add(this.listView1); this.Name = "MyActiveXControl" this.Padding = new System.Windows.Forms.Padding(5); this.Size = new System.Drawing.Size(806, 237); this.ResumeLayout(false); 接下来编写代码,与windows Forms里面编程没有任何区别。为按钮绑定事件处理程序等等这里要注意的是,需要手工地添加一个构

10、造函数,在构造函数中调用InitializeComponent public MyActiveXControl() InitializeComponent(); 至于选择文件夹的代码,大致如下 private void btBrowser_Click(object sender, EventArgs e) FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); if (dialog.ShowDialog() = DialogResult.OK) listView1.Items.Clear(); DirectoryInfo dir = new DirectoryInfo(dialog.SelectedPath); foreach (FileInfo file in dir.GetFiles("*.jpg") ListViewI

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论