none
Unable to cast object of type 'System.Windows.Forms.RichTextBox' to type 'System.Windows.Forms.PictureBox RRS feed

  • Question

  • Hello to all Concerned

    How do solve the error type Unable to cast object of type 'System.Windows.Forms.RichTextBox' to type 'System.Windows.Forms.PictureBox' in Visual Studio Desktop 2012 platform in C#.

    I am attempting to save an existing Jpeg image using picturebox component in an Active Mdichild form

    from the Parent form using a menustrip component,

    The code in C# is as follows:

    private void saveFileToolStripMenuItem_Click(object sender, EventArgs e)
            {
               
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Images|*.png;*.bmp;*.jpg;*.tiff";
                System.Drawing.Imaging.ImageFormat format = System.Drawing.Imaging.ImageFormat.Jpeg;
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string ext = System.IO.Path.GetExtension(sfd.FileName);
                    switch (ext)
                    {
                        case ".jpg":
                            format = System.Drawing.Imaging.ImageFormat.Jpeg;
                            break;
                        case ".bmp":
                            format = System.Drawing.Imaging.ImageFormat.Bmp;
                            break;
                    }
                    Form activeChildForm = this.ActiveMdiChild;

                    if (activeChildForm != null)
                    {
                        PictureBox pictureBox1 = (PictureBox)activeChildForm.ActiveControl;
                        if (pictureBox1 != null)
                            pictureBox1.Image.Save(sfd.FileName, format); 
                    }
                    //Error Response from compiler:  Additional information: Unable to cast object of type

                       'System.Windows.Forms.RichTextBox' to type  'System.Windows.Forms.PictureBox'.

                }
            }


    g

    Thursday, June 6, 2013 3:25 PM

All replies

  • geogenie,

    Sorry but you have posted to a forum that deals exclusively with questions/issues about programming and customizing Microsoft Project, a planning and scheduling application. I suggest you delete this post and start with this forum:

    http://social.technet.microsoft.com/Forums/en-US/whatforum/threads

    John

    Thursday, June 6, 2013 3:31 PM