用户控件,从类对象中选择自定义属性 [英] User control with custom property selecting from class object

查看:77
本文介绍了用户控件,从类对象中选择自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这让我很疯狂,但我正在研究这个约一个星期,我无法实现。

我有一个类,这个类有很多布尔值。



Ex:public bool1,

public bool2等



现在我想创建一个带有自定义属性的自定义单选按钮。

在这个自定义属性区域中,我将选择其中一个我的类的布尔值来自下拉列表。之后如果布尔值为true,将检查单选按钮。



我在WindowsForm上工作。

我该怎么做?



我尝试了什么:



我需要的屏幕截图:示例 - Postimage.org [ ^ ]

推荐答案

当然,您必须在自定义Control中实现自己的Checked / Unchecked布尔属性,在此案例一个RadioButton。但Checked属性必须在自定义UserControl中实现,而不是在不同的类中实现。

然后您可以选择在MyRadiButton控件中使用从UserControl派生的Radibutton,或者您可以使用System.Drawing方法执行此操作绘制一个圆圈并绘制指示文本属性的文本。这对新手来说太难了,但你可以在网上找到一个例子。



这里有一些代码:



Of course you have to implement its own Checked/Unchecked Boolean Property in a custom Control, in this case a RadioButton. But the Checked Property must be implemented inside your custom UserControl not on different class.
You then can choose to use a Radibutton within your MyRadiButton control that derives from UserControl or you would do it using System.Drawing methods to paint a circle and draw text indicating the Text Property. This all is too difficult for a novice but you may find an example on Web.

Here is some code to start with:

Public Class MyRadioButton : Inherits UserControl

Private _Checked As Boolean
Property Checked As Boolean
 Get : Return _Checked : End Get
 Set(value As Boolean) 
   _Checked = value 
   EnableDisable(New PaintEventArgs(Me.CreateGraphics)) 
 End Set
End Property


Sub New()
  '//
End Sub

Protected Sub EnableDisable(e As PaintEventArgs)
   If Checked Then
    'e.graphics.fillellipse(draw/fill a circle)
   Else
    'e.graphics.drawellipse(draw circle)
   End If
   'e.graphics.drawstring(draw string of Me.Text Property)
End Sub

Protected Overrides Sub OnPaint(e As PaintEventArgs)
    EnableDisable(e)
End Sub
End Class


这篇关于用户控件,从类对象中选择自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆