John Smith
John Smith

Reputation: 4516

How do you modify another window's background color?

Suppose that you have a 3rd party application that's just a red window. Is there a straightforward way to change its color once you obtain the window handle?

Upvotes: 2

Views: 1329

Answers (1)

RAS
RAS

Reputation: 3385

The best I could come up with so far is to use Graphics.FillRectangle

Graphics g = Graphics.FromHwnd(handle);
g.FillRectangle(Brushes.Green, new Rectangle(0, 0, 10000, 10000));   

Complete winform working example:

  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (var p in Process.GetProcesses())
            {
                if (p.MainWindowTitle.Contains("Window Name"))
                {
                     IntPtr handle = p.MainWindowHandle;
                    if ((int)handle != 0)
                    {
                        Graphics g = Graphics.FromHwnd(handle);
                        g.FillRectangle(Brushes.Green, new Rectangle(0, 0, 10000, 10000));
                    }

                }
            }
        }
    }  

You also can try obtain window size information by using GetWindowRect as described here: Get A Window's Bounds By Its Handle
to avoid using 10000 for width and height.

Upvotes: 2

Related Questions