本文整理汇总了C#中System.Windows.Controls.OpenFileDialog.ShowDialog方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.ShowDialog方法的具体用法?C# OpenFileDialog.ShowDialog怎么用?C# OpenFileDialog.ShowDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.ShowDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenClick
private void OpenClick(object sender, RoutedEventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "clients.json|clients.json"; //http://www.wpf-tutorial.com/dialogs/the-openfiledialog/
openDialog.ShowDialog();
string ClientFile = openDialog.FileName;
openDialog.Filter = "workers.json|workers.json";
openDialog.ShowDialog();
string WorkerFile = openDialog.FileName;
if (ClientFile == "" || WorkerFile == "") { MessageBox.Show("Select both files!"); return; }
try
{
Clients.RemoveAll(t => t.Name == t.Name);
Clients.AddRange(JsonConvert.DeserializeObject<List<Person>>(File.ReadAllText(ClientFile)));
ClientData.Items.Refresh();
ClientGrid.IsEnabled = true;
Workers.RemoveAll(t => 1 == 1);
Workers.AddRange(JsonConvert.DeserializeObject<List<Person>>(File.ReadAllText(WorkerFile)));
WorkerData.Items.Refresh();
WorkerGrid.IsEnabled = true;
}
catch (Exception exc)
{
MessageBox.Show("Something went wrong! " + exc.Message);
}
}
示例2: Button3_Click
private void Button3_Click(object sender, RoutedEventArgs eArgs)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
if (dlg.ShowDialog() != true)
return;
var txtLines = System.IO.File.ReadAllLines(dlg.FileName);
var pts = new ObservableCollection<NehPoint>();
var idexFile = Path.ChangeExtension(dlg.FileName, ".idx");
using (var idexStream = new FileStream(idexFile, FileMode.Create))
{
using (var gsiWriter = new IDEXFileWriter(idexStream))
{
foreach (var ln in txtLines)
{
if (!string.IsNullOrEmpty(ln.Trim())) {
var pt = new NehPoint(ln);
gsiWriter.AddPoint(pt.Id, pt.E, pt.N, pt.H, null);
pts.Add(pt);
}
}
}
}
PtsGrid.ItemsSource = pts;
MessageBox.Show("Saved to: \r\n" + idexFile);
}
示例3: ImportImageButtonClick
private void ImportImageButtonClick(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
#if WPF
openFileDialog.Filter = "Image Files (*.png, *.jpg, *.bmp)|*.png;*.jpg;*.bmp";
#else
openFileDialog.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg";
#endif
bool? dialogResult = openFileDialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value == true)
{
Image image = new Image();
#if WPF
image.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute));
#else
using (var fileOpenRead = openFileDialog.File.OpenRead())
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(fileOpenRead);
image.Source = bitmap;
}
#endif
Viewbox viewBox = new Viewbox() { Stretch = Stretch.Fill, Margin = new Thickness(-4) };
viewBox.Child = image;
RadDiagramShape imageShape = new RadDiagramShape()
{
Content = viewBox
};
this.diagram.Items.Add(imageShape);
}
}
示例4: BtnNodefileSel_OnClick
/// <summary>
/// Get the nodes from the selected text file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnNodefileSel_OnClick(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
//openFileDialog.InitialDirectory = citiesIn.filepath;
if (openFileDialog.ShowDialog() == true)
{
txtboxNodefile.Text = @"...\" + openFileDialog.SafeFileName;
citiesIn.filepath = openFileDialog.FileName;
}
// set the value of the combobox
nodelist = citiesIn.GetCitieses();
maxNumofCities = nodelist.Count;
List<string> citynames = nodelist.Select(cityNode => cityNode.city).ToList();
comboboxStartCity.ItemsSource = citynames;
comboboxStartCity.SelectedIndex = 0;
lboxManualSelectNodes.ItemsSource = citynames;
if (RandomNodeSelect.IsChecked == true)
lboxManualSelectNodes.IsEnabled = false;
else
lboxManualSelectNodes.IsEnabled = true;
// draw the circles
_drawlines(citylisttodraw);
}
示例5: InitGamePath
/// <summary>
/// Initializes the gamePath if not specefied defines new one
/// </summary>
private void InitGamePath()
{
if (AppSettings.getPropertyValue<string>("GamePath").Length > 2 || Directory.Exists(AppSettings.getPropertyValue<string>("GamePath")) == false)
{
RegistryKey regKey = Registry.CurrentUser;
regKey = regKey.OpenSubKey(@"Software\Valve\Steam");
if (regKey != null && regKey.GetValue("SteamPath") != null && Directory.Exists(regKey.GetValue("SteamPath").ToString().Replace("/", "\\") + "\\steamapps\\common\\Arma 3"))
{
AppSettings.setProperty("GamePath", regKey.GetValue("SteamPath").ToString().Replace("/", "\\") + "\\steamapps\\common\\Arma 3");
AppSettings.SaveAsync();
return;
}
else
if (MessageBox.Show("Unable to locate \"arma3.exe\"!" + Environment.NewLine + "Do you want so specify it?", "Installation not found!", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Arma 3|arma3.exe";
if (ofd.ShowDialog() == true)
{
AppSettings.setProperty("GamePath", ofd.FileName.Replace("\\" + ofd.FileName.Split('\\')[ofd.FileName.Split('\\').Length - 1], ""));
AppSettings.SaveAsync();
}
else
Environment.Exit(1223);
}
else
Environment.Exit(1223);
}
}
示例6: btnRun_Click
private void btnRun_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Programs|*.exe|All files|*.*";
dlg.DefaultExt = ".exe";
if (!(dlg.ShowDialog() ?? false))
return;
string path = dlg.FileName;
// remove UI before disposing profiler
//this.timeLine.ValuesList.Clear();
if (this.provider != null)
this.provider.Close();
if (this.profiler != null)
this.profiler.Dispose();
string pathToDb = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(Profiler.Controller.Profiler).Assembly.Location), "output.sdps");
if (File.Exists(pathToDb))
File.Delete(pathToDb);
this.database = new TempFileDatabase();
this.profiler = new Profiler.Controller.Profiler(path, database.GetWriter(), new ProfilerOptions());
profiler.RegisterFailed += delegate { MessageBox.Show("register failed"); };
profiler.DeregisterFailed += delegate { MessageBox.Show("deregister failed"); };
this.profiler.OutputUpdated += profiler_OutputUpdated;
this.profiler.SessionEnded += profiler_SessionEnded;
this.profiler.Start();
this.btnRun.IsEnabled = false;
this.btnStop.IsEnabled = true;
}
示例7: LoadImage
public void LoadImage()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Bitmap Image (.bmp)|*.bmp|PNG Image (.png)|*.png|JPEG Image (.jpeg)|*.jpeg|JPG Image (.jpg)|*.jpg";
bool? result = ofd.ShowDialog();
string fileName = "";
if (result != null)
fileName = ofd.FileName;
if (fileName == "")
return;
canvas.Children.Clear();
BitmapImage image;
using (FileStream stream = new FileStream(fileName, FileMode.Open))
{
stream.Position = 0;
image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.CacheOption = BitmapCacheOption.OnLoad;
image.EndInit();
}
canvas.Background = new ImageBrush(image);
}
示例8: OpenFile
/**
* <summary>Zeigt OpenFileDialog an</summary>
*
* <remarks>Beate, 09.10.2013.</remarks>
*/
private static string OpenFile()
{
string[] allfiles = { };
string filename = string.Empty;
string path = string.Empty;
List<string> filenameOnly = new List<string>();
OpenFileDialog inputDlg = new OpenFileDialog();
inputDlg.Multiselect = true;
inputDlg.InitialDirectory = @"";
inputDlg.Filter = "Xmascup Competitor Dateien|Competitor*.xml";
if (inputDlg.ShowDialog().Value)
{
allfiles = inputDlg.FileNames;
foreach (string s in allfiles)
{
filename = System.IO.Path.GetFileName(s);
path = System.IO.Path.GetDirectoryName(s);
filenameOnly.Add(filename);
}
MessageBox.Show("Eingabe: " + filename,
"Xmascup Dateiauswahl");
return allfiles[0].ToString();
}
else
{
MessageBox.Show("Keine Datei ausgewählt !!",
"Xmascup Dateiauswahl");
return "keine Auswahl getroffen";
}
}
示例9: SetMode
private void SetMode()
{
if(IsFileSelector)
{
ButtonText = "\uF15C";
ButtonCommand = new RelayCommand(() =>
{
var dlg = new OpenFileDialog();
if (dlg.ShowDialog() == true)
{
ConfigItemValue = dlg.FileName;
}
}, true);
}
else
{
ButtonText = "\uF07C";
ButtonCommand = new RelayCommand(() =>
{
var dlg = new System.Windows.Forms.FolderBrowserDialog();
dlg.ShowNewFolderButton = true;
dlg.ShowDialog();
if (!String.IsNullOrEmpty(dlg.SelectedPath))
{
ConfigItemValue = dlg.SelectedPath;
}
}, true);
}
}
示例10: Button_Click_1
//导入“1300000 "北京市" "联通"”文本格式数据
private void Button_Click_1(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt";
if (ofd.ShowDialog() == false)
{
return;
}
string[] lines = File.ReadLines(ofd.FileName, Encoding.Default).ToArray();
for (int i = 1; i < lines.Count(); i++)
{
string line = lines[i];
string[] str = line.Split('\t');
string startTeLNum = str[0];
string city = str[1];
city = city.Trim('"');
string telType = str[2];
telType = telType.Trim('"');
SqlHelper.ExecuteQuery(@"Insert into T_TelNum(StartTelNum,TelType,TelArea)
values(@StartTelNum,@TelType,@TelArea)",
new SqlParameter("@StartTelNum", startTeLNum),
new SqlParameter("@TelType", telType),
new SqlParameter("@TelArea", city));
}
MessageBox.Show("导入成功!"+lines.Count()+"条数据");
}
示例11: button1_Click
private void button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openfiledialog = new OpenFileDialog();
openfiledialog.ShowDialog();
//if(openfiledialog.FileOk)
// System.IO.Stream fileStream = openfiledialog.FileOk;
}
示例12: btn_insert_Click
//导入“张三|123”文本格式数据
private void btn_insert_Click(object sender, RoutedEventArgs e)
{
//打开文本
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt";
if (ofd.ShowDialog() != true)
{
return;
}
string filename = ofd.FileName;
//把文件一次读取到string集合中
IEnumerable<string> lines = File.ReadLines(filename, Encoding.Default);
foreach (string line in lines)
{
string[] segs = line.Split('|', ' ');
string name = segs[0];
string age = segs[1];
SqlHelper.ExecuteQuery("insert into custome(Name,Age)values(@Name,@Age)",
new SqlParameter("@Name", name),
new SqlParameter("@Age", Convert.ToInt32(age)));
}
MessageBox.Show("导入成功" + lines.Count() + "条数据!");
}
示例13: EjectButton_Click
private void EjectButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog { Title = "Select an audio file (wma, mp3, ...etc.) or video file..." };
if (dialog.ShowDialog() == true)
{
lock (lockAudio)
{
if (audioPlayer != null)
{
audioPlayer.Close();
audioPlayer = null;
}
if (fileStream != null)
{
fileStream.Close();
}
// Ask the user for a video or audio file to play
fileStream = new NativeFileStream(dialog.FileName, NativeFileMode.Open, NativeFileAccess.Read);
audioPlayer = new AudioPlayer(xaudio2, fileStream);
FilePathTextBox.Text = dialog.FileName;
SoundProgressBar.Maximum = audioPlayer.Duration.TotalSeconds;
SoundProgressBar.Value = 0;
// Auto-play
audioPlayer.Play();
}
}
}
示例14: btnBrowse_Click
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog();
if (dialog.ShowDialog() == true)
SetPreviewImage(dialog.FileName);
}
示例15: OpenOnExecuted
// �����Ϳ��� �̺�Ʈ �ڵ鷯 (���� IO�κ�)
// ������ ������� ���̴� Deserialize�� Serialize �κ�
void OpenOnExecuted(object sender, ExecutedRoutedEventArgs args)
{
OpenFileDialog dlg = new OpenFileDialog(); // ���Ͽ��� ���̾�α� ��ü ����
dlg.Filter = strFilter; // ǥ�õǴ� �������� ���� (�������ĺκ�)
Person pers; // PersonŬ���� ��ü ����
if ((bool)dlg.ShowDialog(this)) // ���Ͽ��� ���̾�αװ� ����������?
{
try
{
// �����̸� ���ڿ��� �д� ��Ʈ�� ���� ��ü ����
StreamReader reader = new StreamReader(dlg.FileName);
// ��Ʈ������ ��ü�� �籸�� �ؼ� Person ��ü�� ����
pers = (Person) xml.Deserialize(reader);
reader.Close();
}
catch (Exception exc)
{
MessageBox.Show("������ �����ھ�� �� _�� : " + exc.Message,
Title, MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
// DataContext�� ��Ұ� ���ε��� ���Ǵ� ������ �ҽ��� ���� ���� �� ��� ��
// ���ε��� ��Ÿ Ư���� �θ� ��ҷκ��� ��� �� �� �ֵ��� �ϴ� ����.
pnlPerson.DataContext = pers;
}
}