473,379 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

displaying image in different form

Hi,
I am creating an application which has a main menu which enables a user to open a picture, I then want this picture to be displayed in a different form. I have created a new instance when the file is loaded but I cannot work out what code needs to be imputed to display the picture in the new instance. Please could somebody suggest a solution ?
Mar 13 '10 #1
1 2193
tlhintoq
3,525 Expert 2GB
How do I get my Form2 to react to something on my Form1?
How do I make my Form1 control something on my Form2?
Although you can have Form1 directly access items on Form2 it isn't the recommended way to go. It ties the two forms tightly to each other. If a change is made in Form2 such as removing one of the controls, then code in Form1 breaks.
It is better to Form1 raise an event, and have Form2 contain its own code for how to react to this. This places responsibility for Form2 within Form2, and Form1 within Form1.
It keeps Form1 blissfully ignorant of Form2 - and a logging component - and a progress component, and a dozen other little black boxes that can be subscribed to events in Form1, all without Form1 being made responsible for directly affecting controls other than itself.
Events tutorial (including Form to Form which is the same as class to class)
This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard.
Bad: Directly accessing controls of one class/form from another.
Expand|Select|Wrap|Line Numbers
  1. bool IsOn = Form2.button1.IsChecked;


Good: Use a property to get such information
Expand|Select|Wrap|Line Numbers
  1. //Form1
  2. bool IsOn = Form2.IsOn;
Expand|Select|Wrap|Line Numbers
  1. //Form 2
  2. public bool IsOn
  3. {
  4.    get { return button1.Checked; }
  5.    set { button1.Checked = value; }
  6. }
It's a subtle but important difference as your applications become more complex. Using properties means your target class/form (Form2) can be changed and updated a thousand different ways yet won't negatively impact the classes that are reading from it. If you change the name of a control for example: No break in all your other classes. If your target form evolves where it needs to do 10 things when it is turned on, then the responsibility stays within Form2, and that burden on not put on Form1 and a dozen other forms that might be using Form2. The goal is to compartimentalize the work so that Form2 is responsiblity SOLELY for Form2. From1 should only have to say "Turn on" or "Turn Off"

Expand|Select|Wrap|Line Numbers
  1. Form2
  2. public bool IsOn
  3. {
  4.    get { return btnMeaningfulName.Checked; }
  5.    set {
  6.             btnMeaningfulName.Checked = value;
  7.             panelDashboard.Visible = value;
  8.             labelStatus = value == true ? "On" : "Off";
  9.             btnRunNow.Enabled = value;
  10. }
Now when Form1 tells Form2 to turn on, Form2 will check a box, make an entire panel visible, change its Status label to say 'On' and enable a Run Now button.
Mar 13 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
4
by: pmud | last post by:
Hi, I have an image which resides on a different server...on data server. I am developing on Development server. When I use the image URLin my ASP.Net web page as ...
13
by: Jose.M.Huerta | last post by:
I'm trying to display in a continuos form some *.jpg. I have a table with the file path, (a photo of a person). Display these photos in a single form is very easy, just using changing some...
15
by: mleaver | last post by:
I want to open a second window and display a binary image that is returned from a java program via XMLRPC. The data returned is a binary encoded base64 png file. If I write the data out to a file...
8
by: Jon Weston | last post by:
I'm setting up an Access2003 database with pictures. I put a bound ole picture ctrl on a form that's source is the table that contains the pictures and follow ALL the directions for embedding a...
1
by: nowitsoverx | last post by:
I'm just trying to test something out to see if I can get it working but I'm a little stuck. I have two frames. The left one has a menu of radio buttons. I want it so when you click on the radio...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
7
by: hsegoy1979 | last post by:
Dear All Iam using file upload control and i want to display image in another pop up page .But image is not displaying in image control iam sending image path thru querystring . here is my code ...
11
by: Marge | last post by:
After importing a VB6 project into Express 2008 I have two gif's with transparency do not display correctly. In VB6 these pictures where used with the image object which had different properties...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.