how can i zoom an image inside a picturebox? and i also want to know how can i make a picture inside the picturebox draggable while at the same time, it can be zoomed in and out.
my goal is to crop an image inside the picturebox and i can zoom and drag the image inside if necessary, thanks :)
Uncommented but free code to draw a zoomed image in a picture box with a trackbar. :)
Public Class Form1 Private TheImageOpened As Bitmap Private TheImageRectThatCanBeManipulated As Rectangle Private TrackBarCenter As Integer = 8 Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. TrackBar1.Minimum = 1 TrackBar1.Maximum = 16 TrackBar1.Value = TrackBarCenter End Sub Private Sub ButtonOpenTheImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOpenTheImage.Click Dim OpenFileDialog As New OpenFileDialog OpenFileDialog.Filter = "Image Files|*.png;*.jpg;*.bmp" OpenFileDialog.FilterIndex = 0 OpenFileDialog.RestoreDirectory = True 'Fix Bad logic in Xp that will cause 'Environment.CurrentDirectory 'My.Application.Info.DirectoryPath 'to retrieve the directory of the path opened from this dialog instead of 'the app directory. If OpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then TheImageOpened = New Bitmap(OpenFileDialog.FileName) TheImageRectThatCanBeManipulated = New Rectangle(Point.Empty, TheImageOpened.Size) PictureBox1.Invalidate() End If OpenFileDialog.Reset() OpenFileDialog.Dispose() End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint If TheImageOpened IsNot Nothing Then e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic e.Graphics.DrawImage(TheImageOpened, TheImageRectThatCanBeManipulated) End If End Sub Private Sub TrackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.ValueChanged If TheImageOpened IsNot Nothing Then TheImageRectThatCanBeManipulated.Width = TheImageOpened.Width * (TrackBar1.Value / TrackBarCenter) TheImageRectThatCanBeManipulated.Height = TheImageOpened.Height * (TrackBar1.Value / TrackBarCenter) PictureBox1.Invalidate() End If End Sub End Class
Edited 5 Years Ago by Unhnd_Exception: n/a
OMG Unhnd_Exception, that was great! thanks! theres one more thing, how can i make the image inside the picturebox draggable while it can be zoomed in and out? because i want a certain part of the image cropped and zoomed, thanks for your answer! youre an angel! :)
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...