|
分類:[VB.NET]
2006/07/09(Sun) 12:19:23 編集(投稿者) 2006/07/09(Sun) 12:03:26 編集(投稿者)
■No4869に返信(はいこーんさんの記事) はいこーんさん ありがとうございます
まどかさん、名無しぃシャープ さん、YASさん ごめんなさい
> すでに指摘されていますが、Parentプロパティは親コンテナを取得します。 > Panelに張り付いていれば、そのPanelのインスタンスへの参照が取得できます。 > > すでに指摘されているので、とっくに気付いているのかと思った。。。
ごめんなさい 私が間違った操作をしていました Button1.Parent.Name で取得できました 間違って パネルに張り付いていないボタンに.parentとしていました
どうも 有難う御座いました。
下記のように作りました
Public Class aaToggleButton Public pText As String = "Toggle" Public pOnOff As Integer = 0 Public Event _on_off() Public Event _Click() Public pBcolor As Color = System.Drawing.SystemColors.Control Public pFcolor As Color = System.Drawing.SystemColors.ControlDarkDark _______________________________________________________________________ Private Sub _Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Button1.Location = New System.Drawing.Point(0, 0)
End Sub _______________________________________________________________________ Private Sub _SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged Dim h As Integer = Me.Height Dim w As Integer = Me.Width Button1.Height = h Button1.Width = w
End Sub _______________________________________________________________________ Public Property _Text() As String Get Button1.Text = pText _Text = pText End Get Set(ByVal value As String) Button1.Text = value pText = value End Set End Property _______________________________________________________________________ Property myFont() As Font Get myFont = Button1.Font End Get Set(ByVal value As Font) Button1.Font = value End Set End Property ________________________________________ Public Property on_off() As Integer Get on_off = pOnOff
End Get Set(ByVal value As Integer) pOnOff = value If value = 1 Then _On() Else _Off() End If RaiseEvent _on_off() End Set End Property __________________________________________ Sub _On()
Button1.ForeColor = System.Drawing.SystemColors.ControlDark Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat End Sub _________________________________________ Sub _Off()
Button1.ForeColor = System.Drawing.SystemColors.ControlDarkDark Button1.FlatStyle = System.Windows.Forms.FlatStyle.Standard End Sub _________________________________________ Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sen As Button = CType(sender, Button) RaiseEvent _Click() If on_off = 0 Then _On() on_off = 1 Else _Off() on_off = 0 End If Dim BaseC As Object = Me.Parent ←ここで悩んでました If on_off = 1 Then otherset(BaseC) End If End Sub ________________________________________ Sub Otherset(ByVal base As Object) Dim typ As String = TypeName(Me) Dim nm As String = Me.Name Console.WriteLine(typ) For Each c As Control In base.controls If TypeName(c) = typ Then If c.Name <> nm Then CType(c, aaToggleButton).on_off = 0 End If End If Next End Sub _________________________________________ Public Overrides Property BackColor() As Color Get BackColor = pBcolor End Get Set(ByVal value As Color) pBcolor = value Button1.ForeColor = pFcolor End Set End Property __________________________________________ Public Overrides Property ForeColor() As Color Get ForeColor = pFcolor End Get Set(ByVal value As Color) pFcolor = value Button1.ForeColor = pFcolor End Set End Property End Class __________________________________________
|