We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,018 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Displayin picture in different form

hi,

I am new to c# and I am working on an application which has a main menu with an open dialog which enables users to select picture files, when the user has selected the picture file I then want this to be displayed in a new form called picture_viewer. I have created a new instance of the picture viewer on the main menu but I am stuck on how to get the picture into the picture box on the picture viewer form.

2
Contributors
1
Reply
3 Days
Discussion Span
3 Years Ago
Last Updated
2
Views
jakkee
Newbie Poster
5 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

there are a great many threads on Daniweb about passing data between forms, you should really try to find them and read them as there is a lot of helpful info there.

In order to set the contents of the viewers picturebox, you could either add an overloaded constructor method to the viewer that accepts the image as a parameter, or add a property to the viewer that allows you to set the picturebox contents.

The following sets a labels text property, but you get the idea:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnConstructor_Click(object sender, EventArgs e)
        {
            SubForm sub = new SubForm("Label Set by Constructor");
        }

        private void btnProperty_Click(object sender, EventArgs e)
        {
            SubForm sub = new SubForm();
            sub.LabelText = "Label Set by Property";
        }

    }

    public partial class SubForm : Form
    {
        public SubForm()
        {
            InitializeComponent();
        }

        public SubForm(string text)
        {
            InitializeComponent();
            label1.Text = text;
        }

        public string LabelText
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }
    }
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 247
Skill Endorsements: 10

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.2937 seconds using 2.66MB