Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:30:49+00:00 2026-06-10T06:30:49+00:00

I need a help on this, There are 3 picture boxes, red should grow

  • 0

I need a help on this,

There are 3 picture boxes, red should grow its Width to left, green should grow its height to top blue’s width to right

also if one reaches the top border / any text boxes it should give an error / stop execution

I need to add more picture boxes in future and if two of them collides it should give an error / stop execution. I have managed to code them to go up, however unable to get other functions working. Please some one help me with this.

OR

https://www.box.com/s/d0d302c6c266f52e0abf

Thank you.
RR

My code below,

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ThreadwithmovingPicbxmoving
{
    public partial class Form1 : Form
    {
        Thread t1;
        Thread t2;
        Thread t3;

        delegate void CTMethod(int val);
        delegate void CTFinish(string t);
        Queue<string> order = new Queue<string>();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int r = int.Parse(textBox1.Text);
            int y = int.Parse(textBox2.Text);
            int g = int.Parse(textBox3.Text);

            t1 = new Thread(new ParameterizedThreadStart(loopred));
            t2 = new Thread(new ParameterizedThreadStart(loopyel));
            t3 = new Thread(new ParameterizedThreadStart(loopGree));

            t1.Start(r);
            t2.Start(y);
            t3.Start(g);

        }
        private void updateRed(int val)
        {
            pictureBox1.Height = val;
            pictureBox1.Refresh();
        }

        private void updateyell(int val)
        {
            pictureBox2.Height = val;
            pictureBox2.Refresh();
        }
        private void updategree(int val)
        {
            pictureBox3.Height = val;
            pictureBox3.Refresh();

        }

        private void loopred(object o)
        {
            int c = (int)o;
            CTMethod ctred = new CTMethod(updateRed);
            if (c < 500)
            {
                for (int i = 0; i < c; i++)
                {
                    this.Invoke(ctred, i);
                    Thread.Sleep(20);
                }
            }

            else
            {
                MessageBox.Show("Enter a value less than 500 for Red Box!!!");
            }
            CTFinish CTFin = new CTFinish(Threadfinish);
            this.Invoke(CTFin, "Red");
        }

        private void loopyel(object o)
        {
            int c = (int)o;
            CTMethod ctyell = new CTMethod(updateyell);
            if (c < 500)
            {
                for (int i = 0; i < c; i++)
                {
                    this.Invoke(ctyell, i);
                    Thread.Sleep(20);
                }
            }
            else
            {
                MessageBox.Show("Enter a valure less than 500 for Yellow Box!!!");
            }
            CTFinish CTFin = new CTFinish(Threadfinish);
            this.Invoke(CTFin, "Yell");
        }


        private void loopGree(object o)
        {
            int c = (int)o;
            CTMethod ctgree = new CTMethod(updategree);
            if (c < 500)
            {
                for (int i = 0; i < c; i++)
                {
                    this.Invoke(ctgree, i);
                    Thread.Sleep(20);
                }
            }
            else
            {
                MessageBox.Show("Enter a valure less than 500 for Green Box!!!");
            }
            CTFinish CTfin = new CTFinish(Threadfinish);
            this.Invoke(CTfin, "Green");

        }

        private void Threadfinish(string t)
        {
            order.Enqueue(t);
            if (order.Count == 3)
            {

                MessageBox.Show("Threads finished in this order: \n" + "1." + order.Dequeue() + "\n" + "2." + order.Dequeue()
                    + "\n" + "3." + order.Dequeue() + "\n", "finished");

            }
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:30:51+00:00Added an answer on June 10, 2026 at 6:30 am

    Try It. Its All Fine with three PictureBoxes

    Create New Widows Application with name help and then replace Form1.cs code with Following

    Run It. It also includes values from TextBoxes

    using System;
    using System.Drawing;
    using System.Threading;
    using System.Windows.Forms;
    using System.Collections.Generic;
    
    
    namespace help
    {
    public partial class Form1 : Form
    {
    
        Thread t1;
        Thread t2;
        Thread t3;
    
        delegate void CTMethod(int val);
        delegate void CTFinish(string t);
        Queue<string> order = new Queue<string>();
    
    
        #region Variables of Designer File
        private System.Windows.Forms.PictureBox pictureBox1;
        private System.Windows.Forms.PictureBox pictureBox2;
        private System.Windows.Forms.PictureBox pictureBox3;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.Button button1;
        #endregion
    
    
        public Form1()
        {
            #region Designer Code I have Cut and Pasted Here
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.pictureBox2 = new System.Windows.Forms.PictureBox();
            this.pictureBox3 = new System.Windows.Forms.PictureBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
            this.SuspendLayout();
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.pictureBox3);
            this.Controls.Add(this.pictureBox2);
            this.Controls.Add(this.pictureBox1);
    
            // 
            // pictureBox1
            // 
            this.pictureBox1.BackColor = System.Drawing.Color.Red;
            this.pictureBox1.Location = new System.Drawing.Point(161, 268);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(100, 50);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            // 
            // pictureBox2
            // 
            this.pictureBox2.BackColor = System.Drawing.Color.Green;
            this.pictureBox2.Location = new System.Drawing.Point(383, 268);
            this.pictureBox2.Name = "pictureBox2";
            this.pictureBox2.Size = new System.Drawing.Size(100, 50);
            this.pictureBox2.TabIndex = 1;
            this.pictureBox2.TabStop = false;
            // 
            // pictureBox3
            // 
            this.pictureBox3.BackColor = System.Drawing.Color.Blue;
            this.pictureBox3.Location = new System.Drawing.Point(605, 268);
            this.pictureBox3.Name = "pictureBox3";
            this.pictureBox3.Size = new System.Drawing.Size(100, 50);
            this.pictureBox3.TabIndex = 2;
            this.pictureBox3.TabStop = false;
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(161, 26);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 20);
            this.textBox1.TabIndex = 3;
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(383, 25);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(100, 20);
            this.textBox2.TabIndex = 4;
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(605, 26);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(100, 20);
            this.textBox3.TabIndex = 5;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(37, 23);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 6;
            this.button1.Text = "Go";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            this.PerformLayout();
            #endregion
    
            InitializeComponent();
    
            textBox1.Text = "490";
            textBox2.Text = "490";
            textBox3.Text = "490";
    
            textBox1.Leave += new EventHandler(textBox1_Leave);
            textBox2.Leave += new EventHandler(textBox2_Leave);
            textBox3.Leave += new EventHandler(textBox3_Leave);
        }
    
        // To input Only Valid int values in TextBoxes
        #region TextBoxes Input Validation
        int t1Val = 490;
        int t2Val = 490;
        int t3Val = 490;
        void textBox1_Leave(object sender, EventArgs e)
        {
            try
            {
                int t1Val = Convert.ToInt32(textBox1.Text);
            }
            catch
            {
                textBox1.Focus();
            }
        }
        void textBox2_Leave(object sender, EventArgs e)
        {
            try
            {
                int t2Val = Convert.ToInt32(textBox2.Text);
            }
            catch
            {
                textBox2.Focus();
            }
        }
        void textBox3_Leave(object sender, EventArgs e)
        {
            try
            {
                int t3Val = Convert.ToInt32(textBox3.Text);
            }
            catch
            {
                textBox3.Focus();
            }
        }
        #endregion
    
        private void button1_Click(object sender, EventArgs e)
        {
            int r = t1Val;
            int y = t2Val;
            int g = t3Val;
    
            t1 = new Thread(new ParameterizedThreadStart(loopRed));
            t2 = new Thread(new ParameterizedThreadStart(loopGreen));
            t3 = new Thread(new ParameterizedThreadStart(loopBlue));
    
            // It will avoid proble if you exit app when threads are working
            t1.IsBackground = true;
            t2.IsBackground = true;
            t3.IsBackground = true;
    
    
            t1.Start(r);
            t2.Start(y);
            t3.Start(g);
    
        }
        private void updateRed(int val)
        {
            pictureBox1.Width++;
            pictureBox1.Left--;
            pictureBox1.Refresh();
        }
    
        private void updateGreen(int val)
        {
            pictureBox2.Height++;
            pictureBox2.Top--;
            pictureBox2.Refresh();
        }
        private void updateBlue(int val)
        {
            pictureBox3.Width++;
            pictureBox3.Refresh();
        }
    
        private void loopRed(object o)
        {
            int c = (int)o;
            CTMethod ctRed = new CTMethod(updateRed);
            if (c < 500)
            {
                for (int i = 0; i < c; i++)
                {
                    if (pictureBox1.Left > 0)
                    {
                        this.Invoke(ctRed, i);
                        Thread.Sleep(20);
                    }
                }
            }
    
            else
            {
                MessageBox.Show("Enter a value less than 500 for Red Box!!!");
            }
            CTFinish CTFin = new CTFinish(Threadfinish);
            this.Invoke(CTFin, "Red");
        }
    
        private void loopGreen(object o)
        {
            int c = (int)o;
            CTMethod ctGreen = new CTMethod(updateGreen);
            if (c < 500)
            {
                for (int i = 0; i < c; i++)
                {                    
                    if (pictureBox2.Top > 0 && pictureBox2.Top != textBox2.Top + textBox2.Height)
                    {
                        this.Invoke(ctGreen, i);
                        Thread.Sleep(20);
                    }
                    else
                        break;
                }
            }
            else
            {
                MessageBox.Show("Enter a valure less than 500 for Green Box!!!");
            }
            CTFinish CTFin = new CTFinish(Threadfinish);
            this.Invoke(CTFin, "Green");
        }
    
    
        private void loopBlue(object o)
        {
            int c = (int)o;
            CTMethod ctBlue = new CTMethod(updateBlue);
            if (c < 500)
            {
                for (int i = 0; i < c; i++)
                {
                    if (pictureBox3.Left + pictureBox3.Width < this.Width)
                    {
                        this.Invoke(ctBlue, i);
                        Thread.Sleep(20);
                    }
                    else
                        break;
                }
            }
            else
            {
                MessageBox.Show("Enter a valure less than 500 for Blue Box!!!");
            }
            CTFinish CTfin = new CTFinish(Threadfinish);
            this.Invoke(CTfin, "Blue");
    
        }
    
        private void Threadfinish(string t)
        {
            order.Enqueue(t);
            if (order.Count == 3)
            {
    
                MessageBox.Show("Threads finished in this order: \n" + "1." + order.Dequeue() + "\n" + "2." + order.Dequeue()
                    + "\n" + "3." + order.Dequeue() + "\n", "finished");
    
            }
        }
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really need help this time - Joomla 2.5 and latest K2. I'm using
i need help with this. I'am using JQuery's Dynamic Form plug-in, it duplicates my
I need help finishing this statement. It is frustrating that two of the PHP
I really need help with this last part of my program. I need to
I Really need help in this ... I'm building an application where I need
I really need help on this one. I am having a simple login form
I am new to android and need help on this. I have two views
Not exactly about programming, but I need help with this. I'm running a development
Sorry to bother again, but I really need help transforming this Python2 code into
Need some help with this problem in implementing with XSLT, I had already implemented

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.