VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 307,172 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,572 people online right now. Registration is fast and FREE... Join Now!




Image in a message box?

 

Image in a message box?, New to programming

supaapple

9 Jan, 2009 - 04:38 PM
Post #1

D.I.C Head
**

Joined: 21 Feb, 2008
Posts: 78


My Contributions
I'm trying to make a game, pretty much a game like memory where you flip over a card and find the match. But because of how many buttons I need I was wondering if it was possible to show the picture in a message, all the pictures are funny motivational posters from photobucket so I want the player to be able to read the dialog. I've already tried doing
CODE
Dim picture as string = "1.jpg"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(picture)
    End Sub

but when I click the button nothing happens and yes the name of the picture in my bin folder is "1". I am using Microsoft Visual Basic 2008 Express Edition.

This post has been edited by supaapple: 9 Jan, 2009 - 04:39 PM

User is offlineProfile CardPM
+Quote Post


AdamR

RE: Image In A Message Box?

9 Jan, 2009 - 04:53 PM
Post #2

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
As far as i am aware as a 2005 user, it is not possible to load a image directly into the message box function. You could however, create a custom message box, something along the lines of

Button Click
CODE


        img = Image.FromFile("c:\Myfile\Images\myimage.bmp")
       msgbox(img, msg)


Then try writing a sub named custom message box ... along the lines of

CODE

public sub msgbox(byval img as image, byval msg as string)

        Dim frm As New Form
        Dim pbx As New PictureBox
        Dim lbl Text As New Label
        Dim btn As New Button

        With frm
            .MinimizeBox =
            .MaximizeBox =
            .Width =
            .Height =
            .AutoSize =
        End With


        frm.ShowDialog()
end sub


Obviously the values need filling in, there an example, and use the same With...EndWith for each of the others, pbx, lbl, btn to customise them as needed, just explore the options, there the same as you get using a control you can see smile.gif

Hope this helps!
User is offlineProfile CardPM
+Quote Post

supaapple

RE: Image In A Message Box?

9 Jan, 2009 - 05:13 PM
Post #3

D.I.C Head
**

Joined: 21 Feb, 2008
Posts: 78


My Contributions
Great, thanks smile.gif The only problem I am having is with the words img, and msg in the part
CODE
msgbox(img, msg)
blink.gif and what do I dimension img as in
CODE
img = Image.FromFile("c:\Myfile\Images\myimage.bmp")
?

This post has been edited by supaapple: 9 Jan, 2009 - 05:16 PM
User is offlineProfile CardPM
+Quote Post

AdamR

RE: Image In A Message Box?

9 Jan, 2009 - 05:21 PM
Post #4

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Just realised i missed that bit.

CODE

dim img as image



and as for the img msg bit, you can use one of:

CODE


msgbox(img, "Type out message like this")

'or use
dim msg as string
msg = "your message here"
msgbox(img, msg)


Um you may also want to change the sub name and calling from msgbox to like custommsgbox or something, because it will clash with the built-in msgbox function smile.gif
User is offlineProfile CardPM
+Quote Post

supaapple

RE: Image In A Message Box?

9 Jan, 2009 - 06:38 PM
Post #5

D.I.C Head
**

Joined: 21 Feb, 2008
Posts: 78


My Contributions
Well I got the message box to open but no picture is showing. my code is
CODE
  Public Sub msgbox(ByVal img As Image, ByVal msg As String)

        Dim frm As New Form
        Dim pbx As New PictureBox
        Dim lblText As New Label
        Dim btn As New Button

        With frm
            .MinimizeBox = 0
            .MaximizeBox = 0
            .Width = 800
            .Height = 800
            .AutoSize = False
        End With


        frm.ShowDialog()
    End Sub

    Dim img As Image

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        img = Image.FromFile("D:\Pics\Stuff\002bhk7xqh9.jpg")
        msgbox(img, "Jay rules")

    End Sub


This post has been edited by supaapple: 9 Jan, 2009 - 06:38 PM
User is offlineProfile CardPM
+Quote Post

AdamR

RE: Image In A Message Box?

10 Jan, 2009 - 02:22 AM
Post #6

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Hey, what i posted last night (half asleep) was only half done, you needed to do the extra with...end with statements for each of the other controls, something along the lines of (change values to suit your needs)

CODE


'This is untested, so you know

       With pbx
            .Parent = frm
            .Left = 15
            .Top = 15
            .Width = 130
            .Height = 150
            .Image = img
            .SizeMode = PictureBoxSizeMode.StretchImage
        End With

        With lblText
            .Parent = frm
            .Left = 170
            .Top = 60
            .Width = 100
            .Height = 10
            .Text = msg
            .TextAlign = ContentAlignment.MiddleCenter
        End With

        With btn
            .Parent = frm
            .Left = 170
            .Top = 120
            .Width = 75
            .Height = 20
            .Text = "Ok"
            .DialogResult = DialogResult.OK
        End With




As i commented, i havent tested this code with those values, so you made need to change them if the messagebox looks wrong.

Also, set frm.MinimizeBox and frm.MaximiseBox to False or True, its a boolean option smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:03PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month