سلام
چطور میتونم یک Property رو به یک فرم نسبت بدم
یه چیزی تو مایه های DefultCellStyle توی Data grid view که یه فرم جدید باز میکنه (CellStyleBuilder) و تنظیمات مربوطه رو توی اون فرم میپرسه
ممنون میشم راهنمایی کنید
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System
Public Class MyComponent
[B][COLOR="#0000FF"] Private _power As Boolean
Public Property Power() As Boolean
Get
Return _power
End Get
Set(ByVal value As Boolean)
_power = value
End Set
End Property
[/COLOR][/B]
End Class
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System
Public Class PowerUITypeEditor
Inherits UITypeEditor
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
[B][COLOR="#0000FF"] Return UITypeEditorEditStyle.Modal[/COLOR][/B]
End Function
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim service As IWindowsFormsEditorService = provider.GetService(GetType(IWindowsFormsEditorService))
If (service Is Nothing) Or (value Is Nothing) Then
Return value
End If
[B][COLOR="#0000FF"] Dim power As Boolean = value
Using f As New PowerForm
f.RadioButtonOff.Checked = Not power
f.RadioButtonOn.Checked = power
If service.ShowDialog(f) = DialogResult.OK Then
power = f.RadioButtonOn.Checked
End If
End Using
Return power
[/COLOR][/B]
End Function
End Class
[CODE]
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System
Public Class MyComponent
Private _power As Boolean
[B][COLOR="#0000FF"] <Editor(GetType(PowerUITypeEditor), GetType(UITypeEditor))> _
<TypeConverter(GetType(ExpandableObjectConverter))> _
[/COLOR][/B] Public Property Power() As Boolean
Get
Return _power
End Get
Set(ByVal value As Boolean)
_power = value
End Set
End Property
End Class
خیلی ممنونم از جواب کاملتون استاد گرامی
حالا اگه بخوام DataType ی که میسازم وقتی که به عنوان Property در نظر گرفته میشه این فرم رو نشون بده چه باید بکنم؟
یه جورایی مثل System.Windows.Forms.DockStyle که هر پروپرتی که از اون نوع تعریف بشه فرم مربوط به این DataType رو نشون میده
بازهم ممنونم از راهنمایی های کاملتون
Public Enum PowerState
PowerOff = 0
PowerOn = 1
End Enum
Private _power As PowerState
Public Property Power() As PowerState
Get
Return _power
End Get
Set(ByVal value As PowerState)
_power = value
End Set
End Property
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System
Public Class PowerUITypeEditor
Inherits UITypeEditor
Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
Return UITypeEditorEditStyle.Modal
End Function
Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
Dim service As IWindowsFormsEditorService = provider.GetService(GetType(IWindowsFormsEditorService))
If (service Is Nothing) Or (value Is Nothing) Then
Return value
End If
Dim power As MyComponent.PowerState = value
Using f As New PowerForm
f.RadioButtonOff.Checked = (power = MyComponent.PowerState.PowerOff)
f.RadioButtonOn.Checked = (power = MyComponent.PowerState.PowerOn)
If service.ShowDialog(f) = DialogResult.OK Then
power = IIf(f.RadioButtonOn.Checked, MyComponent.PowerState.PowerOn, MyComponent.PowerState.PowerOff)
End If
End Using
Return power
End Function
End Class
[B][COLOR="#0000FF"] <Editor(GetType(PowerUITypeEditor), GetType(UITypeEditor))> _
<TypeConverter(GetType(ExpandableObjectConverter))> _
[/COLOR][/B] Public Enum PowerState
PowerOff = 0
PowerOn = 1
End Enum
واقعا دستت درد نکنه استاد،
خدا خیرت بده
یه سوال دیگه:
اگه متغیر از نوع Structure باشه چیزی که به عنوان مقدار اون Property نشون میده یه متن بی معنیه (CustomModalUITypeEditor.MyComponent+PersonInformation_Struct) چطور میتونم اون رو تغییر بدم؟
Public Overrides Function ToString() As String
Return "Your text"
End Function
ثبت شدن داده یک مشخصه به این معنا است که داده داخل اون ساختار Serialize بشه و در کد Resource یا کد فایل Design اون فرم ذخیره بشه.سلام مجدد
حالا یه مشکل دیگه دارم استاد
اونم اینه که وقتی متغیر از نوع Structure تعریف میشه دیگه توی محیط Designer مقدارش ذخیره نمیشه و با یه Rebuild کردن هر مقداری که Set شده باشه از بین میره!
ممنون میشم بگید برای رفع مشکل چی کنم؟
[COLOR="#A9A9A9"] <Editor(GetType(InfoUITypeEditor), GetType(UITypeEditor))> _
[/COLOR] Public Structure InfoDataType
Public FirstName As String
Public LastName As String
End Structure
Private _info As New InfoDataType
Public Property Info() As InfoDataType
Get
Return _info
End Get
Set(ByVal value As InfoDataType)
_info = value
End Set
End Property
[B][COLOR="#0000FF"]Imports System[/COLOR][/B]
[COLOR="#A9A9A9"].
.
.
[/COLOR][B][COLOR="#0000FF"] <Serializable()> _[/COLOR][/B]
<Editor(GetType(InfoUITypeEditor), GetType(UITypeEditor))> _
Public Structure InfoDataType
Public FirstName As String
Public LastName As String
End Structure
[B][COLOR="#0000FF"] Public Function ShouldSerialize[U]Info[/U]() As Boolean
Return True
End Function
Public Sub Reset[U]Info[/U]()
Info = New InfoDataType
End Sub
[/COLOR][/B]
Public Function ShouldSerializeInfo() As Boolean
Return True
End Function
Public Sub ResetInfo()
Info = New InfoDataType
End Sub
نه، ShouldSerialize و Reset جزئی از Structure نیست، کنار Property تعریف میشه، یعنی در اون کلاس (User Control شما) تعریف میشه.خیلی ممنون استاد
خدا خیرت بده، واقعا کارت حرف نداره
یه سوال دیگه
قطعه کد زیر توی خود استراکچر تعریف شه؟
متغیر Info میتونه Private باشه یا حتما باید Public Property در نظر گرفته بشه؟
میشه یه مثال کامل بزنید؟کد:Public Function ShouldSerializeInfo() As Boolean Return True End Function Public Sub ResetInfo() Info = New InfoDataType End Sub
Public Class Component1
Private _backColor As Color
Public Property [B][COLOR="#0000FF"]BackColor[/COLOR][/B]() As Color
Get
Return IIf(_backColor.IsEmpty, Color.Blue, _backColor)
End Get
Set(ByVal value As Color)
_backColor = value
End Set
End Property
Public Function ShouldSerialize[B][COLOR="#0000FF"]BackColor[/COLOR][/B]() As Boolean
Return ([B][COLOR="#0000FF"]BackColor[/COLOR][/B] <> Color.Blue)
End Function
Public Sub Reset[B][COLOR="#0000FF"]BackColor[/COLOR][/B]()
[B][COLOR="#0000FF"]BackColor[/COLOR][/B] = Color.Blue
End Sub
End Class