1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

myFrm.BackColor

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

  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 :)
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Duplicate of myFrm.BackColor. Thread closed. Please do not create same thread over and over again
     
  3. ShahzadMughal

    ShahzadMughal New Member

    Joined:
    Nov 7, 2008
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Oh no dear that's not duplicate...
    just to show you the section...


    that's my fault I should mention this.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    You could show all here in the following posts.
     
  5. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    doesn't seem to be a problem.

    try repainting the frm after changing the color.
     

Share This Page