从c#到vb.net的Objectlistview转换PerCellDecoration

时间:2014-08-25 16:01:23

标签: vb.net objectlistview

我需要一些关于vb.net中的objectlistview的帮助,我确实将所有内容从c#转换为vb.net,并将BrightIdeasSoftware导入到vb.net,所有设置和配置都与c#相同,但只有Image + title +描述不起作用,除了小图标的进度。 objectlistview与c#相同,每个imageListLarge,imageListSmall都是一样的。从示例开始,c#工作得很好,在转换代码时我做错了吗?

我需要一些专业的帮助和帮助 感谢

这是convert vb.net

    Public Class NamedDescriptionDecoration
        Inherits BrightIdeasSoftware.AbstractDecoration
        Public ImageList As ImageList
        Public ImageName As String
        Public Title As String
        Public Description As String

        Public TitleFont As New Font("Tahoma", 9, FontStyle.Bold)
        Public TitleColor As Color = Color.FromArgb(255, 32, 32, 32)
        Public DescripionFont As New Font("Tahoma", 9)
        Public DescriptionColor As Color = Color.FromArgb(255, 96, 96, 96)
        Public CellPadding As New Size(1, 1)

        Public Overrides Sub Draw(olv As BrightIdeasSoftware.ObjectListView, g As Graphics, r As Rectangle)
            Dim cellBounds As Rectangle = Me.CellBounds
            cellBounds.Inflate(-Me.CellPadding.Width, -Me.CellPadding.Height)
            Dim textBounds As Rectangle = cellBounds

            If Me.ImageList IsNot Nothing AndAlso Not [String].IsNullOrEmpty(Me.ImageName) Then
                g.DrawImage(Me.ImageList.Images(Me.ImageName), cellBounds.Location)
                textBounds.X += Me.ImageList.ImageSize.Width
                textBounds.Width -= Me.ImageList.ImageSize.Width
            End If

            'g.DrawRectangle(Pens.Red, textBounds)

            ' Draw the title
            Dim fmt As New StringFormat(StringFormatFlags.NoWrap)
            fmt.Trimming = StringTrimming.EllipsisCharacter
            fmt.Alignment = StringAlignment.Near
            fmt.LineAlignment = StringAlignment.Near

            Using b As New SolidBrush(Me.TitleColor)
                g.DrawString(Me.Title, Me.TitleFont, b, textBounds, fmt)
            End Using

            ' Draw the description
            Dim size As SizeF = g.MeasureString(Me.Title, Me.TitleFont, CInt(textBounds.Width), fmt)
            textBounds.Y += CInt(size.Height)
            textBounds.Height -= CInt(size.Height)
            Dim fmt2 As New StringFormat()
            fmt2.Trimming = StringTrimming.EllipsisCharacter
            Using b As New SolidBrush(Me.DescriptionColor)
                g.DrawString(Me.Description, Me.DescripionFont, b, textBounds, fmt2)
            End Using

        End Sub
    End Class

和原来的C#

public class NamedDescriptionDecoration : BrightIdeasSoftware.AbstractDecoration
{
    public ImageList ImageList;
    public string ImageName;
    public string Title;
    public string Description;

    public Font TitleFont = new Font("Tahoma", 9, FontStyle.Bold);
    public Color TitleColor = Color.FromArgb(255, 32, 32, 32);
    public Font DescripionFont = new Font("Tahoma", 9);
    public Color DescriptionColor = Color.FromArgb(255, 96, 96, 96);
    public Size CellPadding = new Size(1, 1);

    public override void Draw(BrightIdeasSoftware.ObjectListView olv, Graphics g, Rectangle r) {
        Rectangle cellBounds = this.CellBounds;
        cellBounds.Inflate(-this.CellPadding.Width, -this.CellPadding.Height);
        Rectangle textBounds = cellBounds;

        if (this.ImageList != null && !String.IsNullOrEmpty(this.ImageName)) {
            g.DrawImage(this.ImageList.Images[this.ImageName], cellBounds.Location);
            textBounds.X += this.ImageList.ImageSize.Width;
            textBounds.Width -= this.ImageList.ImageSize.Width;
        }

        //g.DrawRectangle(Pens.Red, textBounds);

        // Draw the title
        StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap);
        fmt.Trimming = StringTrimming.EllipsisCharacter;
        fmt.Alignment = StringAlignment.Near;
        fmt.LineAlignment = StringAlignment.Near;

        using (SolidBrush b = new SolidBrush(this.TitleColor)) {
            g.DrawString(this.Title, this.TitleFont, b, textBounds, fmt);
        }

        // Draw the description
        SizeF size = g.MeasureString(this.Title, this.TitleFont, (int)textBounds.Width, fmt);
        textBounds.Y += (int)size.Height;
        textBounds.Height -= (int)size.Height;
        StringFormat fmt2 = new StringFormat();
        fmt2.Trimming = StringTrimming.EllipsisCharacter;
        using (SolidBrush b = new SolidBrush(this.DescriptionColor)) {
            g.DrawString(this.Description, this.DescripionFont, b, textBounds, fmt2);
        }
    }
}

0 个答案:

没有答案