VB.NET: PictureBox view range? - vb.net

I two pictureboxes in my application: One that is mostly just a background image, and another which you can move around changing some settings.
However, depending on my settings (X,Y,Width,Height), a fragment or all of the second picturebox might be "out" of the first picturebox. I don't want that.
Basically, if there is anything in the second picturebox's that is not over the first picturebox, I don't want to show that fragment. I want to cut it.
If I move the second picturebox back inside the first picturebox, then I can see all of it again.
Think of the first picturebox as a "view range"

Fixed:
I set the second picturebox's parent to the first picturebox. Now the second picturebox is cut if it leaves the first picturebox's area.
Sorry for wasting your time :(

Take a look if these threads can help : 1 2

Related

ContextMenuStrip Location Point

How to open the ContextMenuStrip programmatically at the cursor on right mouse button down/clicked over PictureBox?
I need to open ContextMenuStrip only in some areas of an Image (Schedule) in a PictureBox, so I disconnected the PictureBox.ContextMenuStrip property from the ContextMenuStrip1 and I'm firing it manually. That means I need to provide a point, which appears to be surprisingly challanging.
My question is similar to "How to get location of ContextMenuStrip", but I need to account for both vertical and horizontal scrolling, which it doesn't (unless I messed something).
So when I'm trying something like this (in PictureBoxPlan.MouseDown):
Dim rpt As Point = Me.PointToClient(PictureBoxPlan.Parent.PointToScreen(e.Location))
...it has a fundamental flaw, because the e.Location is in context of Image, regardless how it is scrolled within the PictureBox. I tried to Form.MouseDown event, but it's not fired, when [right] clicked on a PictureBox.
Just for confirmation, I still need the point in PictureBox context to analyze whether the ContextMenuStrip should be shown or not and to lookup associated ID.
I am now trying to use some constants (may not work if windows "font size" is set to other than 100%) together with scroll bars values, which is not optimal at all.
OK, I found what is breaking the logic in the ContextMenuStrip.Show(Point) documentation:
Show(Point)
Positions the `ToolStripDropDown` relative to the specified screen location.
So the ContextMenuStrip, to my surprise, takes the screen coordinates, not the Form ones. I then just removed PointToClient and everything works as a charm, regardless of window position on the screen or scrollbars position of the Image container:
Dim rpt As Point = PictureBoxPlan.PointToScreen(New Point(e.Location.X, e.Location.Y))
No need to take into account PanelPlan.VerticalScroll.Value or PanelPlan.HorizontalScroll.Value.

Can PictureBox leave a ghost on a Form1 after moving it with a mouse?

I am moving pictureboxes on a Form1 via left-clicking on them and dragging them to another position. (i.e., using mousemove, mousedown, mouseup with e.X and e.Y). I also connect lineshapes from one picturebox to another using drag and drop. When dragging the end of a lineshape, however, I don't show the end of the lineshape when it's over a picture box -- indicating that it's ok to drop on a given picturebox.
Question is, after moving pictureboxes to desired positions, there are times when the end of a dragged lineshape disappears over a "ghost" or remnant of a picturebox, which is no longer there. Apparently, the control positions need to be updated any time I move a picturebox. So, after I move pictureboxes around, is there some sort of refresh I need to do on the Form1's controls, so the positions of pictureboxes are updated?
Yes you need to make custom class that inherits panel/picturebox class and at constructor level you need to say me.doublebuffered=true to prevent shadow of dragging picturebox/panel
Also at your code in mouse moving event you need to subtract the current coordinates of the panel from your cursor coordinates to have the image near your cursor

In VC++ 2013, dialog boxes damage PictureBox contents (drawing)

I cannot find how to protect a drawing in a PictureBox control from being corrupted (wiped out) when I call a dialog to save the form or print it out. The form is saved or printed out OK, but the dialogs wipe out most of the PictureBox drawing after they leave. Yet the buttons and progress bar on the form are restored OK -- so there must be a way to 'protect' the PictureBox drawing as well. How is it done?
The reason is that you need to repaint the picture box after the dialog has gone away.
Your picture box will get a Paint event, that will tell you that you need to do some re-drawing.
In there, use the supplied graphics contexts etc to draw on the picture box again. Probably you will want to write a separate method that does drawing, and call it for an initial view, and also during that paint. But that's up to you.
If you will always have olny one picture in your PictureBox, or you will be always using pictures with of same size you can just override OnEraseBkgnd function for this control and return TRUE on exit of this function.
This way content of your will not be altered by unplanned OnPaint or OnEraseBkgnd calls.

VB.NET: Scrollbar "button"?

I plan on using a scrollbar for, well, scrolling an image. The image is 200x500, however, the only visible area is 200x250.
So I set the max value to 250, and the min value to 0. The idea is that if I drag the scrollbar's button to the bottom, 250 pixels will have moved for the image, right?
But wait, the scrollbar's button is.... very small. And the scrollbar is actually pretty long. Is there a way to make the scrollbar's button longer?
How did you create this scrollbar? Is it a separate control all together, or it is a component of another control? I do know that scrollbars added separately act kinda funny at times.
What I would suggest is using the scollbars built into another container control, which should achieve the exact same effect.
Create a new panel control on your form, and name it. (I suggest something like panelPicture)
Position the panel where you want your picture to be.
Set the panel's size to 200x250.
Set the panel's "Autoscroll" property to True.
Put a PictureBox inside this panel, and name it. (I suggest something like picMyPicture.)
Set the PictureBox's position to 0, 0.
Set the PictureBox's size to 200x500 (or whatever is necessary).
Set the PictureBox's Image property as desired.
Now, the scrollbar should automatically appear on the picture, and it should look normal.
As a side note (which may or may not be relevant), users typically don't like having to scroll to see the rest of an image, so if you don't need the user to scroll down on the image for some definitive purpose (or because you don't know what the size of the image that will be handled is), I'd try and change the size of things on your form so scrolling will not be necessary.
I hope this helps!

Picture box goes blank

In VisualBasic.Net When I activate a picture box and then draw something on it, it draws and then immediately goes blank. Works fine when I re-draw it, but almost always messes up the first time I draw on it. This has happenned with several different programs, and the help file is no help.
Try setting the DoubleBuffered property
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx
If that's not it, please provide more info.
Usually, if you're drawing something on a picture box or on another control, you have to take over the OnPaint event, and you're responsible of persisting what you draw on this event.
Thank you Andrew, but no help. I'm using .Net Framework 1.1, which does not offer the DoubleBuffered property... it was new in 2.0.
Not sure what additional info to provide.. the code is 300 lines long. When a button is clicked, the code expands my form, makes two picture boxes visible (one on top of the other (the back one is for some graph labels), and then uses some graphic brushes and pens to draw a graph on the front box. There's some database activity and calculations going on in the background at the same time.
I assume you're using the standard PictureBox component. Do you draw in the Paint-Handler? If not then the PictureBox will just erase your painted stuff next time it's asked to redraw itself (erase background etc.).
Yes, I believe I am using the standard picture box.
By Paint-Handler, I assume you mean a [Control].PaintEvent Handler. No I'm not using an event handler to do the drawing... drawing my chart is not an event in itself, but part of a much larger response to a button click event.
If you are saying that having the drawing code be part of a separate and specific handler can solve my problem, than I guess I could raise an internal event every time I want to redraw the chart. But I Would rather just figure out what is causing the PB to redraw itself without being told to.
If you cannot use the DoubleBuffered than you can HIDE a second picture box. You do the drawing in it and once it's completed you draw back to the VISIBLE one. This way the process of drawing is done on the hidden one and the white/flickering will not be shown.