Display image on 2nd form?

Discussion in 'C#' started by shah123, May 16, 2007.

  1. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I have 2 forms, on one form i want to browse image and want to save them in array or arraylist and show on 2nd form that selected image. How would that be done?

    One more query is that if i want to show that image in 2nd form can i set the size of image to be shown in a proper place as thier will be some more images will be later on adding to that form as well.

    Please help. Thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Have a static property in Form1 that can be accessible in the other form.
     
  3. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Can you be more specific Shabbir brother?
     
  4. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    It worked now the image is in proper shape in the picture box but now the next question is

    "how u will put them in some arraylist so i can show multiple images at one time in the picturebox on the form".

    Thanks
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Have the property to give you list of images. :D
     
  6. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    I made the property like following but giving exception

    Login.cs
    public String getImages
    {
    get{ return imgtextbox.text;}
    }

    tictactoe.cs
    Login l=new Login();
    Picturebox1.Load(l.getImages); // give exception here
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Make
    Code:
    public String getImages
    as
    Code:
    public ArrayList getImages
     
  8. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    I created two List fields as on Login Form

    private List<string> imageList = new List<string>();
    private List<string> username = new List<string>();

    TicTacToe tic=new TicTacToe(usernametextBox.Text,imgTextbox.Text);

    What I have to do to change in the constructor of TicTacToe so i can add in someway List of usernames.

    Anyway to convert string of usernametextbox to ArrayList?
     
  9. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Its a game of two people so 2 people need to login and 2 images will be displayed on next form?
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    So its you to decide to have 2 properties or array list of images
     
  11. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Hi Shabbir,
    I have one form which is login form which contains username and image browsing field. Now in

    Login.cs

    Code:
    private void LoadGameButton_Click(object sender, EventArgs e)
                {
          TicTacToe tic=new TicTacToe(usernametextBox.Text,imgTextbox.Text);
                    if (imgTextbox.Text.Equals(""))
                    {
                        MessageBox.Show("Please select any image");
                        return;
                    }
                    else
                    {
                        tic.Show();
                       // this.Hide();
                    }
                    }
    
    In TicTacToe.cs

    Code:
    public TicTacToe(String strText,string img)
            {
                InitializeComponent();
                if (strText.Equals(""))
                {
                    label2.Text = "Guest";
                }
                else
                {
                    label2.Text = strText;
                   
                }
               
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                //pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
               
                pictureBox1.Load(img);
                pictureBox1.Refresh();
            }
    
    Question is:
    I defined two picturebox fields on this form where i can load 2 people images but now how to write the code so that once the user is logged in image will come in one picturebox and when second user is logged in it will come in second picturebox and after that login form should be hidden.

    Please help?
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Now after explaining this it looks you are unable to describe the problem properly. First you had something else.

    Simple have a global / class / static variable of username and based on user name load the images accordingly.
     
  13. shah123

    shah123 New Member

    Joined:
    Mar 27, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Got It Working...thanks Anyway
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice