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

  • SEARCH
  • Home
  • 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 8777075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:12:24+00:00 2026-06-13T19:12:24+00:00

Here’s the sitch. I click a button and create a new PictureBox no problem.

  • 0

Here’s the sitch. I click a button and create a new PictureBox no problem. When I click and drag, I move the picture to it’s new location. Now, when I click the button again, I create a new instance of the same PictureBox and when I try to move the old one, I end up moving the newly created box. I take it this is because they both have the same name:

PictureBox pic = new PictureBox();

How can I switch between the two pictureboxes by clicking?

*UPDATE*
Thanks to Nilotpal’s answer I’ve managed to solve the above problem. Only thing is the picturebox now seems to shake, or switch locations back and fourth between the other instance and the one I’m dragging. Either way, I’m really unsure about how to solve this. Any ideas?

*UPDATE*
The code I have:

 private void code128ToolStripMenuItem_Click(object sender, EventArgs e)
    {


        bNum++;
        Barcode barcode = new Barcode();


        pic = new PictureBox();
        pic.Name = "bCode" + bNum;
        pic.SizeMode = PictureBoxSizeMode.AutoSize;
        pic.Image = barcode.createBarcode(BarcodeLib.TYPE.CODE128, 300, 100, "123456789");

        pic.Show();
        labelHolder.Controls.Add(pic);
        pic.BringToFront();
        pic.MouseDown += pic_MouseDown;
        pic.MouseMove +=pic_MouseMove;
        pic.MouseUp += pic_MouseUp;
    }



    PictureBox thisPB;
     private void pic_MouseDown(object sender, MouseEventArgs e)
    {


        mouseDown = true;

        oldX = e.X;
        oldY = e.Y;


    }


    private void pic_MouseMove(object sender, MouseEventArgs e)
    {
        if(mouseDown)
        {



                thisPB = (PictureBox)sender;
                thisPB.Location = new Point(pic.Location.X - (oldX - e.X), pic.Location.Y - (oldY - e.Y));


                this.Refresh();


        }




    }


    private void pic_MouseUp(object sender, MouseEventArgs e)
    {

        mouseDown = false;

    }
  • 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-13T19:12:26+00:00Added an answer on June 13, 2026 at 7:12 pm
        private void button1_Click(object sender, EventArgs e)
        {
            PictureBox pb = new PictureBox();
            pb.Top = 200;
            pb.Left = 200;
            pb.BackColor = Color.Gray;
            pb.MouseMove += new MouseEventHandler(pb_MouseMove);
            this.Controls.Add(pb);
        }
    
        void pb_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                PictureBox thisPB = (PictureBox)sender;
                thisPB.Left = e.X;
                thisPB.Top = e.Y;
            }
        }
    

    The move will be shaky, you can change that according to your need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem. Our tech. writer or customer service will often create new
Here is my problem.. I have the option to create(add) two new input fields,
Here is my problem : I have a post controller with the action create.
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here is the problem that I am trying to solve. I have two folders
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();

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.