0

So I have a Windows Form named Settings.CS

It has nothing.. the code is only this much

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 SteamBot
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();
        }
    }
}

Then I have another CLASS named Bot.CS. What I want to do is, after a specific function, I want the settings form to become visible. In VB it was just Settings.Visible = true

How do I do this in C#? Please help me.

Bone
  • 859
  • 2
  • 9
  • 17
  • Doubtful that this question actually has anything to do with making a form visible. Surely the real problem is using a *type name* where an object reference is required. Settings is a **type**, not an object reference. You cannot use Settings.Visible = true in a C# program. Unlearning the VB.NET syntax can be quite difficult. – Hans Passant Feb 09 '14 at 05:21

3 Answers3

0

Lets assume that Specific Function is a button click

private void Button1_Click(Object sender, EventArgs e ) 
{
   Form1 myForm = new Form1();
   myForm.Show();
}

Replace Form1 with the form name of your settings form !

Magesh Kumaar
  • 1,485
  • 2
  • 10
  • 29
0

Solution 1: if you want to display the Settings Form first time, you need to create an instance variable of that Form and call ShowDialog() method to display it.

Try This:

void SpecificFunction()
{
    //--at the end of MyFunction call settings form

    Settings frmSettings=new Settings();
    frmSettings.ShowDialog();    
}

Solution 2: if you want to display the Settings Form which was hidden before , you need to to follow the below steps make it Visible.

Step 1: identify/obtain the Settings Form by using Application.OpenForms[] Collection.
Step 2: create a new instance variable of a Form by casting the obtained Settings Form in above step.
Step 3: Call the Show() Method on the created instance variable to Show/Display the Settings form.

Try This:

void SpecificFunction()
{
    //--at the end of MyFunction call settings form

    Form frmSettings = (Settings) Application.OpenForms["Settings"];
    frmSettings.Show();    
}
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
0

I just created this new Form which is shown when the button is clicked:

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form f2 = new Form();
            f2.Visible = true;
            //f2.Show(); also works
        }
    }
}

You can also use 'this' if you want to manipulate the instance give it a try

Visionstar
  • 355
  • 2
  • 12