- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
基本上我已经为我的程序制作了一个登录系统,当用户登录时,它会打开 Form1。但我需要 Form1 成为 STA 线程。我在 Form1 中收到此错误:
{"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."} In this code
SaveFileDialog FSave = new SaveFileDialog()
{
Filter = "Executable Files|*.exe",
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
};
if (FSave.ShowDialog() == DialogResult.OK)//im getting the error here
{
// CodeDom compiler code
}
这是我的 Program.cs
using System;
using System.Windows.Forms;
namespace hwid_login_system
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}
}
}
这就是我在表单登录中打开表单 Form1 的方式
private void complete()
{
if (loggedin && hwid)
{
MessageBox.Show("Logged in successfully!");
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
t.Start();
this.Close();
}
else
MessageBox.Show("Something else went wrong..", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
public static void ThreadProc()
{
Application.Run(new Form1());
}
最佳答案
如果您从第二个线程中调用 FSave.ShowDialog(),您将收到此错误。您应该始终从主应用程序线程中打开 Windows 窗体。
考虑调用委托(delegate)来显示您的线程中的对话,而不是直接打开表单。
关于c# - 新窗体上的 STAThread 错误(SaveFileDialog),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18093272/
我当前正在从 URL 读取流。并将其保存为客户端上的文件。我知道 Silverlight 4 不支持 SaveFileDialog 上的默认文件名。 有没有人找到解决方法或某种方法将文件名注入(inj
所以我使用 SaveFileDialog 将文件保存到用户选择的位置。保存发生后,用户可以对保存到的文件和文件夹执行他们想要的操作。 但是,用户无法删除或修改该文件夹...它由应用程序保存在内存中,因
我有一个 SaveFileDialog。 当用户点击确定时,我必须检查是否有相似的文件名。 系统一直在做这样的测试,但是我需要添加一个测试是否有类似名称和编号的文件。 例如,如果用户选择了文件名“a”
经过深思熟虑和 Google 搜索后,我下定决心要创建自己的 SaveFileDialog。 但我不知道从哪里开始,因为我在网上没有看到任何东西,我想知道以前是否有人这样做过,我应该研究什么,或者我应
好的,我这里有这个场景。我将一个 URL 指向用户以允许他们开始下载。下载按钮有一个类似 www.mydomainname/files/abc.mp3 的 navigateURL。所以当用户点击它时,
我在 pictureEdit (Devexpress) 上使用上下文菜单,因此当用户右键单击并选择菜单项时,它应该保存文件。但是当 saveDialog 窗口打开时上下文菜单仍然显示。 如何删除该错误
我正在构建一个需要使用 SaveFileDialog 的应用程序。问题是我想限制用户使用 SaveFileDialog 的某些部分(例如,我不希望他们编辑文件名)。我听说使用 Windows 窗体 S
我正在使用 SaveFileDialog 让用户在可移动驱动器上选择目录和文件名。之后我创建该文件,写入它,然后再次关闭它。 此时文件本身未被锁定(可编辑、可删除),但我无法弹出驱动器,因为 Wind
我使用 SaveFileDialog 选择我想要保存文件的路径。我将 InitialDirectory 设置为某个文件夹,但我想将保存位置限制为该文件夹或该文件夹的子文件夹。这可能吗? SaveFil
我想用 默认文件名 从值 DataGridViewCells 创建 SaveFileDialog 到目前为止我已经尝试过了 private void buttonSave_Click(object s
我想保存一个有两个选项(.Png 或 .Jpeg)的图像,所以我只需要显示具有 Png 和 Jpeg 格式 的文件,就像我们选择保存类型时as All Images 它在对话框中显示所有类型的图像。那
在我的 SaveFileDialog 中,过滤器中有多种类型,但是在查看对话框时,如果我选择一个过滤器来查看目录中该类型的文件,我只能看到第一个和最后一个过滤器的文件。 bool save;
我正在使用 SaveFileDialog.SaveFile。如何将其设置为默认(操作系统)驱动器盘符,并将选项限制为仅显示 .BIN 作为文件扩展名? 我尝试阅读 MSDN 上的文档,但我对此很陌生,
private void button2_Click(object sender, EventArgs e) { SaveFileDialog Sdialog = new Sav
我正在用 C# 编写代码,我想更改 SaveFileDialog 中“保存”和“取消”按钮的默认排列。默认排列是“保存”按钮位于“取消”按钮上方。 我想要的是将“取消”按钮放在“保存”按钮的右侧。 我
我试图从 SaveFileDialog 中获取我的路径,但没有我的文件名,以便创建一个 DirectoryInfo 对象 private void btnBrowseCapture_Click(obj
单击按钮时,我的程序会捕获图表的屏幕截图,标题为 chartMain。代码如下: private void buttonScreenshot_Click(object sender, EventArg
我有保存bin文件的代码,但是用户必须选择文件 Stream myStream; SaveFileDialog saveFileDialog1 = new Save
基本上我有一个创建字节数组的程序(通过 richtextbox 手动输入,我希望能够创建一个新文件并通过 SaveFileDialog() 方法将字节保存在该文件中。 我想出的代码是: byte[]
我们的用户有时会使用不允许删除文件的目录。 (文件系统权限删除 和删除子文件夹和文件 都被拒绝)。我们使用 System.Windows.Forms.SaveFileDialog 来允许用户选择目录并
我是一名优秀的程序员,十分优秀!