Splitter events in 2.0

M

Marina

Hi,

It seems that I am seeing an inconsistency in the arguments that get passed
to the SplitterMoved vs. SplitterMoving events.

As in, the ones for the SplitterMoving are correct coordinates, and the ones
for SplitterMoving are not.

I have a panel with 2 controls in it and a splitter. I also have a textbox
to log all the values of the events.

I then have the following code to capture the event arguments:

Private Sub Splitter1_SplitterMoved(ByVal sender As Object, ByVal e As
System.Windows.Forms.SplitterEventArgs) Handles Splitter1.SplitterMoved
Log("Moved", e.SplitX)
End Sub

Private Sub Splitter1_SplitterMoving(ByVal sender As Object, ByVal e As
System.Windows.Forms.SplitterEventArgs) Handles Splitter1.SplitterMoving
Log("Moving", e.SplitX)
End Sub

Private Sub Log(ByVal eventName As String, ByVal num As Integer)
results.Text += eventName + ": " & num & System.Environment.NewLine
End Sub


The results I get by running this program and moving the splitter a bit are:

Moving: 76
Moving: 77
Moving: 78
Moving: 79
Moving: 80
Moving: 81
Moving: 82
Moved: 123


Notice that the Moving is being fired correctly for every pixel.

However, when Moved has fired, it thinks that the splitter is at 123. When
clearly it would be at 82, since that is the last time Moving was called.
But in any case, it would not be 41 pixels over.

What is up with this? Am I looking at this the wrong way and doing something
incorrectly? Or is this a bug?
 
J

JasonS

Private Sub Splitter1_SplitterMoved(ByVal sender As Object, ByVal e As
System.Windows.Forms.SplitterEventArgs) Handles Splitter1.SplitterMoved
Log("Moved", e.SplitX)
End Sub

Private Sub Splitter1_SplitterMoving(ByVal sender As Object, ByVal e As
System.Windows.Forms.SplitterEventArgs) Handles Splitter1.SplitterMoving
Log("Moving", e.SplitX)
End Sub

Private Sub Log(ByVal eventName As String, ByVal num As Integer)
results.Text += eventName + ": " & num & System.Environment.NewLine
End Sub

It is very odd behavior. It appears that SplitX is always exactly 1.5x the
correct location.
The SplitContainer (which now replaces the Splitter control) doesn't have
this issue, so I would just avoid the Splitter component if that's an
option for you.

Cheers,
Jason
 
C

Chris Dunaway

Marina said:
What is up with this? Am I looking at this the wrong way and doing something
incorrectly? Or is this a bug?

I was able to duplicate this behavior. When my splitter was at 0, the
Moved event also reported 0, but as I moved the splitter to the right,
the SplitX value shown in the Moved event was increasingly off. When I
got to 640 on the Moving event, the Moved event reported 940! I
suspect it is a calculation bug or rounding bug in the event code.
 
C

Chris Dunaway

Marina said:
What is up with this? Am I looking at this the wrong way and doing something
incorrectly? Or is this a bug?

I did the same test with a SplitContainer and it seems to work
correctly. You might try that instead.
 
M

Marina

Thanks Chris. The other workaround is to keep track of the SplitX in the
Moving event, in the Moved just use whatever value was last set in Moving.

Just wanted to confirm this issue.

Thanks,
Marina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top