1.11M Members

Displayin picture in different form

 
0
 

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.

 
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; }
        }
    }
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: