0

Thunderbird ウィンドウに時々見られるように、「OK」ボタンと「キャンセル」ボタンの上にある 3D ラインであるユーザーコントロールを作成しようとしています。

http://s11.postimage.org/gh45ux9wj/thunderbird1.png

ユーザーコントロールをフォームに配置するたびにアンカープロパティを手動で設定する必要はありません。そのため、ユーザーコントロール内で親に自動的にドッキングするようにしたかったのです(Left = 0、Width = Parent.幅)。

しかし、私は本当にそうすることができません。

私の試みは何回もあったので、ここに何を投稿すればよいかわかりません。

私の仮定は、私が使用する必要があるということでした

Private Sub UserControl1_ParentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ParentChanged

    Me.SetBounds(0, Me.Top, Me.Parent.Width, 0, BoundsSpecified.X Or BoundsSpecified.Y Or BoundsSpecified.Width)

End Sub

しかし、それはまったく機能しません。

4

1 に答える 1

1

Resize親のサイズが変更されるたびに通知されるように、親のイベントにイベント ハンドラーを追加する必要があります。たとえば、次のようなものが機能します。

Public Class ThreeDLine
    Private _lastParent As Control

    Private Sub Parent_Resize(ByVal sender As Object, ByVal e As EventArgs)
        resizeToParentWidth()
    End Sub

    Private Sub Divider_ParentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ParentChanged
        If _lastParent IsNot Nothing Then
            RemoveHandler _lastParent.Resize, AddressOf Parent_Resize
        End If
        _lastParent = Parent
        If Parent IsNot Nothing Then
            AddHandler Parent.Resize, AddressOf Parent_Resize
            resizeToParentWidth()
        End If
    End Sub

    Private Sub resizeToParentWidth()
        If Parent IsNot Nothing Then
            Me.Left = 0
            Me.Width = Parent.ClientSize.Width
        End If
    End Sub
End Class
于 2012-10-16T14:32:25.607 に答える