none
como podria hacer que se vea un texto al pasar el mouse por encima de un picturebox RRS feed

Respuestas

  • No sabemos si te refieres a utilizar un control ToolTip, o a pintar un texto sobre el picturebox...

    using System;
    using System.Drawing;
    using System.IO;
    using System.Net;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            bool tieneTexto;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                WebClient wc = new WebClient();
                byte[] b = wc.DownloadData("https://http2.mlstatic.com/D_Q_NP_133305-MLA20849717298_082016-Q.jpg");
                wc.Dispose();
    
                Bitmap bm = new Bitmap(new MemoryStream(b));
    
                pictureBox1.Image = bm;
                pictureBox2.Image = bm;
    
                pictureBox2.ClientSize = pictureBox1.ClientSize = bm.Size;
                pictureBox1.Location = new Point(5, 5);
                pictureBox2.Location = new Point(pictureBox1.Size.Width + 15, 5);
    
                toolTip1.SetToolTip(this.pictureBox1, "perros-salchicha");
                pictureBox2.Tag = "perros-salchicha";
    
                pictureBox2.MouseEnter += (arg1, arg2) => { tieneTexto = true; pictureBox2.Refresh(); };
                pictureBox2.MouseLeave += (arg1, arg2) => { tieneTexto = false; pictureBox2.Refresh(); };
                pictureBox2.Paint += (arg1, arg2) => { if (tieneTexto) arg2.Graphics.DrawString(pictureBox2.Tag.ToString(), this.Font, Brushes.OrangeRed, pictureBox2.ClientRectangle, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near }); }; 
    
                tieneTexto = false;
    
                ClientSize = new Size(2 * bm.Width + 20, bm.Height + 10);
            }
    
        }
    }


    sábado, 10 de junio de 2017 23:20