大致效果看起來如下_第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

提交評論