[英]System.Nullable<System.TimeSpan>' does not contain a definition for 'TotalMinutes'
[英]'System.Nullable<bool>' does not contain a definition for 'OK'
我正在嘗試一個基本的文件對話框示例, 在這里 ,我收到一個關於'確定'的錯誤,我不知道為什么。
錯誤1'System.Nullable'不包含'OK'的定義,並且沒有擴展方法'OK'可以找到接受類型'System.Nullable'的第一個參數(你是否缺少using指令或匯編引用?)
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
.NET框架中有兩個版本的OpenFileDialog
: WinForms one和WPF one 。 看起來你正在使用WPF,實際上,它確實從OpenFile
返回Nullable<bool>
值。 WinForm版本返回一個DialogResult
值,這似乎是您所期望的。
聽起來你有一個名為DialogResult
的本地屬性。 請嘗試使用System.Windows.Forms.DialogResult.OK
。
看起來它試圖將ShowDialog用於System.Windows.Controls
。 嘗試將調用顯式System.Windows.Forms
喜歡:
System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.