-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)
1
  • You seem to be trying to set the BackgroundImage of a control and something goes wrong there. Can you also show the relevant parts of Form1'a code?
    – 41686d6564
    Commented Jul 19, 2020 at 6:05

1 Answer 1

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?).

7
  • 1
    No I'm not usng OnPaint Event and no Third-party tool (I don't like Third-party tools).
    – user13954313
    Commented Jul 19, 2020 at 6:15
  • 1
    @Hello_World: Could you please add the code of Form1 to your question? Because there is a high probability that the exception is passed due to the code in Form1.
    – TheCoder
    Commented Jul 19, 2020 at 6:16
  • 1
    Wait let to do it
    – user13954313
    Commented Jul 19, 2020 at 6:17
  • 1
    @Hello_World: To try this, you can also make a demo form, a new one and then call it instead of Form1. If the error is caused by Form1 then we've got the thief will get stopped and if not then we are free to dig deeper.
    – TheCoder
    Commented Jul 19, 2020 at 6:18
  • 1
    @Hello_World: Can you please check out my last comment? That way you could do the checking work yourself.
    – TheCoder
    Commented Jul 19, 2020 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.