我已在OwnerDraw
中创建了自定义ToolTip
继承的Class
控件,并且还添加了一些自定义属性。我的TextRenderer
看起来像这样:
TextRenderer.DrawText(e.Graphics, e.ToolTipText, Me.Font, e.Bounds,
Me.ForeColor, Me.BackColor,
TextFormatFlags.HorizontalCenter Or TextFormatFlags.VerticalCenter)
我想让TextFormatFlags.HorizontalCenter
和TextFormatFlags.VerticalCenter
来自自定义属性,所以我这样做了:
Private _AlignVertical As TextFormatFlags
<Category("Custom Properties")> <DisplayName("Align Vertical")> <Description("ToolTip's text vertical align.")>
Public Property AlignVertical As TextFormatFlags
Get
Return _AlignVertical
End Get
Set(ByVal Value As TextFormatFlags)
_AlignVertical = Value
End Set
End Property
Private _AlignHorizontal As TextFormatFlags
<Category("Custom Properties")> <DisplayName("Align Horizontal")> <Description("ToolTip's text horizontal align.")>
Public Property AlignHorizontal As TextFormatFlags
Get
Return _AlignHorizontal
End Get
Set(ByVal Value As TextFormatFlags)
_AlignHorizontal = Value
End Set
End Property
然后我将TextRenderer
更改为:
TextRenderer.DrawText(e.Graphics, e.ToolTipText, Me.Font, e.Bounds,
Me.ForeColor, Me.BackColor,
Me.AlignHorizontal Or Me.AlignVertical)
我还将其添加到我的Public Sub New()
:
Me.AlignHorizontal = TextFormatFlags.HorizontalCenter
Me.AlignVertical = TextFormatFlags.VerticalCenter
我的问题是,当我转到属性面板时,转到AlignHorizontal
和AlignVertical
我看到Left, Default, Top, HorizontalCenter
和Left, Default, Top, VerticalCenter
为值,而不是HorizontalCenter
和{ {1}}正如我认为的那样。此外,在我的VerticalCenter
s Form
中,我收到错误,因为这些值看起来像这样:
Designer
任何一种指导都会非常感激!!!
答案 0 :(得分:0)
根据我的知识,我使用下面这个简单的方法。如果有人有更好或更合适的东西......
首先,我将dob_list = raw_input("Enter date of birth. Format: YYYY M D: ").split(' ')
program_data.date_of_birth_transformed = 'date(' + dob_list[0] + ', ' + dob_list[1] + ', ' + dob_list[2] + ')'
属性替换为TextFormatFlags
:
ContentAlignment
然后我在Private _TextAlign As ContentAlignment
<Category("Custom Properties")> <DisplayName("Text Align")> <Description("The alignment of text in the ToolTip.")>
Public Property TextAlign As ContentAlignment
Get
Return _TextAlign
End Get
Set(ByVal Value As ContentAlignment)
_TextAlign = Value
End Set
End Property
之前添加了IF
声明,其中&#34;转换了&#34;从TextRenderer
到TextFormatFlags
的值:
ContentAlignment
答案 1 :(得分:0)
对于来到这里并欣赏Simonetos的C#开发人员来说,希腊语的答案与我一样,是标志分配的C#翻译:
switch (TextAlign)
{
case ContentAlignment.BottomCenter:
return TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter;
case ContentAlignment.BottomLeft:
return TextFormatFlags.Bottom | TextFormatFlags.Left;
case ContentAlignment.BottomRight:
return TextFormatFlags.Bottom | TextFormatFlags.Right;
case ContentAlignment.MiddleCenter:
return TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
case ContentAlignment.MiddleLeft:
return TextFormatFlags.VerticalCenter | TextFormatFlags.Left;
case ContentAlignment.MiddleRight:
return TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
case ContentAlignment.TopCenter:
return TextFormatFlags.Top | TextFormatFlags.HorizontalCenter;
case ContentAlignment.TopLeft:
return TextFormatFlags.Top | TextFormatFlags.Left;
case ContentAlignment.TopRight:
return TextFormatFlags.Top | TextFormatFlags.Right;
default:
return TextFormatFlags.Default;
}