7 Replies - 1123 Views - Last Post: 30 October 2015 - 01:57 PM Rate Topic: -----

#1 mohamedgpaly   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 15

Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 08:30 AM

Hello All :)
I Need Help
I have a problem when running a MainForm (1) from login(2) form ( With Button show MainForm ) I have a show More error because The Class SeleniumControl.cs Call MainForm (1) by : Program.MainForm.btnLogin ..... Or Other

Program = startup object

My class Program Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Data;
using System.Drawing;
using System.Text;


namespace MyTools
{
    static class Program
    {
        public static democs democs;
        public static MainForm MainForm;
        public static LoadingForm loadingForm;
        public static gpaly gpaly;
            /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
                           
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
           // MainForm = new MainForm();
            login= new login();

         //Application.Run(MainForm);
          //democs = MainForm.sendOver();

            login= new login();
            Application.Run(login);
                     
        }
    }
}



Login Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MYTools
{
    public partial class login: Form

    {
           public login()
        {
             InitializeComponent();
        this.IsMdiContainer = true; // This will allow the Form #0 to be responsive while other forms are opened.
        }


        private void button1_Click(object sender, EventArgs e)
        {
         
            //MainForm = new MainForm();
          //Application.Run(new MainForm());
            
           

           // Program.MainForm();
         //   var yourObject = new SeleniumControl();
           // yourObject.MainForm();

           // MainForm = new MainForm();
          //  Application.Run(MainForm);
                        
          }

        }

    }





short! when you open the form(1) from login form before him Gets problem I, for example, I need to work Button When Click The Button open MainForm With The Class SeleniumControl.cs ! Or Any Help !

When using

Form = new Form();

in
In Program.cs
The project works successfully, but shows,Problems or problems in different example of what line In My class

if (Program.form.dgGroups.RowCount == 0) await getGrps();


Object reference not set to an instance of an object.
Error : {MYTools.SeleniumControl} .......

did not sleep and I feel very tired because of this problem
Please Help Me
Thanks All :)

Is This A Good Question/Topic? 0
  • +

Replies To: Help c# SeleniumControl.cs! (startup object ) With Form C#

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 09:18 AM

A few things:

1 - Why are you writing this in end-of-life WinForms? IS this for a Win98 machine? you might want to move forward 15 years into WPF.
2 - "Object reference not set to the instance of an object" -
See tutorial "What does this error mean?"

3 - Getting two old-school forms to talk to each other is mentioned in the FAQ below:
4 - Just because you see the log-in before form1 doesn't mean it should logically work that way. It means that the log-in form because the primary form of the program. It would be better to make the form1 BUT NOT SHOW IT. form1 then is the main form of the program. have it show the log-in form before it shows itself. If the log-in is successful then the log-in form can come down and form1 can show itself.

Mostly though you just need to move forward by a decade both in the GUI technology and the logic behind your design. If this is from/for school that would explain why it doesn't resemble anything we would do in the real world so don't worry. In school you have to do things they way they want.





tlhIn`toq's FAQ list - Updated Oct 2015


Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.
Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute, check the condition of each of variable's run-time value, and watch the logic unfold right before your eyes.
Visualizing what your code does will let you see why it behaves the way it does.
It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.

In addition to FAQ 2 in the list below, also check my signature block for a link on how to look at your variables' values at run-time.

TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2

Why are you still building in WinForms?

Quote

"old 1990's WinForms"? i just use visual studio 2015 and started up with a windows form. didn't know there was an option for a newer winform?


WinForms is OLD. Virtually 'legacy' and to many of us nearly considered end-of-life. There are still placing building new projects in it, but I wouldn't work for anyplace that wanted to hold me back by two decades. There are probably tens of thousands of legacy WinForms applications in use in countless companies. "If it ain't broke, don't fix it." in other words: If there isn't a financial gain to be made in re-writing them right now why invest the time and money?

But with decades of WinForms comes developers with decades more experience than you'll have and you have no way to compete with them. Let the legacy developer maintain the legacy applications. Many of them are too stuck in their ways to move forward to WPF. Which is why if you look at job boards, what companies are hiring for and have been looking for, for the last several years its: WPF/MVVM.

So if I were you I would just jump right to WPF. Don't worry about WinForms unless you have a deliberate need for it down the line. Otherwise you spend 10,000 hours getting good at WinForms only to find you need to spend another 7,500 hours bringing your skillset forward several years into WPF - And at the same time break all the bad habits you learned in WinForms.

If some company hires you for WPF development, but would also like it if you could maintain some legacy applications THEN learn WinForms; and take your good habits from WPF with you.


FAQ (Frequently Asked Questions - Updated Sep 2015
Spoiler



Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 23,989
  • Joined: 05-May 12

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 09:36 AM

Even more interesting is that the OP is using WinForms, but also using the latest .NET features like async and await, so they can't claim that they are constrained to using only the older versions of the framework.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 09:44 AM

and naming such as "button1".

Clearly a case of copy/paste development.
Was This Post Helpful? 0
  • +
  • -

#5 mohamedgpaly   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 15

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 11:16 AM

Thank you very much for this wonderful information and interaction
Thank professor Skydiver
Thank professor tlhIn`toq

I will follow tips

But now the project is very important and in need to actually help with that
It may not be clarified exactly the problem

But I've Capture desktop video until the problem appear clearly and I hope you can watch the video and find a solution if possible
And apologized for any inconvenience
I learn From You , & dreamincode

I apologize if there are errors language because I still learn English

Sorry video link: http://youtu.be/3l1DCravmGg

This post has been edited by tlhIn`toq: 30 October 2015 - 11:49 AM

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 11:52 AM

Quote

I will follow tips

But now the project is very important and in need to actually help with that


It sounds like you're asking us to do your debugging for you, and to re-write your code for you.
We're not here to do that. We've pointed you at tutorials so you can learn the skills to fix your code.
At the very least you need to try. Show us you've made an effort by actually making an effort. Then show us your updated code.
Was This Post Helpful? 0
  • +
  • -

#7 mohamedgpaly   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 15

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 12:00 PM

Thanks ProfessortlhIn`toq
I try and look for five days in this problem only without stop :( Already I still look now and I'm still trying to certainly ............................... I am here to learn more than they get the solutions As soon find a solution and adjust the things I'll show you the updated code and the developer fully until I learn more
... Loved dreamincode :)
Was This Post Helpful? 0
  • +
  • -

#8 mohamedgpaly   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-October 15

Re: Help c# SeleniumControl.cs! (startup object ) With Form C#

Posted 30 October 2015 - 01:57 PM

Hello after various experiments and reached for a solution
Thank you :) encouraging
I've got the solution was simple and very :)
It is

private void login2_Load(object sender, EventArgs e)
{
}
MainForm = new MainForm();
MainForm frmMain = new MainForm();
Program.MainForm.ShowDialog();
Application.Run(MainForm);
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1