Solved

C# & VS2010 Ultimate - Move to another class method and access this method in class form1.cs

Posted on 2012-03-18
7
476 Views
Last Modified: 2012-03-22
Hi everyone.

How to move a method from the Form1 class to another and use this method in Form1?
Thank you,
ocaccy

        private void compare10minutes()
        {
            label_message.ForeColor = Color.Magenta;
            label_message.Text = "Checking if A and A+9 in 10 minutes XXXXX ";
            label4.ForeColor = Color.Magenta;
            label4.Text = label_message.Text;

            timer_keisokukakunin.Enabled = true;
            TimeSpan ts = TargetDateTime.Subtract(DateTime.Now);
            if (ts.TotalMilliseconds > 0)
            {
                label53.Text = int_label_contador.ToString();
                IncrementaContador();
                int i = int_label_contator;

                label1AAA.Text = "-" + ts.Minutes.ToString() + ":" + ts.Seconds.ToString("00");
                label_message.ForeColor = Color.OrangeRed;
                label_message.Text = "Compare A and A+9 in 10 minutes ";
                label4.ForeColor = Color.OrangeRed;
                label4.Text = label_message.Text;

                #region Put de datas in array L_HM_x_yymm
                a_i_delta1[i, 0] = Convert.ToInt32(L_HM_1_2mm.Text);
                a_i_delta1[i, 1] = Convert.ToInt32(L_HM_1_7mm.Text);
                a_i_delta1[i, 2] = Convert.ToInt32(L_HM_1_10mm.Text);

                a_i_delta1[i, 3] = Convert.ToInt32(L_HM_2_2mm.Text);
                a_i_delta1[i, 4] = Convert.ToInt32(L_HM_2_7mm.Text);
                a_i_delta1[i, 5] = Convert.ToInt32(L_HM_2_10mm.Text);

                a_i_delta1[i, 6] = Convert.ToInt32(L_HM_3_2mm.Text);
                a_i_delta1[i, 7] = Convert.ToInt32(L_HM_3_7mm.Text);
                a_i_delta1[i, 8] = Convert.ToInt32(L_HM_3_10mm.Text);

                a_i_delta1[i, 9] = Convert.ToInt32(L_HM_4_2mm.Text);
                a_i_delta1[i, 10] = Convert.ToInt32(L_HM_4_7mm.Text);
                a_i_delta1[i, 11] = Convert.ToInt32(L_HM_4_10mm.Text);

                a_i_delta1[i, 12] = Convert.ToInt32(L_HM_5_2mm.Text);
                a_i_delta1[i, 13] = Convert.ToInt32(L_HM_5_7mm.Text);
                a_i_delta1[i, 14] = Convert.ToInt32(L_HM_5_10mm.Text);

                a_i_delta1[i, 15] = Convert.ToInt32(L_HM_6_2mm.Text);
                a_i_delta1[i, 16] = Convert.ToInt32(L_HM_6_7mm.Text);
                a_i_delta1[i, 17] = Convert.ToInt32(L_HM_6_10mm.Text);
                #endregion

                #region Put the data in listBox
                listBox_k1_2m.Items.Add(a_i_delta1[i, 0]);
                listBox_k1_7m.Items.Add(a_i_delta1[i, 1]);
                listBox_k1_10m.Items.Add(a_i_delta1[i, 2]);
                listBox_k2_2m.Items.Add(a_i_delta1[i, 3]);
                listBox_k2_7m.Items.Add(a_i_delta1[i, 4]);
                listBox_k2_10m.Items.Add(a_i_delta1[i,5]);
                listBox_k3_2m.Items.Add(a_i_delta1[i, 6]);
                listBox_k3_7m.Items.Add(a_i_delta1[i, 7]);
                listBox_k3_10m.Items.Add(a_i_delta1[i, 8]);
                listBox_k4_2m.Items.Add(a_i_delta1[i, 9]);
                listBox_k4_7m.Items.Add(a_i_delta1[i, 10]);
                listBox_k4_10m.Items.Add(a_i_delta1[i, 11]);
                listBox_k5_2m.Items.Add(a_i_delta1[i, 12]);
                listBox_k5_7m.Items.Add(a_i_delta1[i, 13]);
                listBox_k5_10m.Items.Add(a_i_delta1[i, 14]);
                listBox_k6_2m.Items.Add(a_i_delta1[i, 15]);
                listBox_k6_7m.Items.Add(a_i_delta1[i, 16]);
                listBox_k6_10m.Items.Add(a_i_delta1[i, 17]);

                listBox_k1_2m.SelectedIndex = listBox_k1_2m.Items.Count -1; 
                listBox_k1_2m.SelectedIndex = -1;

                listBox_k1_7m.SelectedIndex = listBox_k1_7m.Items.Count - 1; 
                listBox_k1_7m.SelectedIndex = -1;

                listBox_k1_10m.SelectedIndex = listBox_k1_10m.Items.Count - 1; 
                listBox_k1_10m.SelectedIndex = -1;

                listBox_k2_2m.SelectedIndex = listBox_k2_2m.Items.Count - 1; 
                listBox_k2_2m.SelectedIndex = -1;

                listBox_k2_7m.SelectedIndex = listBox_k2_7m.Items.Count - 1;
                listBox_k2_7m.SelectedIndex = -1;

                listBox_k2_10m.SelectedIndex = listBox_k2_10m.Items.Count - 1;
                listBox_k2_10m.SelectedIndex = -1;

                listBox_k3_2m.SelectedIndex = listBox_k3_2m.Items.Count - 1;
                listBox_k3_2m.SelectedIndex = -1;

                listBox_k3_7m.SelectedIndex = listBox_k3_7m.Items.Count - 1;               
                listBox_k3_7m.SelectedIndex = -1;

                listBox_k3_10m.SelectedIndex = listBox_k3_10m.Items.Count - 1;                
                listBox_k3_10m.SelectedIndex = -1;

                listBox_k4_2m.SelectedIndex = listBox_k4_2m.Items.Count - 1;                
                listBox_k4_2m.SelectedIndex = -1;

                listBox_k4_7m.SelectedIndex = listBox_k4_7m.Items.Count - 1;
                listBox_k4_7m.SelectedIndex = -1;

                listBox_k4_10m.SelectedIndex = listBox_k4_10m.Items.Count - 1;
                listBox_k4_10m.SelectedIndex = -1;

                listBox_k5_2m.SelectedIndex = listBox_k5_2m.Items.Count - 1;
                listBox_k5_2m.SelectedIndex = -1;

                listBox_k5_7m.SelectedIndex = listBox_k5_7m.Items.Count - 1;
                listBox_k5_7m.SelectedIndex = -1;

                listBox_k5_10m.SelectedIndex = listBox_k5_10m.Items.Count - 1;
                listBox_k5_10m.SelectedIndex = -1;

                listBox_k6_2m.SelectedIndex = listBox_k6_2m.Items.Count - 1;
                listBox_k6_2m.SelectedIndex = -1;

                listBox_k6_7m.SelectedIndex = listBox_k6_7m.Items.Count - 1;
                listBox_k6_7m.SelectedIndex = -1;

                listBox_k6_10m.SelectedIndex = listBox_k6_10m.Items.Count - 1;
                listBox_k6_10m.SelectedIndex = -1;
                               
                #endregion

                #region DELTA 1
                Func<double, double, bool> PlusMinusDelta = (a, b) => a >= b * (1 - delta) && a <= b * (1 + delta);
                label_i.Text = int_label_contador.ToString();
                if (i >= 9)
                {
                    if (((PlusMinusDelta.Invoke(a_i_delta1[i, 0], a_i_delta1[i - 9, 0]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 1], a_i_delta1[i - 9, 1]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 2], a_i_delta1[i - 9, 2]).ToString()) == "True") &&
                        
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 3], a_i_delta1[i - 9, 3]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 4], a_i_delta1[i - 9, 4]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 5], a_i_delta1[i - 9, 5]).ToString()) == "True") &&
                        
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 6], a_i_delta1[i - 9, 6]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 7], a_i_delta1[i - 9, 7]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 8], a_i_delta1[i - 9, 8]).ToString()) == "True") &&

                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 9], a_i_delta1[i - 9, 9]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 10], a_i_delta1[i - 9, 10]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 11], a_i_delta1[i - 9, 11]).ToString()) == "True") &&

                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 12], a_i_delta1[i - 9, 12]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 13], a_i_delta1[i - 9, 13]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 14], a_i_delta1[i - 9, 14]).ToString()) == "True") &&

                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 15], a_i_delta1[i - 9, 15]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 16], a_i_delta1[i - 9, 16]).ToString()) == "True") &&
                        ((PlusMinusDelta.Invoke(a_i_delta1[i, 17], a_i_delta1[i - 9, 17]).ToString()) == "True"))
                    {
                        #region Put the datas the values of A+9 in the labels
                        ks1_02mm_01x.Text = a_i_delta1[i, 0].ToString();
                        ks1_07mm_01x.Text = a_i_delta1[i, 1].ToString();
                        ks1_10mm_01x.Text = a_i_delta1[i, 2].ToString();

                        ks2_02mm_01x.Text = a_i_delta1[i, 3].ToString();
                        ks2_07mm_01x.Text = a_i_delta1[i, 4].ToString();
                        ks2_10mm_01x.Text = a_i_delta1[i, 5].ToString();

                        ks3_02mm_01x.Text = a_i_delta1[i, 6].ToString();
                        ks3_07mm_01x.Text = a_i_delta1[i, 7].ToString();
                        ks3_10mm_01x.Text = a_i_delta1[i, 8].ToString();

                        ks4_02mm_01x.Text = a_i_delta1[i, 9].ToString();
                        ks4_07mm_01x.Text = a_i_delta1[i, 10].ToString();
                        ks4_10mm_01x.Text = a_i_delta1[i, 11].ToString();

                        ks5_02mm_01x.Text = a_i_delta1[i, 12].ToString();
                        ks5_07mm_01x.Text = a_i_delta1[i, 13].ToString();
                        ks5_10mm_01x.Text = a_i_delta1[i, 14].ToString();

                        ks6_02mm_01x.Text = a_i_delta1[i, 15].ToString();
                        ks6_07mm_01x.Text = a_i_delta1[i, 16].ToString();
                        ks6_10mm_01x.Text = a_i_delta1[i, 17].ToString();
                        #endregion

                        #region Put the data in labels 
                        ks1_02mm_02x.Text = a_i_delta1[i - 9, 0].ToString();
                        ks1_07mm_02x.Text = a_i_delta1[i - 9, 1].ToString();
                        ks1_10mm_02x.Text = a_i_delta1[i - 9, 2].ToString();

                        ks2_02mm_02x.Text = a_i_delta1[i - 9, 3].ToString();
                        ks2_07mm_02x.Text = a_i_delta1[i - 9, 4].ToString();
                        ks2_10mm_02x.Text = a_i_delta1[i - 9, 5].ToString();

                        ks3_02mm_02x.Text = a_i_delta1[i - 9, 6].ToString();
                        ks3_07mm_02x.Text = a_i_delta1[i - 9, 7].ToString();
                        ks3_10mm_02x.Text = a_i_delta1[i - 9, 8].ToString();

                        ks4_02mm_02x.Text = a_i_delta1[i - 9, 9].ToString();
                        ks4_07mm_02x.Text = a_i_delta1[i - 9, 10].ToString();
                        ks4_10mm_02x.Text = a_i_delta1[i - 9, 11].ToString();

                        ks5_02mm_02x.Text = a_i_delta1[i - 9, 12].ToString();
                        ks5_07mm_02x.Text = a_i_delta1[i - 9, 13].ToString();
                        ks5_10mm_02x.Text = a_i_delta1[i - 9, 14].ToString();

                        ks6_02mm_02x.Text = a_i_delta1[i - 9, 15].ToString();
                        ks6_07mm_02x.Text = a_i_delta1[i - 9, 16].ToString();
                        ks6_10mm_02x.Text = a_i_delta1[i - 9, 17].ToString();
                        #endregion
                        
						// Estabilized 
                        label_message.ForeColor = Color.Navy;
                        label_message.Text = "Ok DELTA1 Estabilizado em ± " + (delta * 100) +" % do A+9";
                        label4.ForeColor = Color.Navy;
                        label4.Text = label_message.Text;

                        #region DELTA 1 Average
                        double d_Average_Delta1_02mm = (a_i_delta1[i, 0] + a_i_delta1[i, 3] + a_i_delta1[i, 6] + a_i_delta1[i, 9] + a_i_delta1[i, 12] + a_i_delta1[i, 15]) / 6;
                        double d_Average_Delta1_07mm = (a_i_delta1[i, 1] + a_i_delta1[i, 4] + a_i_delta1[i, 7] + a_i_delta1[i, 10] + a_i_delta1[i, 13] + a_i_delta1[i, 16]) / 6;
                        double d_Average_Delta1_10mm = (a_i_delta1[i, 2] + a_i_delta1[i, 5] + a_i_delta1[i, 8] + a_i_delta1[i, 11] + a_i_delta1[i, 14] + a_i_delta1[i, 17]) / 6;
                        #endregion

                        label56.Text = d_Average_Delta1_02mm.ToString(); label57.Text = d_Average_Delta1_07mm.ToString(); label71.Text = d_Average_Delta1_10mm.ToString();
                        L_Av_2mm.Text = d_Average_Delta1_02mm.ToString(); L_Av_7mm.Text = d_Average_Delta1_07mm.ToString(); L_Av_10mm.Text = d_Average_Delta1_10mm.ToString();

                        #region DELTA 2
                        Func<double, double, bool> PlusMinusDelta2 = (a, b) => a >= b * (1 - delta2) && a <= b * (1 + delta2);
                        if (((PlusMinusDelta2.Invoke(a_i_delta1[i, 0], d_Average_Delta1_02mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 3], d_Average_Delta1_02mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 6], d_Average_Delta1_02mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 9], d_Average_Delta1_02mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 12], d_Average_Delta1_02mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 15], d_Average_Delta1_02mm).ToString()) == "True") &&

                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 1], d_Average_Delta1_07mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 4], d_Average_Delta1_07mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 7], d_Average_Delta1_07mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 10], d_Average_Delta1_07mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 13], d_Average_Delta1_07mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 16], d_Average_Delta1_07mm).ToString()) == "True") &&

                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 2], d_Average_Delta1_10mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 5], d_Average_Delta1_10mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 8], d_Average_Delta1_10mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 11], d_Average_Delta1_10mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 14], d_Average_Delta1_10mm).ToString()) == "True") &&
                            ((PlusMinusDelta2.Invoke(a_i_delta1[i, 17], d_Average_Delta1_10mm).ToString()) == "True"))
                        {
                            adjustOK();

                            L_HK_1_2mm.Text = (d_Average_Delta1_02mm / a_i_delta1[i, 0]).ToString("0.00");
                            L_HK_2_2mm.Text = (d_Average_Delta1_02mm / a_i_delta1[i, 3]).ToString("0.00");
                            L_HK_3_2mm.Text = (d_Average_Delta1_02mm / a_i_delta1[i, 6]).ToString("0.00");
                            L_HK_4_2mm.Text = (d_Average_Delta1_02mm / a_i_delta1[i, 9]).ToString("0.00");
                            L_HK_5_2mm.Text = (d_Average_Delta1_02mm / a_i_delta1[i, 12]).ToString("0.00");
                            L_HK_6_2mm.Text = (d_Average_Delta1_02mm / a_i_delta1[i, 15]).ToString("0.00");

                            L_HK_1_7mm.Text = (d_Average_Delta1_07mm / a_i_delta1[i, 1]).ToString("0.00");
                            L_HK_2_7mm.Text = (d_Average_Delta1_07mm / a_i_delta1[i, 4]).ToString("0.00");
                            L_HK_3_7mm.Text = (d_Average_Delta1_07mm / a_i_delta1[i, 7]).ToString("0.00");
                            L_HK_4_7mm.Text = (d_Average_Delta1_07mm / a_i_delta1[i, 10]).ToString("0.00");
                            L_HK_5_7mm.Text = (d_Average_Delta1_07mm / a_i_delta1[i, 13]).ToString("0.00");
                            L_HK_6_7mm.Text = (d_Average_Delta1_07mm / a_i_delta1[i, 16]).ToString("0.00");

                            L_HK_1_10mm.Text = (d_Average_Delta1_10mm / a_i_delta1[i, 2]).ToString("0.00");
                            L_HK_2_10mm.Text = (d_Average_Delta1_10mm / a_i_delta1[i, 5]).ToString("0.00");
                            L_HK_3_10mm.Text = (d_Average_Delta1_10mm / a_i_delta1[i, 8]).ToString("0.00");
                            L_HK_4_10mm.Text = (d_Average_Delta1_10mm / a_i_delta1[i, 11]).ToString("0.00");
                            L_HK_5_10mm.Text = (d_Average_Delta1_10mm / a_i_delta1[i, 14]).ToString("0.00");
                            L_HK_6_10mm.Text = (d_Average_Delta1_10mm / a_i_delta1[i, 17]).ToString("0.00");

                            PercAveRealtime();
                            biryushirinku();
                        }
                        else
                        {
                            //compare 10 minutes();
                        }
                        #endregion
                    }
                    else
                    {
                    }
                }
                #endregion
            }
            else
            {
                #region End the time.
                timer_01.Enabled = false;
                timer_02.Enabled = false;
                timer_03.Enabled = false;
                timer_04.Enabled = false;
                timer_05.Enabled = false;
                timer_06.Enabled = false;
                timer_10.Enabled = false;
                free1.Enabled = false;
                free2.Enabled = false;
                free3.Enabled = false;
                free4.Enabled = false;
                free5.Enabled = false;
                free6.Enabled = false;
                timer_keisokukakunin.Enabled = false;

                label_message.ForeColor = Color.Red;
                label_message.Text = "End, the time! Check the sensor.";
                label4.ForeColor = Color.Red;
                label4.Text = label_message.Text;

                label1AAA.Text = "Time's Up!";
                timer1.Stop();
                voltaBTkakunin();
                #endregion
            }
        }

Open in new window

0
Comment
Question by:ocaccy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 100 total points
ID: 37736501
public class MyOtherClass
{
        public void compare10minutes()
        {
                     ...
        }
}

on your form:
MyOtherClass myOtherClass = new MyOtherClass();
myOtherClass.compare10minutes();
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 200 total points
ID: 37736508
YOu can do it by passing a reference to the Form1 obejct into the function:

public class MyOtherClass
{
        public void compare10minutes( Form1 frm)
        {
frm.label_message.ForeColor = Color.Magenta;
//AND all other objects on Form1 need to be referenced explicitly as well
...
        }
}

Now create an object and pass in the reference to the Form1 object
MyOtherClass myOtherClass = new MyOtherClass();
myOtherClass.compare10minutes(this);
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 200 total points
ID: 37736654
0
Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

 

Author Comment

by:ocaccy
ID: 37741488
Why are these errors?

errorserrors information 1errors information 2
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 200 total points
ID: 37741527
Copy ALL the #includes from the original file with your form1 into the new file with this new class, then try to compile.
That should cure most (all hopefully) of the error messages.
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 200 total points
ID: 37741549
Why Don't you try to use Re-Sharper, It will automatically fix all these issues for you.
Here is a link for trial edition:-
http://www.jetbrains.com/resharper/

Otherwise you need to add the following in class file:-
using System.Windows.Forms;
using System.Drawing;
0
 

Author Closing Comment

by:ocaccy
ID: 37755404
Very good the help they gave to me.
Able to learn many things with this question.
Thank you,
ocaccy.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question