none
spiltcontainer distance size RRS feed

  • Question

  • hi

    I want to restrict the user to distance size in 150 maximum distance

    my cod not work

     Dim split_distance As Integer = 150
        Dim mouse_down As Boolean = False
    
        Private Sub FORM_SPILT_Layout(ByVal sender As Object, ByVal e As LayoutEventArgs) Handles FORM_SPILT.Layout
            FORM_SPILT.SplitterDistance = Me.split_distance
        End Sub
    
        Private Sub FORM_SPILT_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FORM_SPILT.MouseDown
            Me.mouse_down = True
        End Sub
    
        Private Sub FORM_SPILT_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FORM_SPILT.MouseUp
            Me.mouse_down = False
        End Sub
    
        Private Sub FORM_SPILT_SplitterMoving(ByVal sender As Object, ByVal e As SplitterCancelEventArgs) Handles FORM_SPILT.SplitterMoving
            If Me.mouse_down Then
                Me.split_distance = e.SplitX
            End If
    
        End Sub

    Thursday, May 16, 2019 2:43 PM

Answers

  • Try handling the SizeChanged event of your splitter:

    Private Sub FORM_SPILT_SizeChanged(sender As Object, e As EventArgs) Handles FORM_SPILT.SizeChanged
    
        FORM_SPILT.Panel2MinSize = Math.Max(0, FORM_SPILT.Width - 150 - FORM_SPILT.SplitterWidth)
    
    End Sub

    Other code is not needed.

     

    • Marked as answer by ahmeddc Thursday, May 16, 2019 7:03 PM
    Thursday, May 16, 2019 6:04 PM
  • Hi

    Try this. The User will still see the Splitter moving indication, but will only ever get itto set to 'MaxSplitterDistance'

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim split_distance As Integer = 100
        Dim mouse_down As Boolean = False
        Dim MaxSplitterDistance As Integer = 150
        Private Sub FORM_SPILT_SplitterMoved(sender As Object, e As SplitterEventArgs) Handles FORM_SPILT.SplitterMoved
            If split_distance > MaxSplitterDistance Then split_distance = MaxSplitterDistance
    
            FORM_SPILT.SplitterDistance = split_distance
        End Sub
        Private Sub FORM_SPILT_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FORM_SPILT.MouseDown
            mouse_down = True
        End Sub
        Private Sub FORM_SPILT_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FORM_SPILT.MouseUp
            mouse_down = False
        End Sub
        Private Sub FORM_SPILT_SplitterMoving(ByVal sender As Object, ByVal e As SplitterCancelEventArgs) Handles FORM_SPILT.SplitterMoving
            split_distance = e.SplitX
        End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, May 16, 2019 3:25 PM
    • Marked as answer by ahmeddc Thursday, May 16, 2019 7:03 PM
    Thursday, May 16, 2019 3:24 PM

All replies

  • Hi

    Try this. The User will still see the Splitter moving indication, but will only ever get itto set to 'MaxSplitterDistance'

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim split_distance As Integer = 100
        Dim mouse_down As Boolean = False
        Dim MaxSplitterDistance As Integer = 150
        Private Sub FORM_SPILT_SplitterMoved(sender As Object, e As SplitterEventArgs) Handles FORM_SPILT.SplitterMoved
            If split_distance > MaxSplitterDistance Then split_distance = MaxSplitterDistance
    
            FORM_SPILT.SplitterDistance = split_distance
        End Sub
        Private Sub FORM_SPILT_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FORM_SPILT.MouseDown
            mouse_down = True
        End Sub
        Private Sub FORM_SPILT_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FORM_SPILT.MouseUp
            mouse_down = False
        End Sub
        Private Sub FORM_SPILT_SplitterMoving(ByVal sender As Object, ByVal e As SplitterCancelEventArgs) Handles FORM_SPILT.SplitterMoving
            split_distance = e.SplitX
        End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, May 16, 2019 3:25 PM
    • Marked as answer by ahmeddc Thursday, May 16, 2019 7:03 PM
    Thursday, May 16, 2019 3:24 PM
  • Try handling the SizeChanged event of your splitter:

    Private Sub FORM_SPILT_SizeChanged(sender As Object, e As EventArgs) Handles FORM_SPILT.SizeChanged
    
        FORM_SPILT.Panel2MinSize = Math.Max(0, FORM_SPILT.Width - 150 - FORM_SPILT.SplitterWidth)
    
    End Sub

    Other code is not needed.

     

    • Marked as answer by ahmeddc Thursday, May 16, 2019 7:03 PM
    Thursday, May 16, 2019 6:04 PM