12 Replies - 1405 Views - Last Post: 19 November 2012 - 08:49 AM Rate Topic: -----

#1 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 06:41 AM

Is there anyone here who knows how to solve this?

Actually I do not know what is wrong with my codes. Because I am trying to declare the x and y values for my picturebox.

The picturebox will be loaded during run time only. So how could I use the picturebox_mousemove event?

here is my code for the addingcontroltoform
//Add Control to form
        private void AddtbCtrl1toForm(System.IO.FileInfo Fi)
        {
            Image img = null;
            
            try
            {  
                img = Image.FromFile(Fi.FullName);
                this.FleLst.Items.Add(Fi.Name);

                TabPage tp = new TabPage();
                Panel pnl = new Panel();
                PictureBox PB = new ImageBox();

                tp.Text = Fi.Name;

                //panel
                pnl.AutoScroll = AutoScroll = true;
                pnl.Location = new Point(3, 3);
                pnl.Size = new Size(566, 574);
                pnl.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                tp.Controls.Add(pnl);

                //picturebox
                PB.Location = new Point(25, 25);
                PB.Size = new Size(520, 535);
                PB.SizeMode = PictureBoxSizeMode.AutoSize;
                pnl.Controls.Add(PB);
                
                PB.Image = img;
                this.tbCtrl1.TabPages.Add(tp);
                
                
            }
            catch
            {
                if (img != null)
                    img.Dispose();
            }

            
        }



and for my picturebox_mousemove event.

       // Picture Box Control for X and Y
        private void ImgBx_MouseMove(object sender, MouseEventArgs e)
        {
            if (imgbx.Image != null)
            {
                this.XposTlStrpLbl.Text = " " + e.X.ToString();
                this.YposTlStrpLbl.Text = " " + e.Y.ToString();

                if (gray_in_use)
                {
                    this.XYValTlStrpLbl.Text = " " + GryImg[e.Y, e.X].ToString();
                }
                else
                {
                    this.XYValTlStrpLbl.Text = " " + MImg[e.Y, e.X].ToString();
                }

             
            }
        }   



thanks

Is This A Good Question/Topic? 0
  • +

Replies To: adding picturebox_mousemove event in running at run time

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3531
  • View blog
  • Posts: 10,934
  • Joined: 05-May 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 07:22 AM

I don't see what the problem is. You would still register for the mouse move event at some point after you create an instance of your picturebox. All the controls in WinForms are created at run time. Most of the code is just hidden away in the the .designer.cs file.
Was This Post Helpful? 0
  • +
  • -

#3 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 09:08 AM

I appreciate your reply. Do you have any idea how to control the picturebox_mousemove. i can't connect the AddtbCtrl1toForm to mousemove event or should i connect the mousemove to AddtbCtrl1toForm? is there any function to declare like add to control also like codes?

-thanks-
Was This Post Helpful? 0
  • +
  • -

#4 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 09:15 AM

I forgot to post this codes for opening a file
  //Open File Menu Item

        private void OpenTStrpMItm_Click(object sender, EventArgs e)
        {
           if (this.OpnFleDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
               MImg = new Image<Bgr, byte>(this.OpnFleDlg.FileName);

               //imgbx.Image = MImg.ToBitmap();
                 
               MImg = MImg.Copy();
               
            }
            if (this.OpnFleDlg.FileNames.Length > 0)
            {
        
                this.Text = System.IO.Path.GetDirectoryName(this.OpnFleDlg.FileNames[0]);
                    foreach (string pb in this.OpnFleDlg.FileNames)
                    {
                        AddtbCtrl1toForm(new System.IO.FileInfo(pb));
                    
                    }         
            }
        }     


//imgbx.Image = MImg.ToBitmap(); this is my problem because there is not picturebox on the form. just during run time.

thanks
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3531
  • View blog
  • Posts: 10,934
  • Joined: 05-May 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 06:59 PM

If you want to register for an event, you simply do:
myControl.MouseMove += new EventHandler(MyControl_MouseMove);
:
void MyControl_MouseMove(object sender, MouseEventArgs e)
{
    :
}


Was This Post Helpful? 0
  • +
  • -

#6 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 10:11 PM

i did that but still not working sorry
Was This Post Helpful? 0
  • +
  • -

#7 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 10:29 PM

View PostSkydiver, on 18 November 2012 - 06:59 PM, said:

If you want to register for an event, you simply do:
myControl.MouseMove += new EventHandler(MyControl_MouseMove);
:

{
    :
}



myControl.MouseMove += new EventHandler(MyControl_MouseMove);

void MyControl_MouseMove(object sender, MouseEventArgs e)



will you put this under my tabctrl1toform, openbutton or do i need to make a new one.

this is my code private void Imgx_MouseMove(object sender, MouseEventArgs e)

of course perform the operation here.

sorry i am not expert in programming and still newbie. hope you understand my situation
Was This Post Helpful? 0
  • +
  • -

#8 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 18 November 2012 - 10:40 PM

Is it still possible even the picturebox is not loaded in the form. just during run time to do the operation. sorry i am starting to get confused now.
Was This Post Helpful? 0
  • +
  • -

#9 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: adding picturebox_mousemove event in running at run time

Posted 19 November 2012 - 03:28 AM

Right after you create the picture box you would register the mouse move event handler.
Was This Post Helpful? 0
  • +
  • -

#10 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 19 November 2012 - 07:53 AM


 //picturebox
                PB.Location = new Point(25, 25);
                PB.Size = new Size(520, 535);
                PB.SizeMode = PictureBoxSizeMode.AutoSize;
                PB.MouseMove += new MouseEventHandler(PB_MouseMove); <-this one




  void PB_MouseMove(object sender, MouseEventArgs e)
        {
            throw new NotImplementedException();
        }



but i am still having a problem. because everytime i am controlling the picturebox it is not working. and i got many errors
Was This Post Helpful? 0
  • +
  • -

#11 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 19 November 2012 - 08:00 AM

I already removed

throw new NotImplementedException(); but still having an error

void PB_MouseMove(object sender, MouseEventArgs e)
        {   
            //if (imageBox1.Image!=null)
            {
                this.XposTlStrpLbl.Text = " " + e.X.ToString();
                this.YposTlStrpLbl.Text = " " + e.Y.ToString();
            }
            
            if (gray_in_use)
            {
                 this.XYValTlStrpLbl.Text = " " + GryImg[e.Y, e.X].ToString();
            }
            
            else
            {
                this.XYValTlStrpLbl.Text = " " + MImg[e.Y, e.X].ToString();
            }
        }
    }




   void PB_MouseMove(object sender, MouseEventArgs e)
        {
           //throw new NotImplementedException(); <- even if i removed this or not. 
              //if (imageBox1.Image!=null) <- need to declared the picturebox from private void AddtbCtrl1toForm
            {
                this.XposTlStrpLbl.Text = " " + e.X.ToString();
                this.YposTlStrpLbl.Text = " " + e.Y.ToString();
            }
            
            if (gray_in_use)
            {
                 this.XYValTlStrpLbl.Text = " " + GryImg[e.Y, e.X].ToString();
            }
            
            else
            {
                this.XYValTlStrpLbl.Text = " " + MImg[e.Y, e.X].ToString();
            }
        }
    }


      //Open File Menu Item
        private [u]void[/u] OpenTStrpMItm_Click(object sender, EventArgs e)
        {
           if (this.OpnFleDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
               MImg = new [u]Image[/u]<Bgr, byte>(this.OpnFleDlg.FileName);

           //    imgbx.Image = MImg.ToBitmap();
                     
               MImg = MImg.Copy();
               
            }
            [u]if[/u] (this.OpnFleDlg.FileNames.Length > 0)
            {
        
                this.Text = System.IO.Path.GetDirectoryName(this.OpnFleDlg.FileNames[0]);
                    foreach (string pb in this.OpnFleDlg.FileNames)
                    {
                        AddtbCtrl1toForm(new [u]System[/u].IO.FileInfo(pb));
                    
                    }         
            }
        }     





thanks ^^
Was This Post Helpful? 0
  • +
  • -

#12 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 19 November 2012 - 08:05 AM

View PostMomerath, on 19 November 2012 - 10:28 AM, said:

Right after you create the picture box you would register the mouse move event handler.


my picture box is not loaded in the form. it will be loaded during run time only. meaning in my design there is no picturebox just only tab control with no tabpages
Was This Post Helpful? 0
  • +
  • -

#13 bullred42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 18-November 12

Re: adding picturebox_mousemove event in running at run time

Posted 19 November 2012 - 08:49 AM

i found the solution already. thanks and sorry for giving you trouble
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1