C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Global bool variable - newbie to C# Posted by jarid_lawson on 20 Jun 2012 at 3:27 PM
I have worked with SQL for several years, so I am familiar with programming logic. My company has tasked me with creating an interface for one of our databases, and I have had a little over a week to become familiar with C#.

The problem seems like it should be extremely easy to solve, but so far I have not been able to figure it out, nor have I found any web sites that have offered much in the way of answers.

I have an MDI parent form that opens a navigation child form. To ensure that the navigation child form (and all other forms I'll add to this project) are only opened once (if already open bring to front, if not open then open new) I am attempting to use a global bool variable.

I cannot seem to reference the global variable from the navigation form. The global variable references a public static class, and the variable itself is public having been declared on the MDI parent form (this of course is still open while the child form is open).

Copy of live code:
frmBLD_Main - MDI parent
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 BonfireLoanDatabase_User_Interface
{
    public partial class frmBLD_Main : Form
    {
        public static csWindowControls setScreenStatus;
        frmNavigation newMDIChild = new frmNavigation();

        public frmBLD_Main()
        {
            InitializeComponent();
        }

        private void frmBLD_Main_Load(object sender, EventArgs e)
        {
            // Set the Parent Form of the Child window.
            newMDIChild.MdiParent = this;
            // Display the new form.
            newMDIChild.Show();

            setScreenStatus.navScreenStatus = true;
        }

        private void openNavigationScreenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (setScreenStatus.navScreenStatus == true)
            {
                newMDIChild.TopMost = true;
                newMDIChild.Show();
                newMDIChild.BringToFront();
            }
            else if (setScreenStatus.navScreenStatus == false)
            {
                
                // Set the Parent Form of the Child window.
                newMDIChild.MdiParent = this;
                // Display the new form.
                newMDIChild.Show();

                setScreenStatus.navScreenStatus = true;
            }
            
        }
    }
}


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

        private void frmNavigation_Load(object sender, EventArgs e)
        {
            //this.ActiveMdiChild.WindowState = FormWindowState.Maximized;
            webNavUserNotes.Navigate("C:\\Users\\jarid\\Desktop\\Visual Studio Projects\\C# Programs\\BonfireLoanDatabase User Interface\\BonfireLoanDatabase User Interface\\HTML\\UserNotes.html");
        }

        private void frmNavigation_Resize(object sender, EventArgs e)
        {
            //this.ActiveMdiChild.WindowState = FormWindowState.Maximized;
        }

        private void frmNavigation_FormClosing(object sender, FormClosingEventArgs e)
        {
            setScreenStatus.navScreenStatus = false; //This is the line that causes the error
        }
    }
}


csWindowControls - public static class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BonfireLoanDatabase_User_Interface
{
    public static class csWindowControls
    {
        // ============================================
        // Class Variables
        // ============================================
        bool isNavScreenOpen;

        // ============================================
        // Default Constructor
        // ============================================
        public csWindowControls()
        {   
        }

        // ============================================
        // Method
        // ============================================


        // ============================================
        // Read and write properties
        // ============================================
        public bool navScreenStatus
        {
            get { return isNavScreenOpen; }
            set { isNavScreenOpen = value; }
        }

        // ============================================
        // Write only properties
        // ============================================
    }
}

Thread Tree
jarid_lawson Global bool variable - newbie to C# on 20 Jun 2012 at 3:27 PM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.