2 Replies - 1860 Views - Last Post: 28 March 2011 - 03:50 PM Rate Topic: -----

#1 red1337  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 18-September 10

Loading Picturebox image into Tabpage.Imagekey

Posted 27 March 2011 - 08:34 AM

I'm making a Web Browser, and I want the sites FavIcon to be on the Tab of my Tabpage. I already have it loading into a picturebox next to the URL but I need a way to load it from the Picturebox to the Imagelist, and from the Imagelist to the Tabpage.imagekey.

Right now I'm trying stuff along this line.

tabPage1.ImageKey = imageList1.Images.Add(picturebox1.Image);


I am also looking into how to save to the Temporary Internet Files so I can load the image from the TIF's to the Imagelist, but I don't know how to set it so it isn't depending on my windows username as part of the file path.


I normally use Visual Basic, and I'm not even that good at that, this is my first attempt at C Sharp and any help or advice is greatly appreciated.


Thanks in advance.

-Jarod.

Is This A Good Question/Topic? 0
  • +

Replies To: Loading Picturebox image into Tabpage.Imagekey

#2 red1337  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 18-September 10

Re: Loading Picturebox image into Tabpage.Imagekey

Posted 27 March 2011 - 09:35 AM

Or could I try something like this

            imageList1.Images.Add(FavIcon.Image);
            tabPage2.ImageKey = "0";


How would I set the Imagekey of the newly added picture?
Was This Post Helpful? 0
  • +
  • -

#3 red1337  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 18-September 10

Re: Loading Picturebox image into Tabpage.Imagekey

Posted 28 March 2011 - 03:50 PM

I found a workaround.

In case someone else need a workaround for this, here's the code and how to do it.


Add a Toolstrip and Panel to Usercontrol and Form1, make the button_click event and image load, that is in the code below, in the user control, and then make the modifiers public for the controls in Usercontrol and add the code below to dynamically add the controls to Form1 at runtime.

Code for User control 1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Linq;

using System.Text;

using System.Windows.Forms;



namespace testing

{

    public partial class UserControl1 : UserControl

    {

        public UserControl1()

        {

            InitializeComponent();

        }



        private void toolStripButton1_Click(object sender, EventArgs e)

        {

            panel1.BringToFront();



        }



        private void panel1_MouseEnter(object sender, EventArgs e)

        {

            toolStripButton1.Image = pictureBox1.Image;

            toolStripButton1.Text = pictureBox1.ImageLocation;





        }



    }

}



and the code for Form1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace testing
{
    public partial class Form1 : Form
    {


        public Form1()
        {
            InitializeComponent();
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {

            UserControl1 uc1 = new UserControl1();
            toolStrip1.Items.Add(uc1.toolStripButton1);
            // create a new TabPage object
            uc1.panel1.BorderStyle = BorderStyle.Fixed3D;
            //add the newly created TabPage
            //to the tabcontrol's collection of tab pages 
            panel1.Controls.Add(uc1.panel1);
            //create a WebBrowser object
            uc1.panel1.BringToFront();
            //add some event handlers to your browser object
        }
    }
}



I acturally like it better then the tabs, it's more customizable.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1