前段时间我写了一个具有csv导入/导出功能的silverlight用户控件.这一直很好,直到最近我发现它在一个场景中出错.这可能是由于转向Silverlight 3.
错误:
消息:Silverlight 2中的未处理错误应用程序
代码:4004
类别:ManagedRuntimeError
消息:System.Security.SecurityException:对话框必须是用户启动的.
在
MyControl.OpenImportFileDialog()的System.Windows.Controls.OpenFileDialog.ShowDialog()
处......
代码:
private void BrowseFileButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(lblFileName.Text))
{
if (MessageBox.Show("Are you sure you want to change the Import file?", "Import", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
{
return;
}
}
EnableDisableImportButtons(false);
var fileName = OpenImportFileDialog();
lblFileName.Text = fileName ?? string.Empty;
EnableDisableImportButtons(true);
}
private string OpenImportFileDialog()
{
var dlg = new OpenFileDialog { Filter = "CSV Files (*.csv)|*.csv" };
if (dlg.ShowDialog() ?? false)
{
using (var reader = dlg.File.OpenText())
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用WPF的OpenFileDialog,我正在寻找一种方法来确保它在显示时在父窗口中居中.它似乎缺少可能启用此功能的StartupPosition等明显属性.
有人知道这个秘密吗?
更新:似乎第一次打开它时,它确实出现在父级的中心,但是如果我移动它,它会记住它的位置,并且不会在后续的场景中打开.
如何让我的用户上传照片并设置好图像的图像
- (IBAction)chooseFile:(id)sender {
int i; // Loop counter.
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Enable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:YES];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories …Run Code Online (Sandbox Code Playgroud) 我用C#WPF编程.在MSDN中,它声明OpenFileDialog属于命名空间System.Windows.Controls.但只是使用System.Windows.Controls不允许我使用OpenFileDialog.我必须使用Microsoft.Win32添加以使用OpenFileDialog.
为什么?
我试图打开一个文件来查看内容里面一个纯文本RichTextbox上Button点击.似乎没有什么工作正常.
private void loadFile_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.FileName = "Document";
openFile1.DefaultExt = "*.*";
openFile1.Filter = "All Files|*.*|Rich Text Format|*.rtf|Word Document|*.docx|Word 97-2003 Document|*.doc";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK && openFile1.FileName.Length > 0)
{
//richTextbox1.Document.ContentStart = File.ReadAllText(openFile1.FileName);
}
}
Run Code Online (Sandbox Code Playgroud)
我使用WPF并且LoadFile方法不起作用.我希望能够从中选择一个文件OpenFileDialog并将其作为纯文本加载到RichTextbox.没有看到来自文件格式的添加代码.
我喜欢的行为类似于打开.rtf,选择所有文本,并将结果粘贴到RichTextbox.如何点击按钮才能做到这一点?
基本上,我有一个浏览按钮来打开文件对话框并将图片提取到文本框和图片框中。但是,我希望在用户打开文件对话框之前显示默认图片(如 Facebook 默认个人资料图片)。当用户打开文件对话框,选择一张图片并点击确定后,默认图片将变为选中的图片。如果用户单击取消,则默认图片不会更改。
我的问题:
这是我的以下代码:
private void buttonbrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "image files|*.jpg;*.png;*.gif";
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.Cancel)
return;
pictureBoxPhoto.Image = Image.FromFile(ofd.FileName);
textBoxPhoto.Text = ofd.FileName;
}
Run Code Online (Sandbox Code Playgroud) 我在winforms中提交了文件.它设置为只读.xml文件.
ofd.DefaultExt="xml";
ofd.Filter="XML Files|*.xml";
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时允许上传.htm文件快捷方式.而它根本不应该显示.htm文件.
每当我取消 OpenFileDialog 框时。它给出错误路径为空。我的打开文件对话框
有什么方法可以为 OpenFileDialog 的取消按钮和关闭按钮编写代码
我的代码:
private void button4_Click(object sender, EventArgs e)
{
string s = image_print() + Print_image();
PrintFactory.sendTextToLPT1(s); / sending to serial port
}
private string image_print()
{
OpenFileDialog ofd = new OpenFileDialog();
string path = "";
string full_path = "";
string filename_noext = "";
ofd.InitialDirectory = @"C:\ZTOOLS\FONTS";
ofd.Filter = "GRF files (*.grf)|*.grf";
ofd.FilterIndex = 2;
ofd.RestoreDirectory = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
filename_noext = System.IO.Path.GetFileName(ofd.FileName);
path = Path.GetFullPath(ofd.FileName);
img_path.Text = filename_noext;
//MessageBox.Show(filename_noext, "Filename");
// …Run Code Online (Sandbox Code Playgroud) 我有一个拥有Windows 10的用户,并且说他们的映射驱动器没有专门出现在一台机器上而且只出现在我的程序中.我使用标准的Microsoft.Win32.OpenFileDialog来允许用户浏览到要打开的文件.在这台机器上,他们给我发了一个屏幕截图,其中有一个Windows资源管理器窗口打开,显示映射的驱动器就好了,然后我的程序中的打开对话框根本没有显示它们(同时).真奇怪的是,他们网络上的其他机器没有相同的问题,他们也在我的程序中显示驱动器.
我不确定从哪里开始这个.我用谷歌搜索了它,但没有发现任何东西; 我也在这里搜索过,但没有找到任何东西.有没有人知道是否有一些模糊的设置或可能导致它不显示映射驱动器的东西?
我正在使用 Qt 5.9 打开一个文件对话框,要求用户选择一个图像文件:
QStringList mimeTypeFilters;
const QByteArrayList supportedMimeTypes = QImageReader::supportedMimeTypes();
foreach(const QByteArray& mimeTypeName, supportedMimeTypes) {
mimeTypeFilters.append(mimeTypeName);
}
mimeTypeFilters.sort();
QFileDialog* fileDialog = new QFileDialog(this, "Select image");
fileDialog->setMimeTypeFilters(mimeTypeFilters);
fileDialog->setFileMode(QFileDialog::ExistingFile);
fileDialog->exec();
Run Code Online (Sandbox Code Playgroud)
所有支持的图像格式都作为 MIME 类型过滤器添加到对话框中,效果非常好。但是,我想添加一个额外的过滤器(例如“所有格式”或“所有支持的”),允许用户选择任何受支持格式的图像,因为在选择图像之前选择正确的格式非常繁琐。实现此目的的最优雅的解决方案是什么,而不需要子类化任何涉及的 Qt 类?
openfiledialog ×10
c# ×7
winforms ×3
wpf ×3
c++ ×1
debugging ×1
dialogresult ×1
image ×1
macos ×1
mime-types ×1
objective-c ×1
picturebox ×1
qt ×1
richtextbox ×1
silverlight ×1
windows ×1
windows-10 ×1