c# - 应该显示哪个表格?
问题描述
我想检查某个文件是否存在,如果文件存在则显示登录表单,否则显示创建新用户表单。
我正在使用 .Net Framework 4.8、WinForms、Visual Studio 2019、C#。
在我的 Program.cs 文件中,我编写了这段代码。
using System;
using System.IO;
using System.Windows.Forms;
namespace newApp
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
string location = Application.StartupPath.ToString() + "\\files\\xyz.txt"; //change file name//
if (File.Exists(location))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Signin());
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new createnewuser());
}
}
}
}
但是,每当我尝试在创建新用户表单中输入一些文本时,它都会给出错误提示 Parameter is not valid
。
错误详情:
System.ArgumentException
HResult=0x80070057
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.get_Flags()
at System.Windows.Forms.ControlPaint.IsImageTransparent(Image backgroundImage)
at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle, Color backColor, Point scrollOffset)
at System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle)
at System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs pevent)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
解决方案
很可能,“Form1”中的代码有问题。
Form1 的 OnPaint 事件(您正在使用它吗?)中可能出现问题。
或者某些第三方工具正在传递无效的参数(你在使用它吗?)。
推荐阅读
- postgresql - 无法删除 Terraform 中包含提供程序的模块实例
- angular - Angular 6 pipe 不渲染材质图标
- json - 使用 JSON 和 AJAX 从 sharepoint 在线列表中获取“个人或组”列值
- asp.net-mvc-4 - 如何在不重定向到 MVC 4 中的新视图的情况下显示来自异常的错误消息
- javascript - 如何从动态加载网站获取数据
- debugging - 在 PhpStorm 中调试测试时是否可以打开控制台窗口?
- php - 从 Woocommerce 3 中的订单商品中获取正确的变化价格
- maven - 向控制器发送 http GET 时发生 404 错误
- git - 如何在 Jenkins 管道中使用 GitHub 提交消息和提交 ID?
- python - 忽略或重置日期时间秒和微秒