locked
Display Image RRS feed

  • Question

  • How can I display an image using a program?

    The point of the top-left of the image should be (x,y) (389,563).

    The image itself is 402 x 11.

    I just want to press a button to show the image, not launch the image. Just to display it.
    Friday, August 22, 2008 3:24 PM

Answers

  • How about this:

    • Create your picture on another form
    • Set that form's BackColor and TransparencyKey properties to the same Color
    • Set the form's FormBorderStyle property to "None"
    • Show the form

    With these properties set in this fashion, your form is transparent and borderless. Now it looks like your picture is magically floating on the desktop.

    Friday, August 22, 2008 10:28 PM
  • Try the following code snippet. Also modify it based on your requirement.

    Public Class Form1
        Dim MLoc As Point
        Dim MMov As Boolean
        Dim f As Form
        Dim WithEvents PictureBox1 As PictureBox
        Private Sub picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
            MMov = True
            MLoc = e.Location
            If ((e.Button And Windows.Forms.MouseButtons.Middle) = Windows.Forms.MouseButtons.Middle) Then
            End If
        End Sub
        Private Sub picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If MMov Then
                f.Left += e.X - MLoc.X
                f.Top += e.Y - MLoc.Y
            End If
        End Sub
        Private Sub picturebox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
            MMov = False
            If ((e.Button And Windows.Forms.MouseButtons.Left) = Windows.Forms.MouseButtons.Left) Then
                MMov = False
            End If
        End Sub
        Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            f = New Form
            PictureBox1 = New PictureBox
            f.Show()
            f.Location = New Point(100, 100)
            f.ControlBox = False
            f.Text = String.Empty
            f.Controls.Add(PictureBox1)
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Dock = DockStyle.Fill
            PictureBox1.ImageLocation = "E:\temp\bmp\right.bmp"
            f.Opacity = 0.6
            f.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            f.BackColor = Color.Beige
            f.TopMost = True
        End Sub
    End Class
    Tuesday, August 26, 2008 7:44 AM
    Moderator

All replies

  • Something like this:

     

    Code Snippet

            private void button1_Click(object sender, EventArgs e)
            {
                PictureBox p = new PictureBox();
                p.Location = new Point(389, 563);
                p.Size = new System.Drawing.Size(402, 11);
                p.Image = new Bitmap(@"C:\image.bmp");

                this.Controls.Add(p);
            }

     

     

    EDIT: Oops! Wrong language. If necessary: http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

    Friday, August 22, 2008 8:59 PM
  • Hey. This is close, but I don't want it to be inside a form. I just want it to be like a separate application. It just shows a picture.
    Friday, August 22, 2008 9:24 PM
  • Also, it should be something like it's on top of everything. So you can press any application (Windows Internet Explorer, Video Games, etc.) and it will still be there. It just stays at a point.
    Friday, August 22, 2008 9:35 PM
  • So another example is like it's a picture at this particular point.
    Friday, August 22, 2008 9:42 PM
  • How about this:

    • Create your picture on another form
    • Set that form's BackColor and TransparencyKey properties to the same Color
    • Set the form's FormBorderStyle property to "None"
    • Show the form

    With these properties set in this fashion, your form is transparent and borderless. Now it looks like your picture is magically floating on the desktop.

    Friday, August 22, 2008 10:28 PM
  • That's the problem. It can't "look like" it's floating. It has to actually BE floating.
    Friday, August 22, 2008 10:58 PM
  • Try the following code snippet. Also modify it based on your requirement.

    Public Class Form1
        Dim MLoc As Point
        Dim MMov As Boolean
        Dim f As Form
        Dim WithEvents PictureBox1 As PictureBox
        Private Sub picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
            MMov = True
            MLoc = e.Location
            If ((e.Button And Windows.Forms.MouseButtons.Middle) = Windows.Forms.MouseButtons.Middle) Then
            End If
        End Sub
        Private Sub picturebox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
            If MMov Then
                f.Left += e.X - MLoc.X
                f.Top += e.Y - MLoc.Y
            End If
        End Sub
        Private Sub picturebox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
            MMov = False
            If ((e.Button And Windows.Forms.MouseButtons.Left) = Windows.Forms.MouseButtons.Left) Then
                MMov = False
            End If
        End Sub
        Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            f = New Form
            PictureBox1 = New PictureBox
            f.Show()
            f.Location = New Point(100, 100)
            f.ControlBox = False
            f.Text = String.Empty
            f.Controls.Add(PictureBox1)
            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Dock = DockStyle.Fill
            PictureBox1.ImageLocation = "E:\temp\bmp\right.bmp"
            f.Opacity = 0.6
            f.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            f.BackColor = Color.Beige
            f.TopMost = True
        End Sub
    End Class
    Tuesday, August 26, 2008 7:44 AM
    Moderator