| ■No64915 (shu さん) に返信
ありがとうございます。 コンポーネントを作るのですか。 なるほど勉強になります。 見た目はどの画面でも同じなので、現状案1っぽいものになっています。 (Function.vbにページ名、時計、ボタンを配置、他の画面はすべて Function.vbを継承、標準機能以外が必要なところではボタンの機能を オーバーライドしている) そんな状態でも(Functionのボタンが使われているのと、独自機能で ボタンが上書きされているのが混在している)上記機能は記述できるのでしょうか?
> ■No64910 (MP枯渇ウィザード さん) に返信 > > 案1)ボタンだけのフォームを作りそこから派生させる。 > 案2)ボタン部分をユーザーコントロールにする > 案3)制御用のコンポーネントを作成する。 > > > 案3のコンポーネントについて書きます。 > 新規追加でコンポーネントを追加します。 > Designer.vbファイルはそのままで > vbファイルを例えば以下のように記述します。 > Imports System.ComponentModel > > <ProvideProperty("FuncNo", GetType(Windows.Forms.Control))> _ > Public Class Component1 > Implements IExtenderProvider > > Friend ButtonNo As New Dictionary(Of Button, String) > > Public Function CanExtend(extendee As Object) As Boolean Implements System.ComponentModel.IExtenderProvider.CanExtend > If TypeOf extendee Is Button Then > Return True > Else > Return False > End If > End Function > > Public Function GetFuncNo(ByVal ctrl As Windows.Forms.Control) As String > If Not TypeOf ctrl Is Button Then Return Nothing > Dim btn = DirectCast(ctrl, Button) > Dim ret As String = Nothing > If ButtonNo.TryGetValue(btn, ret) Then > Return ret > Else > Return Nothing > End If > End Function > > Public Sub SetFuncNo(ByVal ctrl As Windows.Forms.Control, ByVal value As String) > If Not TypeOf ctrl Is Button Then Exit Sub > Dim btn = DirectCast(ctrl, Button) > If String.IsNullOrEmpty(value) Then > If ButtonNo.ContainsKey(btn) Then > ButtonNo.Remove(btn) > End If > Else > ButtonNo(btn) = value > End If > End Sub > > Public Property Enabled As Boolean > Get > If ButtonNo.Count > 0 Then > Return ButtonNo.Keys(0).Enabled > Else > Return False > End If > End Get > Set(value As Boolean) > For Each btnNo In ButtonNo > btnNo.Key.Enabled = value > Next > End Set > End Property > End Class > > 一度コンパイルします。 > するとフォームデザイン状態でツールボックスから作成したComponent1を選ぶことが出来るようになります。 > Component1をフォームに貼りつけると > 各ButtonコントロールにToolTipのような拡張プロパティ『Component11のFuncNo』というのが表示されるので > そこに適当に文字を入力します。Func1Buttonなら1など。 > 後はコード上でComponent11.EnabledをTrue,Falseに変えるとFuncNoを設定したButtonのEnabledがすべて変わります。 > > |