




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年部編版語文五年級下冊第一次月考測試及答案(共2套)
- 2014保險銷售從業沖刺練習卷及答案2
- 農產品安全監測信息共享協議
- 童話里的森林王國:想象作文10篇范文
- 軟件測試與性能優化操作規程
- 《古典詩詞鑒賞方法分享:高中語文課程》
- 機械工程零件加工技術知識點詳解
- 化工工藝流程操作及安全知識要點
- 歷史年代事件考查題集
- 2025年中考語文二輪復習講練測第01講 巧辨字音字形(課件)
- 國家開放大學《Python語言基礎》實驗2:基本數據類型和表達式計算參考答案
- 吉蘭-巴雷綜合征
- “項目路演”評分細則
- 部編版小學語文四年級下冊教師教學用書(教學參考)完整版
- pvc生產工藝流程圖
- 利用情境引導學生學習的教學課件設計
- 國開電大專科《辦公室管理》期末紙質考試總題庫2024版
- 倉儲績效考核實施細則倉庫人員績效考核內容與評分標準
- 18年浙江高考英語真題高頻詞匯超全整理
- 10kv及以下電力客戶受電工程中間檢查和竣工檢驗規范
- 工業互聯網平臺架構
評論
0/150
提交評論