TableLayout vertical scrollbar pointing top most Row [duplicate] - c#

i have a panel in my winforms and in it i load some usercontrols .
i would like to autoscroll to the bottom of the panel( as my panel fills ) everytime a new usercontrol is added . How can i do so ?

You can do that by setting the VerticalScroll of the Panel but I think it would be better to use ScrollControlIntoView instead.
private void panel1_ControlAdded(object sender, ControlEventArgs e)
{
panel1.ScrollControlIntoView(e.Control);
}
Good luck!

You could use ScrollControlIntoView and pass the control you last added.
An alternate solution would be:
panel.VerticalScroll.Value = panel.VerticalScroll.Maximum

I found that continuously adding controls to the panel at vertical increments would be affected negatively whenever a user had scrolled the panel up or down. I used the tip from Homam above, and found the following to work well:
panel1.VerticalScroll.Value = 0;
// Creating and adding a TextBox, tb, to the panel
panel1.ScrollControlIntoView(tb);
So first, I scroll to the top in order to use absolute vertical positions for my text boxes, then I place the Text Box, and finally, I make sure that the newly created text box comes into view.

Related

Horizontal Scroll Bar Event

I have created an array of ListBox in which I have populated with some data from a text file. I want to change between each Listbox when the user scrolls either left or right so each one can be displayed. How would I go about doing this? I have populated my user interface with the first List-box Listbox(0).
I don't fully understand your question, but if you are trying to put the scrollbar to the left side of the listbox, you can set the RightToLeft property to true.
If you want to move from one ListBox to another the better control to use is a Slider then a ScrollBar

Having a certain layout when adding labels to a Panel

I have a WinForm with a Panel and I keep adding Labels to it. Is it possible to set the Panel so that everytime I add a label it will have a certain layout ? The layout I am looking for is having a single column of Labels, so everytime I add a new Label it will be added to the next row. I haven't found any property for the Panel to do that. Is this possible ?
Use FlowLayoutPanel instead of Panel. And set the FlowDirection property to TopDown
You can create a ListBox in the panel, and then add the Labels to it, rather than to panel directly.
Use a TableLayoutPanel and set its ColumnCount to 1.

Tabbing in a loop through a winform

I have an application where I have several forms. Its a C# windows-form based application build in .NET 4.O. I have several forms where the user enters the data. There are grids where data is displayed and whole lots of controls on the form. Believe me! its a mess of so many controls. I have to setup the TabIndex for each control. I have literally disabled the TabStop property of certain controls I don't want to be tabed into it. However, still once I go through the order I want, I TAB it, and it works but once it reaches the last box then it takes 3-4 times more tabbing to get to the first field. I tried disabling the TabStop property for the controls I don't want. But I think there might be certain controls that I don't see but they might be included in the Tab property.
My question is that is there any way that I can set the TabStop property of all the controls on the winform to false and then set it to true for the controls I want to include only.
I also open to if there is any other way I can implement this?
If further explanation is needed, let me know!
I have attached a picture thats the order I want and then loop back but somehow its not working. Just in addition there is also two panels in the form and I have disabled their TabStop property to False.
Go to View menu and click Tab Order. This will activate the tab-order selection mode on the form. TabIndex value will be displayed as a number on each control.
Click on controls in order you need them to be tabbed. This will set appropriate values for TabIndex of controls.
After you finished, go to View menu and turn-off Tab Order.
Select controls you don't want to be tabbed and set TabStop = false.
One simple explanation is that you lost a control underneath another one that overlaps it. Or it is located beyond the edges of the Form. A good tool to find it back is View + Other Windows + Document Outline.
If that doesn't help then diagnose it by adding a Label and a Timer. Write the Tick event handler like this:
private void timer1_Tick(object sender, EventArgs e) {
if (this.ActiveControl != null) label1.Text = this.ActiveControl.Name;
}
You should try the following code:
foreach (Control ctrl in this.Controls)
ctrl.TabStop = false;
Also you can try to check the last tabindex. Then go to your form.designers.cs and find all controls with a greater tabindex and then remove them : add
ctrlTabStop = false;
I did not test any of this, so be careful : backup your *.designer.cs before.

Enable scroll bar from disabled listview in C#

I'm getting confusion. I'm set :
this.listView1.Enabled = false;
when i make do that listview's scroll bars are disabled, too. I want to see all listviewitems in listview with scroll bars when listview disabled. Please give me some advices. Thanks.
After a lot of comments, I'm assuming your listview, because of is updated often from many different threads, is flickering.
If so, one possible solution is to enable DoubleBuffering; this property anyway is protected so accessible only from descendant classes.
So you could:
Add a new class to your project and paste the code shown below
Compile
Drop new control from the top of the toolbox onto your form, replacing the old one
This could solve your problem.
using System;
using System.Windows.Forms;
class BufferedListView : ListView
{
public BufferedListView()
{
this.DoubleBuffered = true;
}
}
The idea is taken from this post on SO.
you can't scroll a disabled control, since scrollbars are part of the control itself (and it's disabled, so...).
if you want to scroll but not allow user to select anything, you could do this
this.listBox1.SelectionMode = SelectionMode.None;
if you want to revert it, you can set it to SelectionMode.One for single, or one of the other options for multiple selection allowance.
another (imho overcomplicated) option is making a user drawn ListBox.
You can't scroll a disabled control - but if you really need such a functionality, develop a user control.
Developing Custom Controls in C#
Hiding the scroll bar in CheckListbox
Writing your custom control step by step.
Maybe if you put your listview inside a Panel you can enable scrolling by setting up ScrollBars="Auto" on the Panel control

Winforms: How can I programmatically display the last item in a C# listview when there are vertical scrollbars?

How can I programmatically display the last item in a C# listview when there are vertical scrollbars? I've studied every method associated with listviews and can't find anything.
It's not actually easy/possible to scroll the list view. You need to tell the item to make sure it's visible.
var items = listView.Items;
var last = items[items.Count-1];
last.EnsureVisible();
this.listView1.Items[this.listView1.Items.Count - 1].EnsureVisible();
ListViewItem.EnsureVisible()
WINFORMS:
Did you try setting the Selected value to TRUE in the last item in the Items collection of the ListView?
I think that doing this will focus on the last item... scrolling down if it is necesary.
But I did't tryed myself.
EDIT:
This will do the trick:
Me.ListView1.Items(Me.ListView1.Items.Count - 1).EnsureVisible()
WPF or WinForms?
In WPF, you get the ListViewItem and call BringIntoView on it.
This is a link to using a windows function to hide the horizontal and force vertical to be shown at all times:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/4aa4dade-53a2-4e2e-a8b4-b4980da1f39c/
The following hack will both select and show the last ListView item.
Not sure why this works but it works.
listview.SelectedIndices.Clear();
listview.FocusedItem = listview.Items[listview.Items.Count - 1];
listview.FocusedItem.Selected = true;
listview.BeginInvoke((MethodInvoker)delegate {
listview.FocusedItem.EnsureVisible();
});
Also, if you don't want a horizontal scroll bar to show, you need to resize ListView columns to fit the ListView's ClientArea width before calling BeginInvoke.
I have a custom control that inherits the ListView but since it does not expose the inner ListView I had no way to utilize the above mentioned items...EnsureVisible() solution.
I solved as sort of work around by sending the Ctrl+End keys directly to that control to manually fix the scroll to bottom:
logMsgList.Focus();
SendKeys.Send("^{END}");

Categories

Resources