Ver Mensaje Individual
  #12 (permalink)  
Antiguo 01/12/2010, 06:33
escarba
 
Fecha de Ingreso: septiembre-2010
Mensajes: 26
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: Crear favoritos en navegador web c#

Código c#:
Ver original
  1. namespace WindowsFormsApplication2
  2. {
  3.     public partial class favoritos : Form
  4.     {
  5.         int contador_fav;
  6.         int contador_img;
  7.         public struct favorito
  8.         {
  9.             public string dir;
  10.             public string nom;
  11.             public string img;
  12.         }
  13.         public favoritos()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.            
  21.             //capturar pantalla en el momento
  22.             string ruta_img = @"C:\Users\Pablink\Documents\proyecto\favorito_" + contador_img.ToString() + ".jpg";
  23.  
  24.             Rectangle region = Screen.AllScreens[0].Bounds;
  25.             Bitmap bitmap = new Bitmap(region.Width, region.Height, PixelFormat.Format32bppPArgb);
  26.  
  27.             Graphics graphic = Graphics.FromImage(bitmap);
  28.             graphic.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);
  29.             bitmap.Save(ruta_img, ImageFormat.Png);
  30.             string url = direccion.Text;
  31.             string name = nombre.Text;
  32.             favoritos f = new favoritos();
  33.             favorito nuevo_favorito = new favorito();
  34.             nuevo_favorito.dir = url;
  35.             nuevo_favorito.nom = name;
  36.             nuevo_favorito.img = ruta_img;
  37.             pictureBox1.ImageLocation = ruta_img;
  38.  
  39.             f.Serializa_XML(@"C:\Users\Pablink\Documents\proyecto\favoritos.xml", nuevo_favorito);
  40.             contador_img++;
  41.             contador_fav++;
  42.             Deserializar_XML(@"C:\Users\Pablink\Documents\proyecto\favoritos.xml");
  43.         }
  44.            
  45.         public void Serializa_XML (string ruta, favorito nuevo)
  46.         {
  47.             XmlSerializer serializador = new XmlSerializer(typeof(favorito));
  48.             StreamWriter sw = new StreamWriter(ruta);
  49.             serializador.Serialize(sw,nuevo);
  50.             sw.Close();
  51.  
  52.             //FileStream fs = new FileStream(ruta, FileMode.Append);
  53.             //XmlSerializer serializador = new XmlSerializer(typeof(favorito));
  54.             //serializador.Serialize(fs, nuevo);
  55.             //fs.Close();
  56.  
  57.         }
  58.         void Deserializar_XML(string ruta)
  59.         {
  60.             XmlSerializer serializador = new XmlSerializer(typeof(favorito));
  61.             StreamReader sr = new StreamReader(ruta);
  62.             favorito f = (favorito)serializador.Deserialize(sr);
  63.             //etiqueta_dir.Text = f.dir;
  64.             etiqueta_nom.Text = f.nom;
  65.             pictureBox1.ImageLocation = f.img;
  66.             sr.Close();
  67.         }
  68.  
  69.         private void favoritos_Load(object sender, EventArgs e)
  70.         {
  71.             Deserializar_XML(@"C:\Users\Pablink\Documents\proyecto\favoritos.xml");
  72.         }
  73.     }
  74. }

Sigo teniendo el problema de generar el xml, tambien genero una captura de imagen y guardo su ruta para posteriormente recuperarla...

Otro tema es...como creeis que tengo que recuperar los datos? deserializo, pero tendria que crearme un picturebox por cada favorito y un label para el nombre...alguna idea de como hacer eso??

GRACIAS!! ayudarme por favorr!!