本文整理汇总了C#中System.Windows.Forms.OpenFileDialog类的典型用法代码示例。如果您正苦于以下问题:C# System.Windows.Forms.OpenFileDialog类的具体用法?C# System.Windows.Forms.OpenFileDialog怎么用?C# System.Windows.Forms.OpenFileDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Windows.Forms.OpenFileDialog类属于命名空间,在下文中一共展示了System.Windows.Forms.OpenFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFilm
public void AddFilm()
{
var ofd = new System.Windows.Forms.OpenFileDialog
{
};
if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
var fileInfo = new FileInfo(ofd.FileName);
var closeableTabItem = new CloseableTabItem
{
Header = fileInfo.Name,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Content = new FilmEditor(ofd.FileName)
};
if ((string) closeableTabItem.Header == "swag") return;
foreach (var tabb in homeTabControl.Items.Cast<TabItem>().Where(tabb => tabb.Header == closeableTabItem.Header))
{
homeTabControl.SelectedItem = tabb;
return;
}
homeTabControl.Items.Add(closeableTabItem);
homeTabControl.SelectedItem = closeableTabItem;
}
示例2: Action
public override bool Action(string action)
{
bool result = base.Action(action);
if (result)
{
if (action == ACTION_IMPORT)
{
using (System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog())
{
dlg.FileName = "";
dlg.Filter = "*.gcc|*.gcc|*.*|*.*";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_errormessage = "";
_filename = dlg.FileName;
_importMissing = System.Windows.Forms.MessageBox.Show(string.Concat(Utils.LanguageSupport.Instance.GetTranslation(STR_IMPORTMISSING),"?"), Utils.LanguageSupport.Instance.GetTranslation(ACTION_IMPORT), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question, System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes;
PerformImport();
if (!string.IsNullOrEmpty(_errormessage))
{
System.Windows.Forms.MessageBox.Show(_errormessage, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}
}
}
}
return result;
}
示例3: ChangePictureButton_Click
private void ChangePictureButton_Click(object sender, RoutedEventArgs e)
{
try
{
if (track != null)
{
var dialog = new System.Windows.Forms.OpenFileDialog();
dialog.Filter = "Image Files (*.jpg,*.jpeg,*.png,*.gif)|*.jpg;*.jpeg;*.png;*.gif|All Files (*.*)|*.*";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (track.Path.EndsWith(".mp3"))
{
tagController.AddPicture(track, dialog.FileName);
}
else
{
track.ImagePath = dialog.FileName;
trackController.Save(track);
}
}
}
}
catch (Exception ex)
{
log.Error("MediaPropertyView.ChangePictureButton_Click", ex);
MessageBox.Show("There was an error trying to add a picture to this track.\n\n" + ex.Message, "Could Not Add Picture To Track");
}
}
示例4: GetProperyField
public override FrameworkElement GetProperyField()
{
var pan = new DockPanel();
t = (new TextBox());
try
{
t.Text = GetVaueAsType<ImageSource>().ToString();
}
catch { }//Null value
t.TextChanged += delegate(object sender, TextChangedEventArgs e) { SetString(t.Text); };
var btn = new Button();
btn.Content = "...";
btn.Click += delegate
{
var fpd = new System.Windows.Forms.OpenFileDialog();
fpd.Filter = "Images|*.jpg;*.jpeg;*.png;*.gif;*.tif;*.bmp";
if (fpd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
t.Text = fpd.FileName;
}
};
DockPanel.SetDock(btn, Dock.Right);
pan.Children.Add(btn);
pan.Children.Add(t);
return pan;
}
示例5: UploadNewAvatar
private async void UploadNewAvatar(object sender, MouseButtonEventArgs e)
{
var dialog = new System.Windows.Forms.OpenFileDialog
{
DefaultExt = ".png",
InitialDirectory = Environment.SpecialFolder.MyPictures.ToString(),
Title = "Select a new avatar",
Filter = "Image files | *.png; *.jpg; *.bmp"
};
dialog.ShowDialog();
var mimeType = "image/";
if (String.IsNullOrEmpty(dialog.FileName)) return;
if (dialog.SafeFileName == null) return;
if (dialog.SafeFileName.EndsWith(".png")) mimeType += "png";
else if (dialog.SafeFileName.ToLower().EndsWith(".jpg")) mimeType += "jpg";
else if (dialog.SafeFileName.EndsWith(".bmp")) mimeType += "bmp";
else
{
dialog.Dispose();
App.Connection.NotificationController.Notification.Notify("That's not a supported file type! Please try again.");
return;
}
await App.Connection.SessionController.CurrentSession.UploadAvatar(
new FileStream(dialog.FileName, FileMode.Open), mimeType);
dialog.Dispose();
}
示例6: CreateContent
public UIElement CreateContent(string fileName)
{
Grid grid_main = new Grid();
grid_main.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100.0, GridUnitType.Star) });
grid_main.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
m_textBox_fileName = new TextBox();
m_textBox_fileName.TextChanged += (sender, args) => { FileName = m_textBox_fileName.Text; };
m_textBox_fileName.Text = fileName;
grid_main.SetGridRowColumn(m_textBox_fileName, 0, 0);
Button button_openFile = new Button() { Content = "Select file ..." };
button_openFile.Click += (x, y) =>
{
System.Windows.Forms.OpenFileDialog openFileDialog =
new System.Windows.Forms.OpenFileDialog()
{
CheckFileExists = false,
CheckPathExists = true
};
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
m_textBox_fileName.Text = openFileDialog.FileName;
};
grid_main.SetGridRowColumn(button_openFile, 0, 1);
return grid_main;
}
示例7: LoginDoor
public LoginDoor()
{
InitializeComponent();
var ass = System.Reflection.Assembly.GetExecutingAssembly().GetName();
Title = (ass.Name + " v" + ass.Version) + " 登陆界面";
DataContext = this;
//portTextBox.Text = TextBox_TextChanged_1"0";
//new Window1().Show();
IsHallMode = true;
ResetOptions();
IsRoomGained = false;
voiceEntry = new Voice.VoiceEntry();
voiceEntry.Play("voiceFmxy");
md_openDialog = new System.Windows.Forms.OpenFileDialog()
{
Multiselect = false, RestoreDirectory = true,
Filter = "PSG|*.psg"
};
SetSelTrigger();
SetLvTrigger();
//SetTeamTrigger();
LoadFromConfig();
}
示例8: Execute
static void Execute(ILSpyTreeNode[] nodes)
{
if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
return;
var dialog = new System.Windows.Forms.OpenFileDialog() {
Filter = ".NET NetModules (*.netmodule)|*.netmodule|All files (*.*)|*.*",
RestoreDirectory = true,
};
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
if (string.IsNullOrEmpty(dialog.FileName))
return;
var asm = new LoadedAssembly(MainWindow.Instance.CurrentAssemblyList, dialog.FileName);
if (asm.ModuleDefinition == null || asm.AssemblyDefinition != null) {
MainWindow.Instance.ShowMessageBox(string.Format("{0} is not a NetModule", asm.FileName), System.Windows.MessageBoxButton.OK);
asm.TheLoadedFile.Dispose();
return;
}
var cmd = new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm);
UndoCommandManager.Instance.Add(cmd);
MainWindow.Instance.JumpToReference(cmd.modNode);
}
示例9: bLearn_Click
private async void bLearn_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
dialog.CheckFileExists = true;
dialog.CheckPathExists = true;
dialog.Multiselect = true;
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (dialog.FileNames.Length >= 2)
{
string mimeType = getMimeType();
var infoOne = new FileInfo(dialog.FileNames[0]);
var infoTwo = new FileInfo(dialog.FileNames[1]);
var fileType = MimeDetective.LearnMimeType(infoOne, infoTwo, mimeType);
if (fileType != null)
{
//Detective.types.Add(fileType);
await animateLearnSuccess();
}
else
await animateLearnFailure();
}
}
else
await animateLearnFailure();
}
示例10: InitializeMap
public static SharpMap.Map InitializeMap(float angle)
{
using (var ofn = new System.Windows.Forms.OpenFileDialog())
{
ofn.Filter = "All files|*.*";
ofn.FilterIndex = 0;
if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var m = new SharpMap.Map();
var l = new SharpMap.Layers.GdiImageLayer(ofn.FileName);
m.Layers.Add(l);
m.ZoomToExtents();
var mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, m.WorldToImage(m.Center));
m.MapTransform = mat;
m.MaximumExtents = m.GetExtents();
m.EnforceMaximumExtents = true;
return m;
}
}
return null;
}
示例11: AddProjectClick
private void AddProjectClick(object sender, RoutedEventArgs e)
{
var openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Filter = "C# Project files (*.csproj)|*.csproj|VS Project files (*.vcproj)|*.vcproj|Android Project (*.project)|*.project";
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var newProject = ProjectManager.AddSyncedProject(openFileDialog.FileName);
// If newProject is null, then no project was added
if (newProject != null)
{
ViewModel.Refresh();
}
else
{
GlueGui.ShowMessageBox("The selected project is already a synced project.");
}
GluxCommands.Self.SaveGlux();
ProjectManager.SaveProjects();
}
}
示例12: CreateContent
public UIElement CreateContent(string fileName, IEnumerable<Filter> filters)
{
Grid grid_main = new Grid();
grid_main.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(100.0, GridUnitType.Star) });
grid_main.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
m_textBox_fileName = new TextBox();
m_textBox_fileName.TextChanged += (sender, args) => { FileName = m_textBox_fileName.Text; };
m_textBox_fileName.Text = fileName;
grid_main.SetRowColumn(m_textBox_fileName, 0, 0);
Button button_openFile = new Button() { Content = "Open file ..." };
button_openFile.Click += (x, y) =>
{
System.Windows.Forms.OpenFileDialog openFileDialog =
new System.Windows.Forms.OpenFileDialog()
{
Filter = (filters != null) ? filters.Select(f => f.ToString()).Aggregate((a,b) => string.Format("{0}|{1}", a, b)) : string.Empty,
CheckFileExists = true,
CheckPathExists = true
};
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
m_textBox_fileName.Text = openFileDialog.FileName;
};
grid_main.SetRowColumn(button_openFile, 0, 1);
return grid_main;
}
示例13: bt_browse_Click
public void bt_browse_Click(object sender, EventArgs e)
{
if ((tabControl_modType.SelectedItem as TabItem).Tag.ToString() == "zip")
{
System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
dialog.Filter = "Zipped mod|*.zip";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
tb_path.Text = dialog.FileName;
}
}
else
{
FolderSelectDialog fsd = new FolderSelectDialog();
fsd.ShowDialog();
if (fsd.ShowDialog())
{
tb_path.Text = fsd.FileName;
}
}
/*
string path = null;
if ((((tabControl.SelectedItem as TabItem).Tag) as string) == "zip")
{
System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog();
dialog.Filter = "Zipped mod|*.zip";
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
else
path = dialog.FileName;
}
*/
}
示例14: PrepareInsertFromDatabase
public override bool PrepareInsertFromDatabase()
{
bool result = false;
using (System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog())
{
if (string.Compare(PluginSettings.Instance.ActiveDataFile, dlg.FileName, true) != 0)
{
if (string.IsNullOrEmpty(_lastInsertFromFolder))
{
_lastInsertFromFolder = System.IO.Path.GetDirectoryName(PluginSettings.Instance.ActiveDataFile);
}
dlg.InitialDirectory = _lastInsertFromFolder;
dlg.Filter = "*.gpp|*.gpp";
dlg.FileName = "";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (string.Compare(PluginSettings.Instance.ActiveDataFile, dlg.FileName, true) != 0)
{
_selectedInsertFromFilename = dlg.FileName;
result = true;
}
}
}
}
return result;
}
示例15: OnClickFindBtn2
private void OnClickFindBtn2(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
ofd.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
textBox2.Text = ofd.SafeFileName;
try
{
System.IO.StreamReader sr = new System.IO.StreamReader(ofd.OpenFile());
string content = sr.ReadToEnd();
sr.Close();
selectTextBeforeValue.Text = content;
content = System.Text.RegularExpressions.Regex.Replace(content, "a", "QQQ");
System.IO.StreamWriter writer = new System.IO.StreamWriter(ofd.FileName);
writer.Write(content);
writer.Close();
sr = new System.IO.StreamReader(ofd.OpenFile());
content = sr.ReadToEnd();
sr.Close();
selectTextAfterValue.Text = content;
}
catch(Exception ex)
{
Console.WriteLine("=-=-=-=Exception : " + ex);
}
}
}