C# 导出UltraExpandableGroupBox默认扩展指示符

C# 导出UltraExpandableGroupBox默认扩展指示符,c#,winforms,infragistics,C#,Winforms,Infragistics,我正在WinForms应用程序中使用UltraExpandableGroupBox。我用的是Office2003风格。但是,我想反转使用的展开和折叠指示器图像。我试图从.isl文件中导出图像,但这些图像似乎不在导出的图像中。如何访问这些图像?当UltraExpandableGroupBox控件的ViewStyle属性设置为GroupBoxViewStyle时。Office2003展开/折叠指示器使用嵌入位图。 下面的代码演示如何在运行时从程序集获取此位图,并可用于反转当前展开/折叠的指示器: p

我正在WinForms应用程序中使用UltraExpandableGroupBox。我用的是Office2003风格。但是,我想反转使用的展开和折叠指示器图像。我试图从.isl文件中导出图像,但这些图像似乎不在导出的图像中。如何访问这些图像?

UltraExpandableGroupBox
控件的ViewStyle属性设置为
GroupBoxViewStyle时。Office2003
展开/折叠指示器使用嵌入位图。 下面的代码演示如何在运行时从程序集获取此位图,并可用于反转当前展开/折叠的指示器:

private void ReverseImage_Click(object sender, EventArgs e)
{
    var imageName = "GroupBox.ExpansionIndicator_Chevron.bmp";
    System.IO.Stream stream = typeof(UltraExpandableGroupBox).Module.Assembly.GetManifestResourceStream(typeof(UltraExpandableGroupBox), imageName);

    if (stream != null)
    {
        // The source bitmap has 7x10px size. 
        var image = Bitmap.FromStream(stream);
        // Converting the image to 16x16 pixels
        ultraExpandableGroupBox1.ExpansionIndicatorExpanded = ResizeImage(image, 16, 16);
        // Rotation
        using (var bmp = new Bitmap(image))
        {
            bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
            image = bmp.Clone() as Image;

            // Exporting bitmap to a file
            bmp.Save(@".\" + imageName, ImageFormat.Bmp);
        }                
        ultraExpandableGroupBox1.ExpansionIndicatorCollapsed = ResizeImage(image, 16, 16);
    }
} 

public static Image ResizeImage(Image image, int new_height, int new_width)
{
    var dest = new Bitmap(new_width, new_height);
    var g = Graphics.FromImage(dest);
    g.InterpolationMode = InterpolationMode.High;
    g.DrawImage(image, (dest.Width - image.Width)/2, (dest.Height-image.Height)/2);
    return dest;
}
导出到文件后,展开/折叠的指示器位图如下图所示:


您可以通过简单的操作来实现这一点。按如下方式设置UltraExpandableGroupBox DraFilter属性:

this.myUltraExpandableGroupBox.DrawFilter = new MyDrawFilter(expandedIndicator, collapsedInidcator);
    public class MyDrawFilter : IUIElementDrawFilter
    {
        Image expandedIndicator;
        Image collapsedIndicator;
        public MyDrawFilter(Image expandedIndicator, Image collapsedInidcator)
        {
            this.expandedIndicator = expandedIndicator;
            this.collapsedIndicator = collapsedInidcator;
        }
        public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
        {
            if (drawParams.Element is GroupBoxExpansionIndicatorUIElement)
            {
                // if groupbox is expanded change the image with one provided in the constructor
                // as expandedIndicator
                if ((drawParams.Element.Control as UltraExpandableGroupBox).Expanded)
                {
                    (drawParams.Element.ChildElements[0] as ImageUIElement).Image = this.expandedIndicator;
                }
                // else gropbox is collapsed change the image with one provided in the constructor
                // as collapsedIndicator
                else
                {
                    (drawParams.Element.ChildElements[0] as ImageUIElement).Image = this.collapsedIndicator;
                }
            }

            return false;
        }

        public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams)
        {
            // filter when GroupBoxExpansionIndicatorUIElement should be drawn. This element has
            // one child UIElement of ImageUIElement type. This UIElement holds the expansion
            // indicator image.
            if (drawParams.Element is GroupBoxExpansionIndicatorUIElement)
            {
                // we return BeforeDrawChildeElements in order to be able to change the image
                return DrawPhase.BeforeDrawChildElements;
            }

            return DrawPhase.None;
        }
    }
然后创建一个名为
MyDrawFilter
的新类,并让它继承
iIElementDrawFilter
。绘制过滤器类可能如下所示:

this.myUltraExpandableGroupBox.DrawFilter = new MyDrawFilter(expandedIndicator, collapsedInidcator);
    public class MyDrawFilter : IUIElementDrawFilter
    {
        Image expandedIndicator;
        Image collapsedIndicator;
        public MyDrawFilter(Image expandedIndicator, Image collapsedInidcator)
        {
            this.expandedIndicator = expandedIndicator;
            this.collapsedIndicator = collapsedInidcator;
        }
        public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
        {
            if (drawParams.Element is GroupBoxExpansionIndicatorUIElement)
            {
                // if groupbox is expanded change the image with one provided in the constructor
                // as expandedIndicator
                if ((drawParams.Element.Control as UltraExpandableGroupBox).Expanded)
                {
                    (drawParams.Element.ChildElements[0] as ImageUIElement).Image = this.expandedIndicator;
                }
                // else gropbox is collapsed change the image with one provided in the constructor
                // as collapsedIndicator
                else
                {
                    (drawParams.Element.ChildElements[0] as ImageUIElement).Image = this.collapsedIndicator;
                }
            }

            return false;
        }

        public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams)
        {
            // filter when GroupBoxExpansionIndicatorUIElement should be drawn. This element has
            // one child UIElement of ImageUIElement type. This UIElement holds the expansion
            // indicator image.
            if (drawParams.Element is GroupBoxExpansionIndicatorUIElement)
            {
                // we return BeforeDrawChildeElements in order to be able to change the image
                return DrawPhase.BeforeDrawChildElements;
            }

            return DrawPhase.None;
        }
    }