Reputation: 449
I have a project that executes a series of assembly commands. The commands are located in a panel(autoscroll = true) and the line that is to be executed each time, is highlighted.
The problem is that if the number of commands is bigger than a number, highlighted text is not shown on screen and user has to manually scroll down the panel to see it.
What i want is to automatically change the scroll focus so user can see the hidden text when this is highlighted. All of the text is arranged in a table using table layout panel.
As you can see below, when the command goes over "0040001C", the text is still highlighted but cannot be shown to the user.
So, user has to manually scroll down to see the rest of the text that is executing.
Any help??
Upvotes: 2
Views: 336
Reputation: 2346
See this answer concerning how to scroll a Panel to a specified position.
It creates a new Control at the point you need to make visible, then uses the Panel.ScrollControlIntoView method to force the panel to scroll to it.
You could use a similar approach here. Whenever a row is highlighted, determine the position of the top-left corner of that row within your Panel (how you do this depends on how the table is being drawn). Make it a System.Drawing.Point
and call it location
.
Then call
location = new Point(location.X - 4, location.Y)
Now you can create a new Control at that location (suppose your panel is named panel1)
var control = new Control();
control.Location = location;
panel1.Controls.Add(control);
Finally, call
panel1.ScrollControlIntoView(control)
and this should scroll your Panel to the position indicated by location
.
Don't forget to get rid of the new control by calling
panel1.Controls.Remove(control)
Upvotes: 2