■90171 / ) |
Re[1]: カスタムコントロールのデフォルト値を設定するには? |
□投稿者/ 魔界の仮面弁士 (2051回)-(2019/02/13(Wed) 21:59:56)
|
■No90167 (じきじき さん) に返信 > カスタムコントロールを新規作成した時に > 最初に設定されるデフォルト値を設定したいのですが、 > どうしたら良いですか?
上記がデザイナー依存の話と仮定して、カスタムコントロールの Text プロパティに、 「フォーム名.コントロール名」を初期値として与えてみる例。
<System.ComponentModel.Designer(GetType(CustomControl.CustomControlDesigner))> Partial Public Class CustomControl Inherits System.Windows.Forms.Control
Public Sub New() InitializeComponent() End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs) MyBase.OnPaint(e) e.Graphics.DrawString(Me.Text, Me.Font, Brushes.Black, PointF.Empty) End Sub
Protected Overrides Sub OnControlAdded(e As ControlEventArgs) MyBase.OnControlAdded(e) End Sub
Friend Class CustomControlDesigner Inherits System.Windows.Forms.Design.ControlDesigner Public Overrides Sub InitializeNewComponent(ByVal defaultValues As System.Collections.IDictionary) MyBase.InitializeNewComponent(defaultValues) Dim f As Form = Me.Control.FindForm() If f IsNot Nothing Then Me.Control.Text = f.Name & "." & Me.Control.Name Else Me.Control.Text = Me.Control.Name End If End Sub End Class End Class
|
|