Fit Image into PictureBox

前端 未结 9 781
栀梦
栀梦 2020-12-15 14:43
using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
    myDatabaseConnection.Open();
    using (SqlCommand SqlComma         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 15:37

    I have routine in VB ..

    but you should have 2 pictureboxes .. 1 for frame .. 1 for the image .. and it make keep the picture's size ratio

    Assumed picFrame is the image frame and picImg is the image

    Sub InsertPicture(ByVal oImg As Image)
        Dim oFoto As Image
        Dim x, y As Integer
    
        oFoto = oImg
        picImg.Visible = False
        picImg.Width = picFrame.Width - 2
        picImg.Height = picFrame.Height - 2
        picImg.Location = New Point(1, 1)
        SetPicture(picPreview, oFoto)
        x = (picImg.Width - picFrame.Width) / 2
        y = (picImg.Height - picFrame.Height) / 2
        picImg.Location = New Point(x, y)
        picImg.Visible = True
    
    End Sub
    

    I'm sure you can make it as C# ....

提交回复
热议问题