首页 > 解决方案 > 应该显示哪个表格?

问题描述

我想检查某个文件是否存在,如果文件存在则显示登录表单,否则显示创建新用户表单。

我正在使用 .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)

标签: c#visual-studiowinformsauthentication

解决方案


很可能,“Form1”中的代码有问题。

Form1 的 OnPaint 事件(您正在使用它吗?)中可能出现问题。

或者某些第三方工具正在传递无效的参数(你在使用它吗?)。


推荐阅读