Hi all,

I've declared a static int variable call Click=0; in the Pay.Designer.cs.
then i just want to get the value of it in a button click of another form.
But it says :
The event 'System.Windows.Forms.Control.Click' can only appear on the left hand side of += or -=
It gives aline under Click

public partial class LostBookEntry : Form
    {
  private void button1_Click(object sender, EventArgs e)
        {
                Pay ppay = new Pay(int.Parse(dataGridView1.Rows[ee.RowIndex].Cells["Fine"].Value.ToString()), "Fine", textBox1.Text);
               
                ppay.Show();
                int i = ppay.[B]Click;[/B]
                if (i==1)
                {
                    Pay pppay = new Pay(int.Parse(dt.Rows[0][0].ToString()), "Lost",
textBox1.Text);
                    pppay.Show();
           
        }
}

this is my Pay.Designer.cs

namespace HD
{
    partial class Pay
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        /// 
        //internal static int click = 0;
        internal System.Int32 Bid = 0;
        internal System.Int32 code = 0;
        internal string mid = null;
        [B]internal static int click = 0;[/B]

        public Pay(int i,string cat,string mid)
      
        public Pay(int i,string s,System.Int32 bid,System.Int32 ccode)
        
        public Pay(string s)
      
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

       
        internal System.Windows.Forms.Label Label5;
        internal System.Windows.Forms.Label Label4;
        internal System.Windows.Forms.TextBox TextBox2;
        internal System.Windows.Forms.Label Label3;
        internal System.Windows.Forms.Button Button2;
        internal System.Windows.Forms.Button Button1;
        internal System.Windows.Forms.Label Label2;
        internal System.Windows.Forms.ComboBox ComboBox1;
        internal System.Windows.Forms.TextBox TextBox1;
        internal System.Windows.Forms.Label Label1;

    }
}

Pls help me.

To reference static fields you need to use the class name not the name of an instance.
e.g. int i = Pay.Click; .
The error you are getting is because ppay.Click refers to the Click event that can only be set.

[Edit] I would also advise against writing you own code in the designer.
Put you code in the Pay.cs and leave Pay.Designer.cs to the design tools.
That way you are certain that you will never loose any of your code when you re-design.

To reference static fields you need to use the class name not the name of an instance.
e.g. int i = Pay.Click; .
The error you are getting is because ppay.Click refers to the Click event that can only be set.

[Edit] I would also advise against writing you own code in the designer.
Put you code in the Pay.cs and leave Pay.Designer.cs to the design tools.
That way you are certain that you will never loose any of your code when you re-design.

oh i understood.
thank you fo your advice.

I would recommend not put that whole line for the int.Parse on one line - unless you can guarantee that the cell value will always parse to an integer. It is bad form, and will make it harder to find errors down the track.

Same for this line... dt.Rows[0][0].ToString() - presumably the first cell contains a 'magic value'. If you wrote this, and left the company, and someone else comes along and changes the text, they could inadvertently creak the application, it's a little brittle. Better to use a contact, such as _TITLE (if that is what you are intending) - that also makes unit testing must easier and readable.

I know that wasn't the question you asked, but I just thought I'd mention it!

You are also being affected by the fact that C# is case-sensitive.

You defined your property as "click" (all lower case). But your code referenced ppay.Click (capitalized). Most likely you can thank auto-complete for that.

I would also suggest that you choose your names more carefully. "click" is an integer, you assign it to "i" and compare it with 1. None of that gives the reader any clue what "click" is. Is it a count? Is it a flag? click's purpose isn't apparent to someone reading your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.