Results 1 to 10 of 10

Thread: [RESOLVED] autofit image in multi picturebox and then clicked pop up full size image in VB.NET

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Resolved [RESOLVED] autofit image in multi picturebox and then clicked pop up full size image in VB.NET

    Dear All master,
    please the solution I want the best autofit image in multi picturebox and then I clicked the picturebox then a full-size pop-up image appeared according to the original image size

    Can pop up be done with the mouse and keyboard keys?.
    for information i use visual studio 2010.

    Thanks
    roy88

    Code:
    Public Class Form1
    
        Dim Path As String = "C:\Users\Administrator\Desktop\DBF"
        Dim Pathimage As String = "C:\Users\Administrator\Desktop\CATALOG"
        Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
    
        Private Sub PopulateDataGridView()
            Try
                Dim dt = New DataTable()
    
                Dim query = "select ITM,ITC,QOH,PRS,FILENAME1,FILENAME2,FILENAME3,FILENAME4 FROM ITEM"
    
                Using adapter As New OleDbDataAdapter(query, cn.ToString)
                    adapter.Fill(dt)
                End Using
    
                Me.DataGridView1.DataSource = dt
    
                For x as integer = 4 to 7
                    Me.DataGridView1.Columns(x).Visible = False 
                Next
    
                exPictureBox1.PrePath = Pathimage & "\" 
                exPictureBox2.PrePath = Pathimage & "\"
                exPictureBox3.PrePath = Pathimage & "\"
                exPictureBox4.PrePath = Pathimage & "\"
    
                exPictureBox1.DataBindings.Add("FileName", dt, "FILENAME1")
                exPictureBox2.DataBindings.Add("FileName", dt, "FILENAME2")
                exPictureBox3.DataBindings.Add("FileName", dt, "FILENAME3")
                exPictureBox4.DataBindings.Add("FileName", dt, "FILENAME4")
    
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
            End Try
        End Sub
    
    End Class
    Attached Images Attached Images   

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    So you’re looking for thumbnail images that can be viewed at full size. What if full size is unreasonably large? Wouldn’t it be better to resize them all to a uniform size, whatever the original size is?

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Seems simple enough.
    If you set the picturebox's Sizemode to Zoom the image will be scaled to fit proportionally within the picturebox, so that can give you your samesized thumbnail type images.
    If you select one to show at full size, then just set the sizemode of a "fullsize" picturebox to AutoSize, and the picturebox will be sized to fit the image, so you see the full size image.

    But as Paul says, perhaps what you really would want is the option to scale in both directions, so use Zoom mode in all the pictureboxes, and just use a large picturebox to show a large size version of the smaller pictureboxes.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Quote Originally Posted by .paul. View Post
    So youÂ’re looking for thumbnail images that can be viewed at full size. What if full size is unreasonably large? WouldnÂ’t it be better to resize them all to a uniform size, whatever the original size is?
    Dear Mr. .paul.

    thanks for your reply. I agree with your suggestion to resize everything to a uniform size in the picture box and I want to click the picturebox then the picture appears in the preview panel.
    how to code solution?
    Thanks
    roy88

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Set the exPictureBox1-4 SizeMode to Zoom (in the designer) as passel told you, then add a larger standard PictureBox set Name to largerPictureBox and set SizeMode to Zoom.
    Then...

    Code:
    Private Sub exPictureBoxs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exPictureBox1.Click, exPictureBox2.Click, exPictureBox3.Click, exPictureBox4.Click
        largerPictureBox.Image = DirectCast(sender, exPictureBox).Image
    End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Quote Originally Posted by .paul. View Post
    Set the exPictureBox1-4 SizeMode to Zoom (in the designer) as passel told you, then add a larger standard PictureBox set Name to largerPictureBox and set SizeMode to Zoom.
    Then...

    Code:
    Private Sub exPictureBoxs_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exPictureBox1.Click, exPictureBox2.Click, exPictureBox3.Click, exPictureBox4.Click
        largerPictureBox.Image = DirectCast(sender, exPictureBox).Image
    End Sub
    Dear Mr. .paul.
    thanks for your reply.

    I tried according to your suggestion and the code runs perfectly and I set largerPictureBox to normal but the problem is that if I make a selection in the row datagridview exlargepicturebox still exists if I click on the picturebox then the exlargepicturebox changes with the image. So can the exlargepicturebox be blank when switching row selection in datagridview?
    Thanks
    roy88

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Add this, at Form level...

    Code:
    Private WithEvents dt As New DataTable
    Then instead of...

    Code:
    Dim dt As New DataTable
    Use...

    Code:
    dt =New DataTable
    And add this Handler...

    Code:
    Private Sub dt_RowChanging(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles dt.RowChanging
        largerPictureBox.Image = Nothing
    End Sub

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Quote Originally Posted by .paul. View Post
    Add this, at Form level...

    Code:
    Private WithEvents dt As New DataTable
    Then instead of...

    Code:
    Dim dt As New DataTable
    Use...

    Code:
    dt =New DataTable
    And add this Handler...

    Code:
    Private Sub dt_RowChanging(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles dt.RowChanging
        largerPictureBox.Image = Nothing
    End Sub
    Code:
     Private WithEvents dt As New DataTable
    
        Private Sub dt_RowChanging(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles dt.RowChanging
            largerPictureBox.Image = Nothing
        End Sub
    I use above code but below dt variable I use below this code
    Code:
     Private Sub PopulateDataGridView()
    
    
            Try
                Dim dt = New DataTable()
    
                Dim query = "select ITM,ITC,QOH,PRS,FILENAME1,FILENAME2,FILENAME3,FILENAME4 FROM ITEM"
    
                Using adapter As New OleDbDataAdapter(query, cn.ToString)
                    adapter.Fill(dt)
                End Using
    
                Me.DataGridView1.DataSource = dt
    
                For x As Integer = 4 To 7
                    Me.DataGridView1.Columns(x).Visible = False
                Next
    
                ExPictureBox1.PrePath = Pathimage & "\"
                ExPictureBox2.PrePath = Pathimage & "\"
                ExPictureBox3.PrePath = Pathimage & "\"
                ExPictureBox4.PrePath = Pathimage & "\"
    
                ExPictureBox1.DataBindings.Add("FileName", dt, "FILENAME1")
                ExPictureBox2.DataBindings.Add("FileName", dt, "FILENAME2")
                ExPictureBox3.DataBindings.Add("FileName", dt, "FILENAME3")
                ExPictureBox4.DataBindings.Add("FileName", dt, "FILENAME4")
    
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
            End Try
        End Sub
    is there a solution without removing the code that I marked in red?

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Change the red highlighted line to…

    Code:
    dt = New DataTable

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: autofit image in multi picturebox and then clicked pop up full size image in VB.N

    Quote Originally Posted by .paul. View Post
    Change the red highlighted line to…

    Code:
    dt = New DataTable
    Dear Mr. .paul.
    thank you very much. You are my teacher. Sorry I'm late to reply. I mark my post resolved and rate my post to you.
    Thanks
    roy88

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width