Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6183009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:17:39+00:00 2026-05-24T01:17:39+00:00

I created a Windows Application with a form and few buttons on it. I

  • 0

I created a Windows Application with a form and few buttons on it. I need to fire the button click event automatically some times based on the parameter value passed to the application.

static class SensexPrediction
{
    static void Main(string[] Args)  <---- Modified this so accepting arguments.
    {
       Application.Run(new Sensex_Prediction_Form(Args)); <--- Passing Args to Form.
    }
}

Below is the Code for Sensex_Prediction_Form method.

public Sensex_Prediction_Form(String[] Args)
    {
        InitializeComponent();
        if (Args.Length != 0) //There is atleast one argument.
        {
            this.Invoker = Args[0];  <-----Invoker is the name of the data member of the class.
        }


    }

Now on form load if Invoker == “X” i need to perform button1_Click event code. For that i wrote the following…

private void Sensex_Prediction_Form_Load(object sender, EventArgs e)
    {
      if(Inovker == "x")
        {
          predict_butn.performclick();
        }
    }

But click is not happening automatically even though argument passed is X.

What i couldn’t understand is the button name in the solution explorer is predict_butn but when i click on the button the event code is in a function named button1_click. Is this the reason?
Please help. Thanks.

After the suggestions i separated the event code and actual logic in a separate method named prediction.

private void Sensex_Prediction_Form_Load(object sender, EventArgs e)
    {
        if (Invoker == "Scheduler")
        {
            prediction();
        }

    }

And i initialized the data variable of the class with Scheduler as below..

public string Invoker = "Scheduler";

Even then when i load the form the method is not being invoked.
As suggested i corrected the connection between button name and even method name etc.
thank q

Suprisingly..(for me :-))

if (Invoker == "Scheduler")
        {
            MessageBox.Show("Testing");
            prediction();
            MessageBox.Show("OK");
        }

Testing message is getting executed but after that it just displays the form. so what could be the reason?

Understood the issue..I am getting an exception object reference not set..because i have a line that says

ActiveForm.Text = "Sensex Prediction System ";

At this point form has not been loaded so it can’t set the text.

——> Now the issue is how to call a method automatically after loading the form? because the method will have code that will modify the form while executing.

Got it…using the “shown” event for the form able to do what i wanted. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:17:41+00:00Added an answer on May 24, 2026 at 1:17 am

    Promote the code within button1_click to a method. Then once the form is loaded and if the parameter match your filter, call the method.

    private void Button1_Click(object sender, EventArgs e)
    {
        DoSomething();
    }
    
    private void Sensex_Prediction_Form_Load(object sender, EventArgs e)
    {
        if(Inovker == "X")
        {
            DoSomething();
        }
    }
    
    private void DoSomething()
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using c# .net windows application form. I have created many databases with many
Im using c# .net windows form application. I have many databases created using sql
I have created two forms in my Windows Application. One Form acts as a
I have created a fairly substantial Java GUI application with many form windows where
What am I trying to achieve? I am writing a windows-form based application in
Im using c# .net windows form application. I have created a database which has
I have created a .net 2.0 windows application. This application creates form controls dynamically.
I have created a Windows Form Application using Visual C# 2008 Express Edition with
I have created a windows form application which uses an SQL database. The database
I have created a windows form application: A presentation library with several windows forms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.