locked
Help!! RRS feed

  • Question

  • I'm doing a project. What i want to do is , If I click 'Next' button, if the picture box is empty, It will show a message box that show("Upload your picture first") and if the picture box contain picture , it will go to the next form. But it didn't happen. My lecturer said it was something wrong with my If Else Statement. Can you help me with it?This is my project and its really mean a lot to me!!
    Tuesday, December 4, 2018 3:58 AM

All replies

  • Can you help me with it?

    I'm sure someone here can help you, but only if we see your code.

    - Wayne

    Tuesday, December 4, 2018 4:22 AM
  • Hi,

    Is your code like this?

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If PictureBox1.Image Is Nothing Then
                PictureBox1.Image = Image.FromFile("D:\test.png")
            Else
                Me.Hide()
                Form2.Show()
            End If
    
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 4, 2018 5:19 AM
  • One option is to not use a MessageBox but instead place a image into the picture box indicating what they need to do.

    Requires a PictureBox and two buttons.

    Public Class Form1
        Private _pinvalidImage As Image
    
        ''' <summary> 
        ''' Responsive for creating a error image 
        ''' </summary> 
        ''' <param name="pMessageText">Message to display in image</param> 
        ''' <param name="pFontName">Font for pMessageText</param> 
        ''' <param name="pFontSize">Font size for pMessageText</param> 
        ''' <param name="pBackColor">pMessageText back color</param> 
        ''' <param name="pForeColor">pMessageText fore color</param> 
        ''' <param name="pWidth">Image width</param> 
        ''' <param name="pHeight">Image height</param> 
        ''' <returns></returns> 
        Private Function ConvertTextToImage(pMessageText As String,
                                            pFontName As String, pFontSize As Integer,
                                            pBackColor As Color,
                                            pForeColor As Color,
                                            pWidth As Integer,
                                            pHeight As Integer) As Bitmap
    
            Dim bmp As New Bitmap(pWidth, pHeight)
    
            Using graphics As Graphics = Graphics.FromImage(bmp)
                Dim font As New Font(pFontName, pFontSize)
                graphics.FillRectangle(New SolidBrush(pBackColor), 0, 0, bmp.Width, bmp.Height)
                graphics.DrawString(pMessageText, font, New SolidBrush(pForeColor), 0, 0)
                graphics.Flush()
                font.Dispose()
                graphics.Dispose()
            End Using
    
            Return bmp
    
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            _pinvalidImage = ConvertTextToImage(Environment.NewLine & "Upload an image first", "Arial",
                                                20, Color.Red, Color.White, 300, 200)
    
            PictureBox1.Tag = "init"
            OpenFileDialog1.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory
    
        End Sub
        Public ReadOnly Property InvalidImage() As Image
            Get
                Return _pinvalidImage
            End Get
        End Property
        Private Sub cmdNextAction_Click(sender As Object, e As EventArgs) Handles cmdNextAction.Click
            Dim imageStates = {"init", "empty"}
            If imageStates.Contains(PictureBox1.Tag.ToString()) Then
                PictureBox1.Image = InvalidImage
            Else
                MessageBox.Show("Picture is loaded do next action")
            End If
        End Sub
        Private Sub cmdLoadImageFromFile_Click(sender As Object, e As EventArgs) Handles cmdLoadImageFromFile.Click
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
                PictureBox1.Tag = "loaded"
            End If
        End Sub
    End Class
    

    Click next button without an image.

    Load an image

    Do next again


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, December 4, 2018 11:11 AM