My report is an image in a picturebox. I want it so if the user clicks on it it will zoom larger --- while the picturebox remains the same size. That's important. The examples I've found for picturebox zooming cause the picturebox to get bigger and smaller. I need it to be like an Access report. Click on the report and it gets bigger. Click again and it goes back to the full image. Of cours when you're zoomed in, the perimeter of the report is not visible. So I'd like to be able to drag the image as well so the unseen portions can be seen. Does anyone know of an example or tutorial in VB.Net for this type of picturebox function?
Re: Zoom picturebox with static edges (for report)
here's a custom control that zooms the image when you doubleclick it + allows you to drag the image.
needs a bit more work on the location after resizing:
vb Code:
Imports System.Runtime.InteropServices
Public Class dragMoveZoomPicturebox
Inherits Panel
<DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
<DllImport("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
Re: Zoom picturebox with static edges (for report)
Put the PictureBox inside a Panel and set the Panel's AutoScroll property to True. Then use one of the methods you already have for zooming the picture box complete with the image. Only the part of the PictureBox which is inside the panel will be visible. The panel will show scroll bars when necessary to allow the image to be scrolled.
Re: Zoom picturebox with static edges (for report)
I tried putting the picture in a panel and made the changes in the program but there's a problem. When the picturebox is clicked the previous image on the upsized picturebox is upsized correctly but it is cut off on the right and on the bottom.
Now the picturebox is inside a panel. On clicking the picturebox, the height and width of the picturebox are doubled, causing scroll bars to appear, and the contents of the picture box are regenerated with an adjusted font size and adjusted coordinates. The part that does appear is correct. But it is cut off on the right and on the bottom.
This is the code that prints one of the lines which is cutoff on the right:
Code:
Try
gr.DrawString(text, New Font(printFont, printFontSize, printfontstyle, GraphicsUnit.Pixel), printbrush, xadjusted, yadjusted)
Finally
gr.Dispose()
End Try
The field text contains a string of characters. In the upsized picturebox the text from text gets cut off on the right. It's cutoff about 4/5 of the way over. The area that's okay is still larger that the original picturebox. That's what's so strange about it. The original report prior to clicking the picturebox appears okay. Any idea why it's doing this? Unless I'm wrong, the DrawString prints the given text at the given coordinate. There is no end point specified. Why should it just quit at some point?
Last edited by projecttoday; Jul 10th, 2011 at 02:06 AM.
Re: Zoom picturebox with static edges (for report)
@ProjectToday. (EDIT) What happens when you leave out the Try-End Try? It may be masking some coding error. Apart from that, it will be hard to help without seeing more code and maybe a screenshot.
@.Paul. Of course, the method I mentioned is similar in broad respects to your class: a PictureBox in a Panel. The main difference is that I suggest using the Panel scroll bars instead of Interop to drag the picture box. It may not work as smoothly in some circumstances but it is simpler.
BB
Last edited by boops boops; Jul 10th, 2011 at 03:39 AM.
Reason: second thoughts
Re: Zoom picturebox with static edges (for report)
I took a look at .Paul.'s post but was concerned about trying something which he says "needs a bit more work".
Unfortunately when I took out Try, End, Finally the result was the same. This is the subroutine which prints the line which is cut off on the right
Code:
Private Sub Println(ByVal text As String, ByVal x As Single, ByVal y As Single, _
ByVal printFont As String, ByVal printfontstyle As FontStyle, _
ByVal fontsize As Single, ByVal brushcolor As Color, _
ByVal printstatus As String, ByVal gr As Graphics, ByVal ev As PrintPageEventArgs)
Dim printbrush As Brush
printbrush = New SolidBrush(brushcolor)
Dim printFontSize As Double, xadjusted As Single, yadjusted As Single
If printstatus = "preview" Then
' the parameters must be adjusted to fit the size of the output
printFontSize = fontsize * dRatio 'scale font size for picture box
xadjusted = x * dRatio
yadjusted = y * dRatio
'Try
gr.DrawString(text, New Font(printFont, printFontSize, printfontstyle, GraphicsUnit.Pixel), printbrush, xadjusted, yadjusted)
'Catch exc As Exception
'MsgBox(exc.Message)
'Finally
'gr.Dispose()
'End Try
ElseIf printstatus = "print" Then
Dim prntfont As Font = New System.Drawing.Font(printFont, fontsize, _
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
ev.Graphics.DrawString(text, prntfont, printbrush, x, y)
End If
printbrush.Dispose()
End Sub
str contains "abcdefghijklmnopqrstuvwxyz1234567890" and this appears in the picturebox before the upsizing. After the upsizing only abcdefghijklmnopqrstuvwxyz12" appears even though there's plenty of room for the rest of it and the full string makes it into the subroutine (I checked). The entire rest of the document is cut off at that same point and it is also cut off at the bottom.
2.84 is the number of inches from the left the line appears (on the actual paper) and 0.8 is the number of inches from the top the line appears.
Re: Zoom picturebox with static edges (for report)
Are you sure the bitmap is getting resized correctly to match the PictureBox when you zoom it? You could check that quickly by giving the bitmap a contrasting background colour. For example, you could add this line for testing purposes (before gr.DrawString):
Code:
gr.Clear(Color.Red)
I have to come back on my suggestion of using the Panel scrollbars to scroll the PictureBox. I haven't been able to get it to work really well -- the scrollbars themselves cause lots of jerking and flashing. So it would be better to drag the PictureBox with the mouse, and that comes down to practically the same as .Paul's method (although there are other ways of dragging). I suspect a "bit more work" refers the adjustments needed to keep the Image centred reliably during zooming.
In fact I already have made a custom image zoom/pan control. Everything works perfectly, including zooming to the cursor position. At present it's overcomplicated (too many options) but I think I could boil it down to essentials. Zooming and dragging are done by changing the size and position of a rectangle, and the image is painted into that rectangle. Let me know if you are interested.
Re: Zoom picturebox with static edges (for report)
The red does the same thing. It's cut off on the side and the bottom.
This picturebox was actually downsized once earlier. The original was a larger form. I decided to reduce the size of the form and the picture box and because the code multiplies everything by a scaling factor it worked. But the image is too small to see detail. So I decided to add a click to upsize it. The current viewable area of the upsized image looks suspiciously like the size of the old/original picturebox.
In any case it must be a setting somewhere but I can't find it. I am not at all expert in VB.Net drawing code.
The scroll bars are working fine.
Also, the hard copy print works fine.
Last edited by projecttoday; Jul 10th, 2011 at 02:54 PM.
Re: Zoom picturebox with static edges (for report)
Originally Posted by projecttoday
The red does the same thing. It's cut off on the side and the bottom.
This picturebox was actually downsized once earlier. The original was a larger form. I decided to reduce the size of the form and the picture box and because the code multiplies everything by a scaling factor it worked. But the image is too small to see detail. So I decided to add a click to upsize it. The current viewable area of the upsized image looks suspiciously like the size of the old/original picturebox.
In any case it must be a setting somewhere but I can't find it. I am not at all expert in VB.Net drawing code.
The scroll bars are working fine.
Also, the hard copy print works fine.
Well I'm sorry, I can't find it either. I wonder why? BB
Re: Zoom picturebox with static edges (for report)
I'm sorry if I was sarcastic. I have to guess that you are using the bitmap as the PictureBox.Image. It's clear that your bitmap is smaller than you expect. You haven't said how you are resizing the PictureBox or how you are setting the size of the bitmap. How can anyone debug that if you don't show the relevant code?
The normal (simple) approach is to set the PictureBox.SizeMode to AutoSize and zoom by changing the size of its Image. Have you tried it that way?
Re: Zoom picturebox with static edges (for report)
Autosize didn't work. I'm doing my own zooming and it works. It's just cut off for some reason. This is the code
Code:
Picturebox1.Height =* 2
standardratio = 8.5 / 11.0
pictureboxheight = PictureBox1.Height
PictureBox1.Width = pictureboxheight * standardratio
pointsperinch = 98
'scale the report on the screen to an 8.5 by 11 sheet of paper
dRatio = (pictureboxheight / pointsperinch) / 11.0
Re: Zoom picturebox with static edges (for report)
Originally Posted by projecttoday
1. Everywhere. Everything, including the fonts, gets multiplied by dRatio.
Everywhere? That's tough, because it's where you need to look to find what you are doing wrong. My psychic debugging powers have run out for today. If you want someone to help you, I suggest you take the time to figure out what code shows exactly what you are doing and post it. BB
Re: Zoom picturebox with static edges (for report)
You may find it interesting to try out the ZoomPictureBox control I have just posted to the VB.Net code bank. The approach is clearly different from what you are doing but maybe it would serve your purposes. BB
Re: Zoom picturebox with static edges (for report)
Thanks for your trouble but my form is basically working except for some reason the drawing is clipped off. When I get a chance I'm going to recreate the whole thing, checking it along the way, and that will probably solve the problem. In the meantime I'm using a zoom factor of 1.5 instead of 2.