´°Ìå¶Ô»°¿ò×é¼þÓë΢ÈíÊÓ´°²Ù×÷ϵͳÖеĶԻ°¿òÊÇÒ»ÑùµÄ£»Ò²¾ÍÊÇ˵£¬PrintDialog ×é¼þÊÇ¡°´òÓ¡¡±¶Ô»°¿ò£¬OpenFileDialog ×é¼þÊÇ ¡°´ò¿ªÎļþ¡±¶Ô»°¿ò£¬ÒÀ´ËÀàÍÆ¡£
ÓëÒÔÍùµÄ Microsoft Visual Basic 6.0 µÈ Windows ³ÌÐòÉè¼ÆÓïÑÔÏàËÆ£¬.NET ¿ò¼ÜÌṩÁË Windows Óû§¶úÊìÄÜÏêµÄ¶Ô»°¿ò¡£¶Ô»°¿òµÄ¾ßÌåÓÃ;(Èç Printdialog ¿ÉÓÃÓÚÎļþ´òÓ¡µÈ)ͨ³£ÊǶàÖÖ¶àÑùµÄ¡£¹Ê¶øÔÚ .NET ¿ò¼ÜÌṩµÄ»ù´¡ÀàÖв»°üº¬ÓÃÓÚÎļþ´òÓ¡¡¢ÑÕɫѡÔñµÈ¾ßÌå²Ù×÷µÄ´úÂ룬¶øÄãÈ´¿ÉÒÔ¸ù¾ÝÓ¦ÓóÌÐòµÄÐèÒªÁé»îµØÊµÏÖËüÃÇ¡£Òò´Ë£¬ÔÚ .NET ¿ò¼ÜÏ£¬Äã²»µ«¿ÉÒÔÖ±½ÓÓ¦Óñê×¼¶Ô»°¿ò£¬¶øÇÒÄܸù¾ÝÓû§µÄÑ¡Ôñ×÷³ö²»Í¬µÄÏìÓ¦¡£±¾ÎÄÌṩµÄ´úÂëÆäÓÃ;¾ÍÔÚÓÚ´Ë¡£
×¢Ò⣬¹ØÓÚ¸÷ÖÖ¶Ô»°¿òµÄÊôÐÔ¡¢·½·¨ºÍʼþµÄÍêÕûÃèÊö£¬¿ÉÒÔÔÚÏàÓ¦ÀàµÄ Members Ò³ÃæÖÐÕÒµ½¡£±ÈÈçÒª²é¿´ OpenFileDialog ×é¼þµÄijһ·½·¨£¬¾Í¿ÉÒÔÔÚÎĵµË÷ÒýµÄ¡°OpenFileDialog class, all members¡±À¸Ä¿ÖÐÕÒµ½Ïà¹ØµÄÖ÷Ìâ¡£
OpenFileDialog ×é¼þ
OpenFileDialog ¶Ô»°¿òʹµÃÓû§Äܹ»Í¨¹ýä¯ÀÀ±¾µØ»òÕßÔ¶³ÌµÄÎļþϵͳÒÔ´ò¿ªËùÑ¡Îļþ¡£Ëü½«·µ»ØÎļþ·¾¶ºÍËùÑ¡µÄÎļþÃû¡£
OpenFileDialog ×é¼þºÍ SaveFileDialog ×é¼þ(ÏÂÎĽ«»áÏêϸÃèÊö)°üº¬ÁËÓÃÓÚä¯ÀÀºÍѡȡÎļþËù±ØÐèµÄ»ù±¾´úÂë¡£ÓÐÁËËüÃÇ£¬Äã¾Í²»±ØÎªÕâЩ¹¦ÄܱàдÈκδúÂ룬½ø¶øÄܹ»×¨ÐÄʵÏÖ´ò¿ª»òÕß±£´æÎļþµÈ¾ßÌå²Ù×÷¡£
×¢Ò⣬FileDialog ÀàµÄ FilterIndex ÊôÐÔ(ÓÉÓڼ̳еÄÔÒò£¬Îª OpenFileDialog ºÍ SaveFileDialog ÀàËù¹²ÓÐ) ʹÓà one-based Ë÷Òý(ÒëÕß×¢£ºÖ¸´Ó 1 ¿ªÊ¼±àºÅµÄË÷Òý)¡£ ´ËÌØÐÔ½«ÔÚÏÂÎĵĴúÂëÖÐÓõ½(²¢ÇÒ»áÔÚÏàӦλÖÃÔÙ´ÎÇ¿µ÷)¡£µ±Ó¦ÓóÌÐòͨ¹ýÀàÐ͹ýÂËÆ÷´ò¿ªÎļþʱ£¬»òÕßÐèÒª±£´æÎªÌض¨¸ñʽµÄÎļþ(±ÈÈ磺±£´æÎª´¿Îı¾Îļþ¶ø²»ÊǶþ½øÖÆÎļþ)ʱ£¬ÕâÒ»µãÊǷdz£ÖØÒªµÄ¡£ÈËÃÇÔÚʹÓà FilterIndex ÊôÐÔʱȴ¾³£ÍüÁËËü£¬Òò´ËÏÖÔÚÎñ±ØÒª°ÑËü¼Çס¡£
ÏÂÁдúÂëͨ¹ý Button ¿Ø¼þµÄ Click ʼþµ÷Óà OpenFileDialog ×é¼þ¡£µ±Óû§Ñ¡ÖÐij¸öÎļþ£¬²¢ÇÒµ¥»÷ OK µÄʱºò£¬ËùÑ¡µÄÎļþ½«±»´ò¿ª¡£ÔÚ±¾ÀýÖУ¬ÎļþÄÚÈݽ«±»ÏÔʾÔÚÏûÏ¢¿òÄÚ£¬ÒÔ֤ʵÎļþÁ÷±»¶ÁÈë¡£
±¾Àý¼ÙÉè´æÔÚÃûΪ Button1 µÄ Button ¿Ø¼þºÍÃûΪ OpenFileDialog1 µÄ OpenFileDialog ¿Ø¼þ¡£
' Visual Basic
' NOTE: You must import the following namespace:
' Imports System.IO
' Without this import statement at the beginning
' of your code, the example will not function.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim sr As New StreamReader(OpenFileDialog1.FileName)
MessageBox.Show(sr.ReadToEnd)
sr.Close()
End If
End Sub
// C#
// NOTE: You must import the following namespace:
// using System.IO;
// Without this import statement at the beginning
// of your code, the example will not function.
private void button1_Click(object sender, System.EventArgs e)
{
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(openFileDialog1.FileName);
MessageBox.Show(sr.ReadToEnd());
sr.Close();
}
}
´ò¿ªÎļþ»¹¿ÉÒÔʹÓà OpenFileDialog ×é¼þµÄ OpenFile ·½·¨£¬Ëü½«·µ»ØÎļþµÄÿһ¸ö×Ö½Ú¡£ÔÚÏÂÃæµÄÀý×ÓÖУ¬Ò»¸ö OpenFileDialog ×é¼þ½«±»ÊµÀý»¯£¬ËüʹÓÃÁË cursor ¹ýÂËÆ÷£¬ÒÔÏÞ¶¨Óû§Ö»ÄÜѡȡ¹â±êÎļþ(À©Õ¹ÃûΪ .cur)¡£Ò»µ©Ä³¸ö .cur Îļþ±»Ñ¡ÖУ¬´°ÌåµÄ¹â±ê¾Í±»Éè³É¸ÃÎļþÃè»æµÄ¹â±êÐÎ×´¡£
±¾Àý¼ÙÉè´æÔÚÃûΪ Button1 µÄ Button ¿Ø¼þ¡£
' Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Display an OpenFileDialog so the user can select a Cursor.
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "Cursor Files|*.cur"
openFileDialog1.Title = "Select a Cursor File"
' Show the Dialog.
' If the user clicked OK in the dialog and
' a .CUR file was selected, open it.
If openFileDialog1.ShowDialog() = DialogResult.OK Then
If openFileDialog1.FileName <> "" Then
' Assign the cursor in the Stream to the Form's Cursor property.
Me.Cursor = New Cursor(openFileDialog1.OpenFile())
End If
End If
End Sub
// C#
private void button1_Click(object sender, System.EventArgs e)
{
// Display an OpenFileDialog so the user can select a Cursor.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Cursor Files|*.cur";
openFileDialog1.Title = "Select a Cursor File";
// Show the Dialog.
// If the user clicked OK in the dialog and
// a .CUR file was selected, open it.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if(openFileDialog1.FileName != "")
{
// Assign the cursor in the Stream to the Form's Cursor property.
this.Cursor = new Cursor(openFileDialog1.OpenFile());
}
}
}
¹ØÓÚ¶ÁÈ¡ÎļþÁ÷µÄ½øÒ»²½ÐÅÏ¢£¬Çë²ÎÔÄFileStream.BeginRead ·½·¨¡£
SaveFileDialog ×é¼þ
±¾¶Ô»°¿òÔÊÐíÓû§ä¯ÀÀÎļþϵͳ²¢ÇÒѡȡ½«±»Ð´ÈëµÄÎļþ¡£µ±È»£¬Ä㻹±ØÐëΪÎļþдÈë±àд¾ßÌå´úÂë¡£
ÏÂÁдúÂëͨ¹ý Button ¿Ø¼þµÄ Click ʼþµ÷Óà SaveFileDialog ×é¼þ¡£µ±Óû§Ñ¡ÖÐij¸öÎļþ£¬²¢ÇÒµ¥»÷ OK µÄʱºò£¬RichTextBox ¿Ø¼þÀïµÄÄÚÈݽ«±»±£´æµ½ËùÑ¡µÄÎļþÖС£
±¾Àý¼ÙÉè´æÔÚÃûΪ Button1 µÄ Button ¿Ø¼þ£¬ÃûΪ RichTextBox1 µÄ RichTextBox ¿Ø¼þºÍÃûΪ OpenFileDialog1 µÄ SaveFileDialog ¿Ø¼þ¡£
' Visual Basic
ÎÄÕÂÕûÀí£ºÎ÷²¿ÊýÂë--רҵÌṩÓòÃû×¢²á¡¢ÐéÄâÖ÷»ú·þÎñ
http://www.west263.com
ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúÒª×ªÔØ±¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!



