i would like to allow the user to play around with the size of the trackbar in vb.net. is there an easy way to do this?
i want to clarify that i would like the user to be able to just resize the trackbar by dragging it just like in design mode.
You can assign a new size of the trackbar like this:
TrackBar1.Size = New Point(newwidth, newheight)
One way to handle the user interface you mentioned would be to use mousemove, mouseup, and mousedown events of the trackbar.
When you get a mousemove trackbar event with the left mouse button up, you could change the cursor depending on whether it's near an edge (left-right arrows for left or right edge, up-down arrows for top or bottom edge), near a corner (diagonal arrows), or elsewhere in the middle of the trackbar (4 arrows).
When you get a mousedown trackbar event, save the location. If it's near an edge or corner, you will be stretching the edge or the corner of the trackbar. If it's in the central area, you'll be moving it (if that's an option).
When you get a mousemove trackbar event with the left button down, move and/or resize the trackbar using the trackbar size and location properties. Compare the current location with the one you saved at the mousedown event, and stretch or move that distance. Perform the resize and/or relocate according to the current operation as defined by the location in the previous mousedown event (edge stretch, corner stretch, or move). You can either draw a rectangle or resize the trackbar at this point, whichever looks better to you.
When you get a mouseup event, finalize the operation by setting the new trackbar size and location.
Related
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.
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
Actually I'm creating a simple paint application in VB.Net 2010. I want to draw shapes in my application same as we do in Microsoft Paint using mouse.
I'm a bit successful also using mousedown and mouseup events of a picture box. The mousedown event sets the starting point and mouseup event sets the ending point(diagonally opposite point of rectangle.) The problem is "Nothing seems to be occuring between mousedown and mouseup events(Well..that is obvious because I didn't add any code on mousemove event). My question is: "Can I do something to see a growing rectangle during mousemove event?". The rest of the drawing should remain unaffected. Thanks!! :)
You need to cache the image before you begin rectangle drawing (first thing you do in mousedown). then in mousemove you use that start point and the mouse location to construct a rectangle and draw it to a new bitmap (draw the cached image first, then layer the rect on top), then show the new bitmap in your pic box. finally in mouseup you set a flag that indicates that mousemove should not be doing anything (until mousedown again).
Sometimes, I have a picturebox lets say 100x100. But the image it will display is actually 100x400.
I don't want to increase the size of the picturebox itself. Instead, I would like to create a vertical scrollbar (or horizontal if needed).
I could not find a scrollbar in the toolbox, so I guess I have to code it. But, how?
And I still wonder if I didn't make a mistake and didn't see the scrollbar in the toolbox. My apologies then :(
I suppose you could add separate scrollbar controls and sync their Scroll events up with the offset at which the picture in the PictureBox is drawn, but that sounds like actual work. There's a better way.
Add a Panel control to your form, and set its AutoScroll property to "True". This will cause the control to automatically show scrollbars when it contains content that lies outside of its currently visible bounds. The .NET Framework will take care of everything for you under the covers, without you having to write a single line of code.
Drag and drop your PictureBox control inside of the Panel control that you just added. The Panel control will then detect that one of its child controls is larger than its visible area and show scrollbars, thanks to the AutoScroll property. When the user moves the scrollbars, the portion of the image in your PictureBox that is visible will be automatically adjusted. Magic.
(The reason you have to use a Panel control as a container is because PictureBox does not inherit directly from the ScrollableControl base class, which is what provides the AutoScroll property.)
I tried this and it worked well. But I noted that if the picturebox is docked in the panel, the picturebox is automatically set to the size of the parent panel, and can't be set larger (at least not in any way I could find). This defeats the purpose of the technique. So -- put the picturebox on the panel, but don't dock it, and it will work perfectly.
There are no automatic scroll bars on a picture box, but you can add the VScrollBar (and HScrollBar) control to the form and handle the image scrolling manually by redrawing it at a different offset each time the Scroll event is fired.
I need to create a quick-n-dirty knob control in Visual Basic 2005 Express, the value of which is incremented/decremented by "grabbing" it with the mouse and moving the cursor up/down. Because the knob itself doesn't move, I need to keep tracking the mouse movement outside of the rectangle of the control.
I use a Label with an ImageList to implement this (I have a list of 127 bitmaps representing the knob in various positions).
Which events should I react to?
You need the control to handle three events: Mouse Down, Mouse Move and Mouse Up. On the Mouse Down event, you will need to capture the mouse. This means the mouse messages are sent to the control that has the capture. In the mouse move event, if the input is captured then update the displayed image depending on the amount the mouse moved. In the mouse up event, release the capture if the input is captured.
The boolean jjnguy suggests is unnecessary as the Capture property of a Control is readable so it's possible to determine if the capture has been set.
Your problem will be to determine which bitmap you have to display based upon the coordinates the mouse reports in the mouse_move event. You'll need to perform some magic to transform the coordinates and come up with a value that you can use to pick the right image.
It doesn't sound too complicated, just a little bit of trial and error in the math. Skizz has already show you how to capture the events.