导出UltraExpandableGroupBox默认扩展指示器

时间:2019-12-11 17:53:06

标签: c# winforms infragistics

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

2 个答案:

答案 0 :(得分:0)

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

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;
}
  

展开/折叠指示器位图输出到文件中,如下图所示:

enter image description here

答案 1 :(得分:0)

您可以使用简单的DrawFilter来实现。设置为您的UltraExpandableGroupBox DraFilter属性,如下所示:

this.myUltraExpandableGroupBox.DrawFilter = new MyDrawFilter(expandedIndicator, collapsedInidcator);

然后创建一个名为MyDrawFilter的新类,并使其继承IUIElementDrawFilter。您的绘图过滤器类可能如下所示:

    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;
        }
    }