控件属性问题

zhl1983929 2008-11-27 10:41:43
如何做出像控件字体属性那种效果,前面是小加号,点击后有很多具体的子属性,请教??
...全文
100 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhengnan 2008-11-27
  • 打赏
  • 举报
回复

'在你的控件里声明如下属性
<TypeConverter(GetType(CDisplayFormatConvert))> _
<DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)> _
Property DisplayFormat() As CDisplayFormat
Get
Return _DisplayFormat
End Get
Set(ByVal value As CDisplayFormat)
_DisplayFormat = value
End Set
End Property

'编写如下类
Imports System.ComponentModel

Public Class CDisplayFormatConvert
Inherits TypeConverter

Public Overrides Function GetPropertiesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function

Public Overrides Function GetProperties(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal value As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection
Return TypeDescriptor.GetProperties(GetType(CDisplayFormat))
End Function
End Class

Imports System.ComponentModel

<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class CDisplayFormat
Private _DisplayFormatString As String = "####0.##"
Private _Separator As String = ","

<NotifyParentPropertyAttribute(True)> _
<DefaultValue("####0.##")> _
Public Property FormatString() As String
Get
Return _DisplayFormatString
End Get
Set(ByVal value As String)
_DisplayFormatString = value
End Set
End Property
<NotifyParentPropertyAttribute(True)> _
<DefaultValue(",")> _
Public Property Separator() As String
Get
Return _Separator
End Get
Set(ByVal value As String)
_Separator = value
End Set
End Property

Public Overrides Function toString() As String
'这里返回的字符串是要在属性栏里显示的东西
Return "(DisplayFormat)"
End Function
End Class

zhl1983929 2008-11-27
  • 打赏
  • 举报
回复
没有人会吗???
xiaojin0710 2008-11-27
  • 打赏
  • 举报
回复
没用过,学习啊
zhl1983929 2008-11-27
  • 打赏
  • 举报
回复
有没有高手再指点一下啊
tonny008 2008-11-27
  • 打赏
  • 举报
回复
误解楼主的意思了
zhl1983929 2008-11-27
  • 打赏
  • 举报
回复

如何做出像控件字体属性那种效果,前面是小加号,点击后有很多具体的子属性,请教??
-------------------------------
这个是复杂属性,属性的类型不是简单类型,其实很简单:
比如你有个类为A:
public class A
{
public string P1{get;set;}
public string P2{get;set;}
}

你有控件类为B,其中有个类型为A的属性:
public class B : Control
{
public A A{get;set;}
}
*************
好像不行呵
tonny008 2008-11-27
  • 打赏
  • 举报
回复
Editor("System.Drawing.Design.FontEditor

font类型有这个EditorAttribute

你的类型也可以加Attribute,你可以自定义Editor
mapserver 2008-11-27
  • 打赏
  • 举报
回复
如何做出像控件字体属性那种效果,前面是小加号,点击后有很多具体的子属性,请教??
-------------------------------
这个是复杂属性,属性的类型不是简单类型,其实很简单:
比如你有个类为A:
public class A
{
public string P1{get;set;}
public string P2{get;set;}
}

你有控件类为B,其中有个类型为A的属性:
public class B : Control
{
public A A{get;set;}
}

那么在vs的Design模式下,B的A属性,就会出现那种效果。
Component的属性类型转换,可以看这里:http://www.cnblogs.com/mapserver/articles/353722.html
tonny008 2008-11-27
  • 打赏
  • 举报
回复
那是PropertyGrid对该类型属性的内建支持吧
zhl1983929 2008-11-27
  • 打赏
  • 举报
回复
我是要在控件属性列表中实线那种效果,也就是说我做了一个控件,我要把属性显示成字体那种效果
wenh7788 2008-11-27
  • 打赏
  • 举报
回复
貌似没有听懂你说的是什么
是不是你可以放一个button
然后text="..."
这样你单击下这个button然后弹出一个窗体
这样对吗?
凤宝儿 2008-11-27
  • 打赏
  • 举报
回复
不明白你的问题
说清楚点...
风骑士之怒 2008-11-27
  • 打赏
  • 举报
回复
TREEVIEW
zhl1983929 2008-11-27
  • 打赏
  • 举报
回复
=……=
zhl1983929 2008-11-27
  • 打赏
  • 举报
回复
不行啊

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧