Splitcontainer : change splitter color on drag

Xancholy

Well-known member
Joined
Aug 29, 2006
Messages
143
Programming Experience
Beginner
In a splitcontainer, how can I change the splitter bar's color to red when I begin to drag it ?

Can someone please show me how to code this?
 
You can do this:
VB.NET:
Private Sub SplitContainer1_SplitterMoving(ByVal sender As Object, _
                                           ByVal e As SplitterCancelEventArgs) Handles SplitContainer1.SplitterMoving
    Me.SplitContainer1.BackColor = Color.Red
End Sub

Private Sub SplitContainer1_SplitterMoved(ByVal sender As Object, _
                                          ByVal e As SplitterEventArgs) Handles SplitContainer1.SplitterMoved
    Me.SplitContainer1.BackColor = SystemColors.Control
End Sub
but there's not much point. The system draws a selection indicator over the splitter anyway so you won't see any colour at all.
 
Thank you. I see what you mean. But the splitter color becomes lil more visible if you change the splitter width to say, >4pix

All right then what about when the cursor hovers over the splitter and cursor changes. Can we change the color of the splitter when the cursor is over (mouseover)the splitter ?
 
The only event I think would be applicable would be the mousehover event. But mousehover applies to the splitcontainer as a whole.

How do I trap the mousehover event only IF the mouse is over the splitter (when the cursor changes to splitter cursor) THEN color splitter red.
 
Last edited:
The only event I think would be applicable would be the mousehover event. But mousehover applies to the splitcontainer as a whole.

How do I trap the mousehover event only IF the mouse is over the splitter (when the cursor changes to splitter cursor) THEN color splitter red.
This is EXACTLY why I told you to test it. Had you done so you'd already know that the MouseHover event of the SplitContainer is ONLY raised when the mouse cursor hovers over the splitter bar. That's because on each side of the bar is a SplitterPanel that has its own events. It's the MouseHover event of one of those SplitterPanels that will be raised when the mouse cursor hovers over them. Don't assume, especially when you're a beginner and especially when someone else specifically indicates that you should investigate something. Test. Then you know.
 
Yes, my assumptions were incorrect but I do ask terrific questions don't I ? :)

If anyone is interested in the actual answer, hope this helps.

VB.NET:
Private SplitColor As System.Drawing.Color

    Private Sub SplitContainer1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SplitContainer_Live.MouseEnter
        SplitColor = SplitContainer1.BackColor
        SplitContainer1.BackColor = Drawing.Color.LightGreen
    End Sub

    Private Sub SplitContainer1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SplitContainer1.MouseLeave
        SplitContainer1.BackColor = SplitColor
    End Sub
 
The only problem with the above code is that it causes flickering on any control hosted within the splitcontainer's panels. 100 points for anyone who can tell me why ?? :)
 
Back
Top