I have a form with a floating gridview that must appear when filling a textbox or clicking on a button. If item selected or mouse leaving grid, grid becomes invisible so user can see rest of the form. Grid data most cases exceed maximum vertical size, so a vertical scrollbar is needed. My problem is that when mousing to vertical scrollbar triggers MouseLeave event, so grid becomes invisible.
This time I think it's not a code matter, so is there some property to change to make the program identify vscrollbar as part of the GridView? Or else is there some code solution to ignore MouseLeave event when mousing to scrollbar?
Here is my event code, pretty simple:
Private Sub GridCliente_MouseLeave(sender As Object, e As System.EventArgs) Handles GridCliente.MouseLeave
GridCliente.Visible = False
End Sub
Also, I'm using Component One C1TrueDBGrid instead of standard gridview. It may be important.
I found a solution to my problem by adding the GridView to a panel and changing the MouseLeaveevent to the panel. For this to work, the panel must exceed the GridView size at least one pixel each side, since MouseLeave will not trigger if GridView is the same size of the panel (you must mouse over the panel and not any other component inside it to have vb.net consider mouse inside panel). Maybe it's not the best solution but it works for me.
Related
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
I just want to resize a certain Control in a Panel at the certain point when the vertical ScrollBar of the Panel is appeared due to need of scrolling.
Panel.Resize or Panel.SizeChanged is not exactly what I wanted because it is called whenever the size of the Panel is changed rather than exact point when the inside of the Panel size is changed due to the Panel get a ScrollBar width.
The ClientSizeChanged event will fire. You could detect that the scrollbar became visible with code like this:
Private Sub Panel1_ClientSizeChanged(sender As Object, e As EventArgs) Handles Panel1.ClientSizeChanged
If Panel1.VerticalScroll.Visible Then
'' etc...
End If
End Sub
Beware that the event will fire multiple times. If you do anything to rearrange controls to make the scrollbar invisible again then beware that you'll induce a good deal of highly visible flicker.
Since there normally isn't anything that the user could do to resize controls, only your code does that, the much better alternative is to actively prevent the scrollbar from showing in the first place.
Basically, I'm just wondering whether it's possible to disable horizontal scrolling while leaving vertical scrolling enabled with a listview in VB.NET without having to make a new class for it.
Why? Well, purely aesthetic, my listview currently has a tiny bit of horizontal scroll in it, which doesn't make it worth the effort to make a new class just for that, although if it can be coded without too much effort, I'd be more than willing to do that.
PS: I'm working in Windows Forms
I often use ListView controls in Details view with a single column in order to provide a list with drag-and-drop functionality, which is lacking in the ListBox control. ListView works beautifully for this apart from its annoying habit of wanting to scroll horizontally. It's possible to get around this to a degree by setting the column width to a suitable value (typically 4 less than the ListView's width) but this won't render well if the look-and-feel changes and will fail completely if the control decides to add a vertical scrollbar at run-time.
The workaround I use (and I'll admit it doesn't cope with every situation) is this. First, configure a ListView with a single column (the name is arbitrary) and hide its header:
lvList.View = View.Details
lvList.FullRowSelect = True
lvList.Columns.Add("ColName")
lvList.Columns(0).Width = lvList.ClientSize.Width
lvList.HeaderStyle = ColumnHeaderStyle.None
Then handle the ListView's ClientSizeChanged event and use it to set the width of the column to the width of the client area (which is essentially the area the list body has to fill):
Private Sub lvList_ClientSizeChanged(ByVal sender As Object, ByVal e As EventArgs) _
Handles lvList.ClientSizeChanged
If lvList.Columns.Count > 0 Then
lvList.Columns(0).Width = lvList.ClientSize.Width
End If
End Sub
As the list contents change and the vertical scrollbar is added or removed, the ClientSizeChange event is fired and adjusts the width of the column so that it exactly fills the client area.
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.
From the post "Growing user control not updating"...
Using C#, .Net 2.0 in a Windows environment.
UserControl1 - draws cells to a bitmap buffer dependent upon NumberOfCells property
UserControl2 - panel contains UserControl1 which displays vertical scroll when necessary; also contains NumberOfCells which sets UserControl1's NumberOfCells.
Formf1 - contains NumericUpDown controls (just increments) which updates the UserControl2 - suppose to!
When I increment the control on the form by say 20, UserControl1 adds the necessary cells, UserControl2 displays the vertical scroll bar accordingly, BUT the form does not 'redraw' to the updated/correct image!! Meaning, after I increment by 20, cells are added, vertical scrool bar added... but the image shown is just everything else expanding.
I reset the control to scoll to the very TOP and the scrolling works, but the image is still staic... UNTIL I resize my form, more specifically, when I change it from maximize to window or vice versa!!!
What can I do to 'reset/redraw' the correct image???? Thank you in advance.
Lawrence
If this is C# and Windows Forms I would try calling Update() or Refresh() on the control to make it redraw itself.
Try calling Refresh in the Scroll events and the NumberOfCells Property.