Which Form should be shown?

-2

I want to check whether a certain file is present or not, if the file is present then show Login Form else show Create a new user form.

I'm using .Net Framework 4.8, WinForms, Visual Studio 2019, C#.

In my Program.cs file I have written this code.

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());
            }
        }
    }
}

But whenever I try to enter a some text in Create a new user form it gives error saying Parameter is not valid.

Error Image

Error details:

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-studio
winforms
authentication
asked on Stack Overflow Jul 19, 2020 by (unknown user) • edited Jul 20, 2020 by Cody Gray

1 Answer

1

Most probably, there is something wrong with the code in 'Form1'.

Something is going wrong maybe in the OnPaint event(are you using it?) of Form1.

Or some third party tool is passing invalid arguments(are you using that?).

answered on Stack Overflow Jul 19, 2020 by TheCoder • edited Jul 19, 2020 by TheCoder

User contributions licensed under CC BY-SA 3.0