0

First of all, I'm new in c#, a newbie. Basically I have 2 forms, one is the "main" form, and the second is the "prompt" form.

  • The "main" form has a groupbox and a button in it, in which the groupbox is not visible by default (visibility = false).
  • When the button in "main" prompt is click, the "prompt" form will show.
  • The "prompt" form has a textbox in it, which the user will type his password in it.
  • If the user click the button in "prompt" form and inputted the correct password in textbox, the groupbox in "main" form will be visible.

Here is my code in my "main" form:

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 User_Interface
{
    public partial class HomePage : Form
    {
        public HomePage()
        {
            InitializeComponent();
        }
        private void sECRETQUESTIONToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SecQuestionPrompt aac = new SecQuestionPrompt();
            aac.Show();
            //this will show my "prompt" form
        }
    }
}

And this is my code in my "prompt" form:

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;
using System.Data.Sql;
using System.Data.SqlClient;

namespace User_Interface
{
    public partial class UserPassPrompt : Form
    {
        public UserPassPrompt()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string emnconnection = "data source = -L-EMN-L-\\SQLExpress; database = buildingmanagement; integrated security = true";
                SqlConnection sqlconn = new SqlConnection(emnconnection);
                SqlCommand sqlcomm = new SqlCommand("select * from tbl_admin where admin_pass = '" + this.textBox1.Text + "' ;", sqlconn);
                SqlDataReader sqlreader;
                sqlconn.Open();
                sqlreader = sqlcomm.ExecuteReader();
                int count = 0;
                while (sqlreader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    //in this part, i don't know how to call or make the groupbox visible...
                    this.Hide();
                    HomePage aaa = new HomePage();
                }
                else
                    MessageBox.Show("Password");
                sqlconn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

to be precise in this part:

//in this part, i don't know how to call or make the groupbox visible...
//Homepage is my "main" form.. and the name of my groupbox is "grpBox_userndpass"
                        this.Hide();
                        HomePage aaa = new HomePage();

Sorry for the long post guys... T_T

xleMnlx
  • 29
  • 6
  • what is the name of grpBox and in which form it is used, in current form or HomePage ? – Mukul Varshney Sep 25 '16 at 04:39
  • Hi, thanks for responding. The name of the groupbox is "grpBox_userndpass", it is in HomePage - my "main" form... – xleMnlx Sep 25 '16 at 04:49
  • See the marked duplicate for detailed information on how to write your two form classes so that they can communicate with each other, such that user input on the prompt form can effect change on the main form. – Peter Duniho Sep 25 '16 at 04:53
  • Use can use the ShowDialog method set DialogResult to DialogResult.OK if your logon passes and then test the return value of the ShowDialog to determine whether to show your groupbox – Mark Hall Sep 25 '16 at 05:11
  • Thanks guys!! the link work for me. – xleMnlx Sep 25 '16 at 05:58

0 Answers0