Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / August 2005

Tip: Looking for answers? Try searching our database.

Problems with picturebox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
indubidu - 13 Aug 2005 12:12 GMT
Hi,

first, sorry for my BAD english.
I come from the JAVA pogramming and now I try to programming in J#. M
problem, I have 3 classes, a ControlClass(with a button) and
ViewClass(with a picturebox, declared as public) and the MainClass(
form that contains the ControllClass and the ViewClass).
With the button i will change the image in the picturebox, but i
dosn't work.
//here some code from the ControllClass
//global declaration
..
public Forum.View view;

//Constructor
..
view = new Forum.View();

//button1_click
private void button1_Click (Object sender, System.EventArgs e)
{
        view.pictureBox1.set_Image(Image.FromFile("pic.jpg"));
}
The problem, the picturebox will not update/repaint.
I hope there is anybody with a god idea.

thanks for your help
invio

the attachment-function dosn't work, so i can't show you the ful
sourcecod

--
indubid
Sushovan - 15 Aug 2005 09:41 GMT
Dear indubidu,
 If you wish to force a picturebox to repaint itself, call Refresh() on it,
like

pictureBox1.Refresh();

 If this does not work, make sure that the pictureBox is visible on the
MainClass form - one quick way to check this is to set the BackColor property
of the pictureBox to Color.Red, so that if it is rendered on the form, you
will be able to see it.

--
Sushovan, a crazy junior

> Hi,
>
[quoted text clipped - 27 lines]
> the attachment-function dosn't work, so i can't show you the full
> sourcecode
Lars-Inge Tønnessen [VJ# MVP] - 17 Aug 2005 20:15 GMT
Hi,

Please show me more code, if you want more help with your problem.

> view.pictureBox1.set_Image(Image.FromFile("pic.jpg"));

I hope your Image must be a bitmap. All graphics in Windows is Bitmaps on
the lowest level.

Here you will find a sample that will show you a GIF image in a picturebox.
Please remember to give the correct path to the image.

package PicBox;

import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
import System.Data.*;

public class Form1 extends System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.Container components = null;

public Form1()
{
 InitializeComponent();
}

/**
 * Clean up any resources being used.
 */
protected void Dispose(boolean disposing)
{
 if (disposing)
 {
  if (components != null)
  {
   components.Dispose();
  }
 }
 super.Dispose(disposing);
}

#region Windows Form Designer generated code
/**
 * Required method for Designer support - do not modify
 * the contents of this method with the code editor.
 */
private void InitializeComponent()
{
 this.button1 = new System.Windows.Forms.Button();
 this.pictureBox1 = new System.Windows.Forms.PictureBox();
 this.SuspendLayout();
 //
 // button1
 //
 this.button1.set_Location(new System.Drawing.Point(112, 168));
 this.button1.set_Name("button1");
 this.button1.set_TabIndex(0);
 this.button1.set_Text("button1");
 this.button1.add_Click( new System.EventHandler(this.button1_Click) );
 //
 // pictureBox1
 //
 this.pictureBox1.set_Location(new System.Drawing.Point(24, 24));
 this.pictureBox1.set_Name("pictureBox1");
 this.pictureBox1.set_Size(new System.Drawing.Size(240, 128));
 this.pictureBox1.set_TabIndex(1);
 this.pictureBox1.set_TabStop(false);
 //
 // Form1
 //
 this.set_AutoScaleBaseSize(new System.Drawing.Size(5, 13));
 this.set_ClientSize(new System.Drawing.Size(292, 266));
 this.get_Controls().Add(this.pictureBox1);
 this.get_Controls().Add(this.button1);
 this.set_Name("Form1");
 this.set_Text("Form1");
 this.ResumeLayout(false);

}
#endregion

/**
 * The main entry point for the application.
 */
/** @attribute System.STAThread() */
public static void main(String[] args)
{
 Application.Run(new Form1());
}

private void button1_Click (Object sender, System.EventArgs e)
{
 this.pictureBox1.set_Image( System.Drawing.Bitmap.FromFile("SAP.GIF" ) );
}
}

Regards,
Lars-Inge Tønnessen

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.