Code Red > .NET

Align One Form to another

(1/5) > >>

jjs:
I want the lefts and tops to match when loaded, and when main form is moved.

I get the error =
Error   3   The name 'frmInformation' does not exist in the current context   C:\Users\jimbob\Documents\Visual Studio 2005\Projects\MotorThemCS\MotorThemCS\FrmMotorThem.cs   2225   21   MotorThemCS
which applies to the alignforms routine


FrmMotorThem.cs

--- Code: ---private void cmdInformation_Click(object sender, EventArgs e)
        {
            Form frmInformation = FrmInformation.Instance();
            this.AddOwnedForm(frmInformation);
            //frmInformation.Left = this.Left + this.Width;    <<<<<<----- this works
            //frmInformation.Top = this.Top;
            AlignForms();
            frmInformation.Show();
            frmInformation.Activate();
           
        }

        private void cmdOverloads_Click(object sender, EventArgs e)
        {
            Form frmOverload = FrmOverload.Instance();
            this.AddOwnedForm(frmOverload);
            //frmOverload.Left = this.Left + this.Width;
            //frmOverload.Top = this.Top;
            AlignForms();
            frmOverload.Show();
            frmOverload.Activate();
        }
private void FrmMotorThem_Move(object sender, EventArgs e)
        {

            AlignForms();
        }

        private void AlignForms()
        {
           

            if (frmInformation == null || frmOverload == null)
            {
                if (frmInformation != null)
                {
                    frmInformation.Left = this.Left + this.Width;
                    frmInformation.Top = this.Top;
                }

                if (frmOverload != null)
                {
                    frmOverload.Left = this.Left + this.Width;
                    frmOverload.Top = this.Top;
                }
               
            }
            else
            {
                frmOverload.Left = this.Left + this.Width;
                frmOverload.Top = this.Top;
                frmInformation.Left = this.Left + this.Width + frmOverload.Width;
                frmInformation.Top = this.Top;
            }
        }

--- End code ---
FrmInformation.cs (FrmOverload would be the same)

--- Code: ---using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MotorThemCS
{
    public partial class FrmInformation : Form
    {
        //**************
        private static FrmInformation frmInformation = null;
        public static FrmInformation Instance()
        {
            if (frmInformation == null)
            {
                frmInformation = new FrmInformation();
            }
            return frmInformation;
        }

        private FrmInformation()
        //**************
        //public FrmInformation()
        {
            InitializeComponent();
        }

  }
}

--- End code ---

Greg B:

--- Quote from: jjs on November 07, 2008, 02:47:45 PM ---I want the lefts and tops to match when loaded, and when main form is moved.

I get the error =
Error   3   The name 'frmInformation' does not exist in the current context   C:\Users\jimbob\Documents\Visual Studio 2005\Projects\MotorThemCS\MotorThemCS\FrmMotorThem.cs   2225   21   MotorThemCS
which applies to the alignforms routine


FrmMotorThem.cs

--- Code: ---private void cmdInformation_Click(object sender, EventArgs e)
        {
            Form frmInformation = FrmInformation.Instance();   [color=red]<<<<<<<__Should the F in FrmInformation be capitalized???[/color]
            this.AddOwnedForm(frmInformation);
            //frmInformation.Left = this.Left + this.Width;    <<<<<<----- this works
            //frmInformation.Top = this.Top;
            AlignForms();
            frmInformation.Show();
            frmInformation.Activate();
           
        }



--- End code ---


--- End quote ---

jjs:
yes, that part of the code works fine. the form name is with capital F.
the variable name that references the form has lowercase F.

TonyT:

--- Quote from: jjs on November 07, 2008, 03:47:43 PM ---yes, that part of the code works fine. the form name is with capital F.
the variable name that references the form has lowercase F.

--- End quote ---

You should probably consider some basic learning about the
programming language you're trying to use.

While the folks here are good natured and willing to help, the
mistakes in your code clearly indicate that you've skipped some
basics and prerequisites needed to use C# and you seem to be
expecting folks here to fill in the blanks for you.

Unlike LISP (which uses Dynamic Scoping), in C#, local variables
that are declared in a method are not visible from other methods
you call from it.


Mark:

--- Quote from: TonyT on November 08, 2008, 04:45:59 AM ---
--- Quote from: jjs on November 07, 2008, 03:47:43 PM ---yes, that part of the code works fine. the form name is with capital F.
the variable name that references the form has lowercase F.

--- End quote ---

...

While the folks here are good natured and willing to help, the
mistakes in your code clearly indicate that you've skipped some
basics and prerequisites needed to use C# and you seem to be
expecting folks here to fill in the blanks for you.

....


--- End quote ---

Maybe it's more like a helping hand at solving a problem. I really don't think jjs expects anything.

Navigation

[0] Message Index

[#] Next page

Go to full version