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.

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; }
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.