Is it possible to show SilverLight busy indicator inside Winforms application?

£可爱£侵袭症+ 提交于 2019-12-10 11:55:28

问题


Currently i am using a simple PictureBox with GIF file inside and wonder if this is possible and if it does what the differences between this 2 options

This is what i have at this moment using PictureBox:

pictureBox1.BringToFront();
pictureBox1.Dock = DockStyle.None;
pictureBox1.Visible = true;

回答1:


You can try hosting SilverLight inside Winforms.

While SilverLight is intended to be used in a web browser, WPF is more native to desktop, and WPF does have a simimar BusyIndicator, it is downloadable from CodePlex-Extended WPF Toolkit.

First define a WPF user control MyBusyIndicator.

<UserControl x:Class="Stackoverflow.MyBusyIndicator"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <xctk:BusyIndicator IsBusy="True" />
    </Grid>
</UserControl>

Then you can host this user control in Winform using an ElementHost, first you add the ElementHost from Form's designer, and in Form's constructor

public partial class MyForm : Form
{
    public MyForm ()
    {
        InitializeComponent();
        this.elementHost1.Child = new Stackoverflow.MyBusyIndicator();
    }
}

The differences:

While BusyIndicator comes with some properties to let you customize the indicator, it adds a dependency on SL or WPF. With PictureBox all you need to do is preparing animated GIFs. There are many tools for generating animated GIFs.



来源:https://stackoverflow.com/questions/27674884/is-it-possible-to-show-silverlight-busy-indicator-inside-winforms-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!