Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   myFrm.BackColor (http://www.go4expert.com/forums/myfrmbackcolor-t19631/)

ShahzadMughal 30Sep2009 16:25

myFrm.BackColor
 
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; //this is not working is this correct way to do so, if not then please correct it or at least suggest me         
            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; //this is not working is this correct way to do so, if not then please correct it or at least suggest me          
            myText.Text = this.Text;         
        }



Thanks & Regards
Shahzad :)

shabbir 30Sep2009 19:33

Re: myFrm.BackColor
 
Duplicate of myFrm.BackColor. Thread closed. Please do not create same thread over and over again

ShahzadMughal 1Oct2009 08:23

Re: myFrm.BackColor
 
Oh no dear that's not duplicate...
just to show you the section...


that's my fault I should mention this.

shabbir 1Oct2009 16:47

Re: myFrm.BackColor
 
You could show all here in the following posts.

nimesh 2Oct2009 02:48

Re: myFrm.BackColor
 
doesn't seem to be a problem.

try repainting the frm after changing the color.


All times are GMT +5.5. The time now is 22:09.