I am working on an application that works as a dashboard. The form includes a flowlayoutpanel that contains several datagridviews. The flowlayoutpanel is set to autoscroll because there are usually more datagrids than will fit on the visible page. Each datagrid has a buttonclick event that opens a chart form when a particular column (3) is selected. All of the chart functionality works fine. The problem I'm having is that when I click a datagrid that is only partially visible, the page scrolls to bring that datagridview completely onto the page. Because that happens on the click (MouseDown), the page scrolls so quickly that it doesn't actually trigger the clickevent, but selects several cells in the column, as if the user did a click/drag down the column.
What I would like to have happen is when the user clicks on a datagridview that is only partially visible, the chart would open, then the page would scroll on the chart close event. That actually happens if the datagridview in question has focus, but is partially off the page. For example, if I selet the datagridview, then scroll down/up until it is partially off the visible page, then click a cell in column 3. It will display the chart, then autoscroll when I close the chart. But if the datagridview does not have focus, it does the autoscroll thing. I have tried putting the flowlayoutpanel inside another panel, and that worked to some degree, but it was inconsistent.
Sorry for the long description, but I'm trying to be as detailed as possible. Any help would be greatly appreciated. The application is being built in .NET, using VS 2013.
This seems similar to a issue I had with multiple datagridviews inside a panel, this article was the solution for me.
In short, all you need to do is create a custom panel and override the ScrollToControl method. I belive you can do the same with a FlowLayoutPanel.
EDIT:
Your CustomPanel class should look something like this (code converted with developer fusion
Public Class CustomPanel
Inherits System.Windows.Forms.FlowLayoutPanel
Protected Overrides Function ScrollToControl(activeControl As System.Windows.Forms.Control) As System.Drawing.Point
' Returning the current location prevents the panel from
' scrolling to the active control when the panel loses and regains focus
Return Me.DisplayRectangle.Location
End Function
End Class
If this doesn't work you could try inheriting a regular Panel and place a FlowLayoutPanel inside it.
Related
To boil the situation down, I have a panel with 3 textboxes on it. When I hide the panel, the first textbox in the tab order for the panel gets assigned to Me.ActiveControl (The form), regardless of which one was focused when the panel was hidden.
I thought a hidden control could never have focus. I have other controls on my form where the issue was originally found, so I thought it would have to choose a non hidden control to focus on. Is this a bug, or designed this way?
I use a timer on my simple form that fires every 5 seconds, recording the active control name in a label.
I have been able to recreate your scenario and it revealed an interesting possibility (more on this later).
WinForms has the concept of the Selected (or activated) control. The Control.Select Method is related to the Control.Focus Method. The Focus Method-Remarks section documentation is relevant.
A control can be selected and receive input focus if all the following
are true: the Selectable value of ControlStyles is set to true, it is
contained in another control, and all its parent controls are both
visible and enabled.
...
Focus is a low-level method intended primarily for custom control
authors. Instead, application programmers should use the Select method
or the ActiveControl property for child controls, or the Activate
method for forms.
The ContainerControl.ActiveControl Property points to the last selected control.
The reason that the first control by tab order in the Panel is selected is due to the code that executes when the Panel.Visible property is set to false. The Visible Property setter calls SetVisibleCore that in turn calls SelectNextIfFocused that calls SelectNextControlInternal that finally calls Control.SelectNextControl that selects the your TextBox1.
This is where it gets interesting. At this point the Panel and TextBox are both visible. Therefore, the TextBox receives focus and retains it when the Panel is hidden. This condition allows for a hidden TextBox to have keyboard input and no rules about a hidden control not being able to receive focus are violated.
I want to prevent my form from automatically scrolling when a control at the bottom is focused but still keep the scrollbars if they ever appear.
Since some users have a slightly lower screen's resolution than the form, the scrollbars do sometimes appear. This created a problem with some DataGridView. Since the AutoScroll option is enabled, when clicking the DataGridView, it does a multiselect since we click and it moves.
When I disable the AutoScroll property, the scrollbars go away. Therefore, the user can't see everything.
Is there a way to disable the AutoScroll, but still keep the scrollbar?
If I understand your situation correctly, you basically want the user to have the ability to scroll the form manually but prevent the form from scrolling automatically to the control that gets focused.
Put this code in your form:
Protected Overrides Function ScrollToControl(activeControl As Control) As Point
'Return MyBase.ScrollToControl(activeControl) ' <-- Keep this line commented.
End Function
Result:
I created an interface it has several forms you can switch between using a panel as the parent form. My problem is that when i switch between my forms on the second time i open a form if that form has autoscroll on a panel it will not allow you to scroll and the window is stuck on the view you previously had.
In this image i open the form internet. after doing so i will click on instruction( any form switch triggers this)
now i open the same form again and the scroll bar is gone and it locks in on the last position the form was in.
the very curious thing in this is that this only happens on the internet form word also has a scroll bar however even though the properties and settings for both are identical only one does not work.
What could be causing this and how do i go about troubleshooting errors like this.
The forms are removed from the panel and re-added, they are not closed.
Assumption 0:
The forms are removed from the panel and re-added, they are not
closed.
Store the state of panel autoscroll and set it after you have re-added it. Note that if you add controls to the panel first and panel is not docked, then scroll will not appear because panel dimensions can be huge. You should set following property as well:
vScrollBar1.Vericalscroll.Value = 0
Assumption 1:
I assume what is actually going on is that you do not add controls to that panel, but to the form behind it or something similar. In that case - program is correct, you just asked it to do a wrong thing.
Assumption 2:
Assuming is panel is anchored top, left, bottom, right. There is currently a limitation in Windows Forms that prevents all classes derived from ScrollableControl from acting properly when both RightToLeft is enabled and AutoScroll is set to True.
Manual : link
Assumption 3:
You add the controls back, by recreating them, but forget to add handlers or create them in order where scrollbar is out of view. Instead of absolute positions you could use dockstyle:
Dim vScrollBar1 As VScrollBar = New VScrollBar
vScrollBar1.Dock = DockStyle.Right
Controls.Add(vScrollBar1)
I am trying to make a transparent control with child controls that are visible and opaque.
I have added a panel control to the main form via code in the form load event. In this I am adding five buttons as child controls like: panel.controls.add(). To all of these, I have set backcolor=color.transparent.
When I run this program, the button background shows the background of the next button in the panel. If I open a child form, then I can see labels on the child form as the background of the panel.
I want to make container panel control completely transparent, so I can see the main form through it. How can this be achieved?
When the form loads, you can see neighbor buttons behind the actual buttons
"Perform Check" is a label on a child form which I opened right before taking this picture.
: "Check Cases and Combinations" is a button on a child form which I opened right before I took this picture.
How can I make it truly transparent? Why doesn't the background of the panel control refresh with the main form background? The panel sort of "keeps" whatever happens on the main form and shows it as a background.
I found out there some issues with setting controls that are transparent and on top of other controls in the main form. They take the background of the container form, whether or not there is any control in between. I used WPF form instead of the panel and it worked perfectly.
Please excuse my lack of familiarity with vb.net. Just got thrown on a project with no vb.net experience.
I have to add some things to an application that was written by somebody who is no longer in the picture. I have to add more textboxes into a groupbox and when I do that it exceeds the size of the form. How can I make it so that I can scroll through the groupbox?
GroupBox, as it doesn't derive from ScrollableControl, so itself can't have scrolling functionality.
So...
Place the GroupBox inside a panel, and set the panel AutoScroll to true.
Guides:
Adding a panel control
Setting properties (of anything)
Moving content is just simply selecting all the elements you want to move, and click and drag them into the new place.
You could set the AutoSize property of the groupbox to true, and then set the AutoScroll of the form to true as well. This should resize the groupbox so that everything in it is visible, and then the form will have a scrollbar. If you don't want to make your form have a scrollbar for some reason, then you could use a panel and set it's AutoScroll to True so that just the panel has a scrollbar.
Add a Panel with no border inside the GroupBox to group your controls (put the controls inside). Then:
Panel1.ScrollBars = ScrollBars.Vertical
Or even ScrollBars.Auto.
GroupBox doesnt have scrolling functionality itself. Most likely most simple solution here is to just put a Panel inside the groupbox and add the textboxes to the panel instead.