Global bool variable - newbie to C# - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Global bool variable - newbie to C#

jarid_lawsonjarid_lawson Posts: 4Member
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
[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 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;
}

}
}
}
[/code]

frmNavigation
[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 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
}
}
}[/code]

csWindowControls - public static class
[code]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
// ============================================
}
}[/code]
Sign In or Register to comment.