|
-
Mar 4th, 2010, 04:00 PM
#1
Thread Starter
Hyperactive Member
Scrolling in a panel
Okay, I have a problem with scrolling in a panel.
I have a panel on my main form that has vertical scrollbars enabled. I also have a custom control I have built that is the same width as the panel and has a height of 45. I store multiple of my user controls in an array, and I want the panel to display these controls like a listbox... one stacked on top of the other. So I loop through the array and add each control to the panel at coordinates right under the previous one.
This works fine, and as long as I use the the mouse to scroll down and expose the controls I'm interested in and then clicking on that control, things work great. The problem comes in when I want to use the arrow key to move down to the next control. If the next control is visible on the panel, it works fine.
This is where it gets strange.
Assume I've arrowed down to the last control displayed on the panel, and then I hit the down arrow key one more time. What happens is that the control is selected and theoretically has focus (a focus() was called for that control), but it doesn't scroll down and display the active control. I can hit down arrow multiple times, and though it happily activates the next control in line each time, it does not scroll... though the control flickers as though a paint was executed.
After I programatically set the new control, I try to scroll down to it using panel1.ScrollControlIntoView(control)... and yes, the panel does have AutoScroll set to true. So it SHOULD scroll down... but it doesn't.
Now let's change things slightly. Assume I MOUSE CLICK on the last displayed control (as opposed to arrowing down to it as in the above example), and then I hit the down arrow key. It not only activates the next control, IT SCROLLS DOWN ONE TO SHOW IT! I can then use the down arrow three or four times and it works... then stops working again with the behavior observed above
I do not know what the problem is. Am I missing something? How am I supposed to scroll to a specific control on the panel?
-
Mar 4th, 2010, 05:09 PM
#2
Re: Scrolling in a panel
what code are you using to move focus to your next control with your arrow keys?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 4th, 2010, 05:14 PM
#3
Re: Scrolling in a panel
i tried it with 10 rtb's on a panel using this code, + it worked fine:
vb Code:
Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles _
RichTextBox1.KeyDown, RichTextBox2.KeyDown, RichTextBox3.KeyDown, RichTextBox4.KeyDown, RichTextBox5.KeyDown, _
RichTextBox6.KeyDown, RichTextBox7.KeyDown, RichTextBox8.KeyDown, RichTextBox9.KeyDown, RichTextBox10.KeyDown
If e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Down Then
Me.Panel1.SelectNextControl(DirectCast(sender, Control), True, True, False, True)
e.SuppressKeyPress = True
ElseIf e.KeyCode = Keys.Up Then
Me.Panel1.SelectNextControl(DirectCast(sender, Control), False, True, False, True)
e.SuppressKeyPress = True
End If
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 4th, 2010, 05:16 PM
#4
Re: Scrolling in a panel
where are the vertical scrollbars enabled? the panel or the form? it needs to be the panel
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 4th, 2010, 05:27 PM
#5
Thread Starter
Hyperactive Member
Re: Scrolling in a panel
The panel has scrollbars enabled.
When the user presses the down arrow key I perform the following steps.
1) I determine which control in the array should receive focus and call it's custom "activate" method which activates an indicator that shows THAT control is selected.
2) I deactivate the previously selected control in a similar fashion, by calling a custom "deactivate" method... clears the visual indicator.
2) I call the SetFocus method for the newly activated control.
3) I call panel1.ScrollControlIntoView(control(SelectedIndex)) to scroll the control into view.
The results of this sequence I described to you earlier.
-
Mar 4th, 2010, 05:36 PM
#6
Re: Scrolling in a panel
if you have an array of controls, i'd still recommend using the method i posted in post #3.
you could call your custom "activate" + "deactivate" methods in the control's gotfocus + lostfocus events
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|