Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

C# coding modify code to toggle between two objects and iterate thru ten.

Avatar of tconingford
tconingfordFlag for United States of America asked on
Programming Languages-Other.NET ProgrammingC#Microsoft Development
3 Comments1 Solution491 ViewsLast Modified:
Currently toggling between two displays, need to be able to go through ten. The textboxGraphics are 1-10 respectivley on the form now and these 10 display textboxGraphix values need to be able to loop. The full source code is below.

            if (m_strDisplayName == textBoxGraphic2.Text)
                m_strDisplayName = textBoxGraphic1.Text;
            else
                m_strDisplayName = textBoxGraphic2.Text;

Actual 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;
using Microsoft.Win32;

namespace GraphicDriver
{
    public partial class Form1 : Form
    {
        private string m_strDisplayName = "";
        private int MaxWatchdogTimer = 10000;
        private int m_WatchdogTimeRemaining = 0;

        public Form1()
        {
            InitializeComponent();
            timer1.Tick += new EventHandler(timer1_Tick);

            RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Software\Lin and Associates\LA_ADVGraphics", true);
            string strDone = "1";
            try
            {
                strDone = rk.GetValue("MenuTrigger_done").ToString();
            }
            catch
            {
                rk.SetValue("MenuTrigger_done", "1");
            }
            rk.Close();

            buttonStart.Enabled = true;
            buttonStop.Enabled = false;
            buttonInvoke.Enabled = true;
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            labelMessage.Text = "";
            RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Software\Lin and Associates\LA_ADVGraphics", true);
            if (checkBoxDone.Checked)
            {
                if (rk.GetValue("MenuTrigger_done").ToString() == "0")
                {
                    labelMessage.Text = "MenuTrigger_done is 0";
                    rk.Close();
                    return;
                }
            }
            if (m_strDisplayName == textBoxGraphic2.Text)
                m_strDisplayName = textBoxGraphic1.Text;
            else
                m_strDisplayName = textBoxGraphic2.Text;
            //G.g_Tracer.Trace(10, "Writing to registry MenuDisplay: " + sDisplayName);
            rk.SetValue("MenuDisplay", m_strDisplayName);
            //G.g_Tracer.Trace(10, "Writing to registry MenuScreenLocation: " + sWindowName);
            rk.SetValue("MenuScreenLocation", "1");
            string strTrigger = "0";
            try
            {
                strTrigger = rk.GetValue("MenuTrigger").ToString();
                if (strTrigger == "0")
                    strTrigger = "1";
                else
                    strTrigger = "0";
            }
            catch
            {
            }
            //G.g_Tracer.Trace(10, "Writing to registry MenuDisplayInvokeTime: " + DateTime.Now.ToString());
            rk.SetValue("MenuDisplayInvokeTime", DateTime.Now.ToString());
            //G.g_Tracer.Trace(10, "Writing to registry MenuTrigger: " + strTrigger);
            if (checkBoxDone.Checked)
            {
                rk.SetValue("MenuTrigger_done", "0");
            }
            rk.SetValue("MenuTrigger", strTrigger);

            rk.Close();
            labelMessage.Text = "Invoke display " + m_strDisplayName;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Software\Lin and Associates\LA_ADVGraphics", true);
            rk.SetValue("MenuTrigger_done", "1");
            rk.Close();
            timer1.Interval = int.Parse(textBoxTimer.Text);
            timer1.Enabled = true;

            buttonStart.Enabled = false;
            buttonStop.Enabled = true;
            buttonInvoke.Enabled = false;

        }

        private void buttonStop_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            buttonStart.Enabled = true;
            buttonStop.Enabled = false;
            buttonInvoke.Enabled = true;
        }

        private void buttonInvoke_Click(object sender, EventArgs e)
        {
            labelMessage.Text = "";
            RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Software\Lin and Associates\LA_ADVGraphics", true);
            if (checkBoxDone.Checked)
            {
                if (rk.GetValue("MenuTrigger_done").ToString() == "0")
                {
                    labelMessage.Text = "MenuTrigger_done is 0";
                    rk.Close();
                    return;
                }
            }
            if (m_strDisplayName == textBoxGraphic2.Text)
                m_strDisplayName = textBoxGraphic1.Text;
            else
                m_strDisplayName = textBoxGraphic2.Text;
            //G.g_Tracer.Trace(10, "Writing to registry MenuDisplay: " + sDisplayName);
            rk.SetValue("MenuDisplay", m_strDisplayName);
            //G.g_Tracer.Trace(10, "Writing to registry MenuScreenLocation: " + sWindowName);
            rk.SetValue("MenuScreenLocation", "1");
            string strTrigger = "0";
            try
            {
                strTrigger = rk.GetValue("MenuTrigger").ToString();
                if (strTrigger == "0")
                    strTrigger = "1";
                else
                    strTrigger = "0";
            }
            catch
            {
            }
            //G.g_Tracer.Trace(10, "Writing to registry MenuDisplayInvokeTime: " + DateTime.Now.ToString());
            rk.SetValue("MenuDisplayInvokeTime", DateTime.Now.ToString());
            //G.g_Tracer.Trace(10, "Writing to registry MenuTrigger: " + strTrigger);
            if (checkBoxDone.Checked)
            {
                rk.SetValue("MenuTrigger_done", "0");
            }
            rk.SetValue("MenuTrigger", strTrigger);

            rk.Close();
            labelMessage.Text = "Invoke display " + m_strDisplayName;
        }
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert SchuttFlag of Netherlands imageSoftware Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers