欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#中OpenFileDialog和PictrueBox的用法分析

 更新時間:2014年11月12日 10:47:11   投稿:shichen2014  
這篇文章主要介紹了C#中OpenFileDialog和PictrueBox的用法,以實(shí)例的形式較為詳細(xì)的分析了OpenFileDialog和PictrueBox使用時的注意事項(xiàng)與具體用法,具有一定的參考借鑒價值,需要的朋友可以參考下

本文實(shí)例講述了C#中OpenFileDialog和PictrueBox的用法。分享給大家供大家參考。具體用法分析如下:

先來看看這段代碼:

復(fù)制代碼 代碼如下:
string resultFile = "";
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "D:\\Patch";
openFileDialog1.Filter = "All files (*.*)|*.*|txt files (*.txt)|*.txt";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
  if (openFileDialog1.ShowDialog() == DialogResult.OK)
     resultFile = openFileDialog1.FileName;

resultFile 就能得到你選中文件的路徑

OpenFileDialog控件有以下基本屬性

InitialDirectory 對話框的初始目錄

Filter 要在對話框中顯示的文件篩選器,例如,"文本文件(*.txt)|*.txt|所有文件(*.*)||*.*"
FilterIndex 在對話框中選擇的文件篩選器的索引,如果選第一項(xiàng)就設(shè)為1
RestoreDirectory 控制對話框在關(guān)閉之前是否恢復(fù)當(dāng)前目錄
FileName 第一個在對話框中顯示的文件或最后一個選取的文件
Title 將顯示在對話框標(biāo)題欄中的字符
AddExtension 是否自動添加默認(rèn)擴(kuò)展名
CheckPathExists 在對話框返回之前,檢查指定路徑是否存在
DefaultExt 默認(rèn)擴(kuò)展名
DereferenceLinks 在從對話框返回前是否取消引用快捷方式
ShowHelp 啟用"幫助"按鈕
ValiDateNames 控制對話框檢查文件名中是否不含有無效的字符或序列

怎樣設(shè)置OpenFileDialog組件的Filter,使實(shí)現(xiàn)一次過濾出多種擴(kuò)展名的文件?

復(fù)制代碼 代碼如下:
dlg.Filter   =   "Image   Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All   files   (*.*)|*.* "

第一個參數(shù)是picturebox的寬度,第二個是picturebox的高度,第三個是你的圖片。這個方法可以把圖片調(diào)整到合適的大小。你就不要設(shè)置SizeMode的屬性了,通過這個方法得到合適的圖片后,設(shè)置picturebox的image屬性等于這個圖片,不要設(shè)置背景圖。我沒有測試。你自己去測試下吧,如果還是有問題,那就是圖片太小了。你要重新做張圖

復(fù)制代碼 代碼如下:
public Image GetNewImage(int newImgWidth, int newImgHeight, Image srcImage)
{
    Image newImg = srcImage.GetThumbnailImage(newImgWidth, newImgHeight, null, new IntPtr());
    Graphics gr = Graphics.FromImage(newImg);
    gr.DrawImage(newImg, 0, 0, newImg.Width, newImg.Height);
    gr.Dispose();
    return newImg;
}

PictrueBox的SizeMode屬性:

復(fù)制代碼 代碼如下:
// 摘要:
//     圖像被置于 System.Windows.Forms.PictureBox 的左上角。如果圖像比包含它的   System.Windows.Forms.PictureBox
//     大,則該圖像將被剪裁掉。
Normal = 0,
//
// 摘要:
//     System.Windows.Forms.PictureBox 中的圖像被拉伸或收縮,以適合 System.Windows.Forms.PictureBox
//     的大小。
StretchImage = 1,
//
// 摘要:
//     調(diào)整 System.Windows.Forms.PictureBox 大小,使其等于所包含的圖像大小。
AutoSize = 2,
//
// 摘要:
//     如果 System.Windows.Forms.PictureBox 比圖像大,則圖像將居中顯示。如果圖像比 System.Windows.Forms.PictureBox
//     大,則圖片將居于 System.Windows.Forms.PictureBox 中心,而外邊緣將被剪裁掉。
CenterImage = 3,
//
// 摘要:
//     圖像大小按其原有的大小比例被增加或減小。
Zoom = 4,

希望本文所述對大家的C#程序設(shè)計有所幫助。

相關(guān)文章

最新評論