myFrm.BackColor

Discussion in 'C#' started by ShahzadMughal, Sep 30, 2009.

Thread Status:
Not open for further replies.
  1. ShahzadMughal

    ShahzadMughal New Member

    Joined:
    Nov 7, 2008
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Following is the code which is not producing expected outout
    Code:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Security.Cryptography;
    
    namespace Form_Paint_event
    {
        public class Form_Paint_event : System.Windows.Forms.Form
        {
            private Button myButton;
            private TextBox myText;
            private Form_Paint_event myFrm;
    
            public Form_Paint_event()
            {
                myButton = new Button();
                myButton.Text = "Refresh";
                myButton.Location = new System.Drawing.Point(64, 32);
                this.myButton.Click += new System.EventHandler(this.myButton_Click);
                myButton.Size = new System.Drawing.Size(150, 50);
    
                myText = new TextBox();
                myText.Location = new System.Drawing.Point(100, 100);
                myText.Size = new System.Drawing.Size(150,150);
                
                Controls.AddRange(new System.Windows.Forms.Control[] { this.myButton, this.myText });
                CenterToScreen();
            }
            private void myButton_Click(object sender, System.EventArgs e)
            {
                myFrm = new Form_Paint_event();
                myFrm.BackColor = System.Drawing.Color.Red; //[COLOR="DarkRed"]this is not working is this correct way to do so, if not then please correct it or at least suggest me[/COLOR]          
                myText.Text = this.Text;           
            }
           
            static void MyPaintHandler(object objSender, PaintEventArgs pea)
            {
                Random rand = new Random();
                Color color = Color.FromArgb(rand.Next(256),
                                             rand.Next(256),
                                             rand.Next(256));
                
                Console.WriteLine("Color code: {0}", color.Name);
    
                Graphics graphics = pea.Graphics;
    
                graphics.Clear(color);
            }
            public static void Main()
            {
                Form_Paint_event form = new Form_Paint_event();
                form.Text = "Paint Event";
                form.Paint += new PaintEventHandler(MyPaintHandler);
                form.StartPosition = FormStartPosition.CenterScreen;
                Application.Run(form);
            }
        }
    }
    
    I have problem in following section

    Code:
    private void myButton_Click(object sender, System.EventArgs e)
            {
                myFrm = new Form_Paint_event();
                myFrm.BackColor = System.Drawing.Color.Red; //[COLOR="DarkRed"]this is not working is this correct way to do so, if not then please correct it or at least suggest me [/COLOR]          
                myText.Text = this.Text;           
            }
    


    Thanks & Regards
    Shahzad :)
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice