CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

Updating a picture box in one class from a different class. topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 09-08-2010, 01:55 PM
Junior Member
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
tomprice0189 is on a distinguished road
| More
Updating a picture box in one class from a different class.

Hi all,

So here is my situation:

2 classes

1st class is a windows form created in VS2008. It has a picture box on it which i want to update with images.

2nd class is a custom class called 'camera' which uses the AForge.Net framework to grab images from my webcam. The important part is that there is an event handler that fires everytime a new frame is got from the webcam and creates a bitmap.


So... I need some advice on the best way of updating the picturebox in the form class with the latest frame in the camera class..

At the moment I have a set method in the form class like so...

public static void setPB(Bitmap image)
{


var form = Forms.ActiveForm as Form1;
form.PictureBox.Image = image

}

this method is then called in the newframe event handler within the camera class.

This code works fine however I would like to know if this is the best way to attack the problem?

The other way I thought of doing it was when i create an object of the camera class, to pass my form as a parameter so that I can set the picturebox image from within the camera class itself.

Please note: i only have 1 thread at the moment.

Thanks in advance, much appreciated.

Tom
Reply With Quote
  #2  
Old 11-30-2010, 10:07 PM
Senior Member
 
Join Date: Sep 2010
Location: Kolkata, India
Posts: 307
Thanks: 0
Thanked 15 Times in 15 Posts
techforum4u is on a distinguished road
| More
Re: Updating a picture box in one class from a different class.

This can be achieved with the use of "Interform Control Access"...
let me give u an example:-

Code:
public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
   
          private void Form1_Load(object sender, EventArgs e)
          {
              Form2 frm2 = new Form2(this); //pass reference to this form in constructor
          }
           
    }


      public partial class Form2 : Form
      {
          Form1 frm1;
          public Form2(Form1 callingForm)
          {
              InitializeComponent();
              frm1 = callingForm;  //store local reference to Form1
          }
   
          private void Form2_Load(object sender, EventArgs e)
          {
              frm1.picturebox.Image=”path”;
          }
      }
Let me know for any concerns...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Base Class pointer can't operate on a class derived in protected mode? S.P.I. C++ Programming 1 09-03-2010 02:32 AM
New Window class - cannot convert LRESULT Class:: to LRESULT c0d3m0nk3y Win32 Programming 0 08-28-2010 03:00 AM
Can Derived Class Contain Vector of pointers to the parent class? ZhiYi C++ Programming 0 07-02-2010 12:23 AM
Pointer and Class inspiration C++ Programming 8 05-31-2010 08:55 PM
get Class johny10151981 Win32 Programming 1 10-07-2008 03:58 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:46 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board