Splitter withhidden left control

xiaoxiao2021-03-06  15

There is a button in the middle of the splitter in some software. You can display / hide the control on the left, such as WPS. One is also customized in .NET.

Class code:

Public class mysplitter

Public Shared Sub AddshowHideEvent (Byval SL As Splitter)

DIM LBL AS New Label

lbl.text = "3"

LBL.FONT = New System.drawing.Font ("Marlett", 7.0 !, system.drawing.fontstyle.regular, System.drawing.graphicsUnit.point, CType (2, byte)

lbl.autosize = true

LBL.Location = New Point (-3.5, sl.height / 2 - lbl.height)

lbl.cursor = cursors.hand

lbl.forecolor = color.red

sl.Controls.Add (LBL)

sl.Width = 3.5

AddHandler LBL.Click, Addressof LBL_Click

AddHandler Sl.resize, Addressof Splitter_resize

DIM TT AS New Tooltip

Tt.SetTooltip (LBL, "Hide Controls on the left"))

lbl.tag = tt

End Sub

Private Shared Sub LBL_Click (Byval E AS Object, Byval e as system.eventargs)

Dim lbl as label = ctype (sender, label)

Dim Targetctrl As Control

DIM SL as splitter = ctype (lbl.parent, splitter)

Dim PCTRL AS Control = SL.Parent

For Each Temp as Control in PCTRL.CONTROLS

If not temp.equals (sl) then

If sl.dock = DockStyle.Left then

If Temp.dock = DockStyle.Left Andalso_

(Not Temp.Visible Oralse Temp.left

Targetctrl = TEMP

EXIT for

END IF

Elseif Sl.dock = DockStyle.top Then

IF Temp.dock = DockStyle.top andalso_Andalso_

(Not Temp.visible Oralse Temp.top

Targetctrl = TEMP

EXIT for

END IF

END IF

END IF

NEXT

IF not targetctrl is nothing then

DIM TT As Tooltip = CType (LBL.TAG, Tooltip)

If lbl.text = "3" THEN

LBL.TEXT = 4

Tt.SetTooltip (LBL, "Shows the control on the left")

Targetctrl.visible = false

Else

LBL.TEXT = 3

Tt.SetTooltip (LBL, "Hide Controls on the left"))

Targetctrl.visible = true

END IF

END IF

End Sub

Private Shared Sub Splitter_resize (Byval E AS ISTEM.EVENTARGS)

DIM SL As Splitter = CType (Sender, Splitter)

Dim lbl as label = sl.controls (0)

LBL.Location = New Point (-3.5, sl.height / 2 - lbl.height)

End Sub

END CLASS

When using, add the red code as shown below in the initialization code of the form:

Public Sub New ()

Mybase.new ()

'This call is required for the Windows Form Designer.

InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

MySplitter.addshowhideEvent (me.splitter1)

End Sub

转载请注明原文地址:https://www.9cbs.com/read-47990.html

New Post(0)