我在WPF中使用web browser控件,全屏打开一个flash,代码如下:<Window x:Class="B1Motion.ViewDashboard"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ViewDashboard" Height="1010" Width="1900">
<Grid>
<WebBrowser x:Name="WebBrowser1" Source="file://127.0.0.1/c$/dashboard1.swf"></WebBrowser>
</Grid>
</Window>
我希望鼠标移动到某个位置时,可以在鼠标下方显示一个浮动的进度条,这个进度条可以是一张动态的图片,不需要考虑实际进度,请问各位大侠有没有好的方法,我在google上没有找到比较有价值的资料,最好是基于.net framework4.0的版本。弹出窗口也行,但是要求隐藏掉窗口的标题栏和状态栏。
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ViewDashboard" Height="1010" Width="1900">
<Grid>
<WebBrowser x:Name="WebBrowser1" Source="file://127.0.0.1/c$/dashboard1.swf"></WebBrowser>
</Grid>
</Window>
我希望鼠标移动到某个位置时,可以在鼠标下方显示一个浮动的进度条,这个进度条可以是一张动态的图片,不需要考虑实际进度,请问各位大侠有没有好的方法,我在google上没有找到比较有价值的资料,最好是基于.net framework4.0的版本。弹出窗口也行,但是要求隐藏掉窗口的标题栏和状态栏。
解决方案 »
- c#开发的Web程序发布时,能把源代码封装吗?
- 为结此帖者散分100
- 在KeyDown事件中怎么屏蔽掉KeyUp事件
- 正则表达式 在线急求
- c#与LOTUS NOTES的连接
- 为什么窗体不能接收委托方法中得到的数据呢
- 帮我看看上传文件的一段程序!!!!!!
- 如果用户直接关闭窗体则将捕捉这个关闭窗体的事件将会员设置成离线
- 频繁操作导致程序崩溃:System.AccessViolationException:尝试读取或写入受保护的内存。这通常指示其他内存已损坏
- 数据库Update出错,在线等待,高分求解
- 系统定时自动执行一个任务用什么办法。
- asp.net实现附件预览功能,类似邮箱中的附件预览功能
这个站点有说到“C#进度条在弹出窗口中显示”,但是我在WPF中没法调试通,有可能用的是winform,我对于桌面应用这块不是很熟悉,请教WPF达人把这段代码改为WPF的实现,或者WPF调用winform控件也可以啊!
<local:GifImage Background="Transparent" Source="/Resources/load.gif" Height="14" Width="190" Margin="260,244,66,57"></local:GifImage>c# 代码
[code=C#]
public class GifImage : System.Windows.Controls.UserControl
{
private GifAnimation gifAnimation = null;
private Image image = null; public GifImage()
{
} public static readonly DependencyProperty ForceGifAnimProperty = DependencyProperty.Register("ForceGifAnim", typeof(bool), typeof(GifImage), new FrameworkPropertyMetadata(false));
public bool ForceGifAnim
{
get
{
return (bool)this.GetValue(ForceGifAnimProperty);
}
set
{
this.SetValue(ForceGifAnimProperty, value);
}
} public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(string), typeof(GifImage), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnSourceChanged)));
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
GifImage obj = (GifImage)d;
string s = (string)e.NewValue;
obj.CreateFromSourceString(s);
}
public string Source
{
get
{
return (string)this.GetValue(SourceProperty);
}
set
{
this.SetValue(SourceProperty, value);
}
}
public static readonly DependencyProperty StretchProperty = DependencyProperty.Register("Stretch", typeof(Stretch), typeof(GifImage), new FrameworkPropertyMetadata(Stretch.Fill, FrameworkPropertyMetadataOptions.AffectsMeasure, new PropertyChangedCallback(OnStretchChanged)));
private static void OnStretchChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
GifImage obj = (GifImage)d;
Stretch s = (Stretch)e.NewValue;
if (obj.gifAnimation != null)
{
obj.gifAnimation.Stretch = s;
}
else
if (obj.image != null)
{
obj.image.Stretch = s;
}
}
public Stretch Stretch
{
get
{
return (Stretch)this.GetValue(StretchProperty);
}
set
{
this.SetValue(StretchProperty, value);
}
} public static readonly DependencyProperty StretchDirectionProperty = DependencyProperty.Register("StretchDirection", typeof(StretchDirection), typeof(GifImage), new FrameworkPropertyMetadata(StretchDirection.Both, FrameworkPropertyMetadataOptions.AffectsMeasure, new PropertyChangedCallback(OnStretchDirectionChanged)));
private static void OnStretchDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
GifImage obj = (GifImage)d;
StretchDirection s = (StretchDirection)e.NewValue;
if (obj.gifAnimation != null)
{
obj.gifAnimation.StretchDirection = s;
}
else
if (obj.image != null)
{
obj.image.StretchDirection = s;
}
}
public StretchDirection StretchDirection
{
get
{
return (StretchDirection)this.GetValue(StretchDirectionProperty);
}
set
{
this.SetValue(StretchDirectionProperty, value);
}
} public delegate void ExceptionRoutedEventHandler(object sender, GifImageExceptionRoutedEventArgs args); public static readonly RoutedEvent ImageFailedEvent = EventManager.RegisterRoutedEvent("ImageFailed", RoutingStrategy.Bubble, typeof(ExceptionRoutedEventHandler), typeof(GifImage)); public event ExceptionRoutedEventHandler ImageFailed
{
add
{
AddHandler(ImageFailedEvent, value);
}
remove
{
RemoveHandler(ImageFailedEvent, value);
}
} void image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
{
RaiseImageFailedEvent(e.ErrorException);
}
void RaiseImageFailedEvent(Exception exp)
{
GifImageExceptionRoutedEventArgs newArgs = new GifImageExceptionRoutedEventArgs(ImageFailedEvent, this);
newArgs.ErrorException = exp;
RaiseEvent(newArgs);
}
private void DeletePreviousImage()
{
if (image != null)
{
this.RemoveLogicalChild(image);
image = null;
}
if (gifAnimation != null)
{
this.RemoveLogicalChild(gifAnimation);
gifAnimation = null;
}
} private void CreateNonGifAnimationImage()
{
image = new Image();
image.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(image_ImageFailed);
ImageSource src = (ImageSource)(new ImageSourceConverter().ConvertFromString(Source));
image.Source = src;
image.Stretch = Stretch;
image.StretchDirection = StretchDirection;
this.AddChild(image);
}
{
gifAnimation = new GifAnimation();
gifAnimation.CreateGifAnimation(memoryStream);
gifAnimation.Stretch = Stretch;
gifAnimation.StretchDirection = StretchDirection;
this.AddChild(gifAnimation);
}
private void CreateFromSourceString(string source)
{
DeletePreviousImage();
Uri uri; try
{
uri = new Uri(source, UriKind.RelativeOrAbsolute);
}
catch (Exception exp)
{
RaiseImageFailedEvent(exp);
return;
} if (source.Trim().ToUpper().EndsWith(".GIF") || ForceGifAnim)
{
if (!uri.IsAbsoluteUri)
{
GetGifStreamFromPack(uri);
}
else
{ string leftPart = uri.GetLeftPart(UriPartial.Scheme); if (leftPart == "http://" || leftPart == "ftp://" || leftPart == "file://")
{
GetGifStreamFromHttp(uri);
}
else
if (leftPart == "pack://")
{
GetGifStreamFromPack(uri);
}
else
{
CreateNonGifAnimationImage();
}
}
}
else
{
CreateNonGifAnimationImage();
}
} private delegate void WebRequestFinishedDelegate(MemoryStream memoryStream); private void WebRequestFinished(MemoryStream memoryStream)
{
CreateGifAnimation(memoryStream);
}
private delegate void WebRequestErrorDelegate(Exception exp);
private void WebRequestError(Exception exp)
{
RaiseImageFailedEvent(exp);
} private void WebResponseCallback(IAsyncResult asyncResult)
{
WebReadState webReadState = (WebReadState)asyncResult.AsyncState;
WebResponse webResponse;
try
{
webResponse = webReadState.webRequest.EndGetResponse(asyncResult);
webReadState.readStream = webResponse.GetResponseStream();
webReadState.buffer = new byte[100000];
webReadState.readStream.BeginRead(webReadState.buffer, 0, webReadState.buffer.Length, new AsyncCallback(WebReadCallback), webReadState);
}
catch (WebException exp)
{
this.Dispatcher.Invoke(DispatcherPriority.Render, new WebRequestErrorDelegate(WebRequestError), exp);
}
} private void WebReadCallback(IAsyncResult asyncResult)
{
WebReadState webReadState = (WebReadState)asyncResult.AsyncState;
int count = webReadState.readStream.EndRead(asyncResult);
if (count > 0)
{
webReadState.memoryStream.Write(webReadState.buffer, 0, count);
try
{
webReadState.readStream.BeginRead(webReadState.buffer, 0, webReadState.buffer.Length, new AsyncCallback(WebReadCallback), webReadState);
}
catch (WebException exp)
{
this.Dispatcher.Invoke(DispatcherPriority.Render, new WebRequestErrorDelegate(WebRequestError), exp);
}
}
else
{
this.Dispatcher.Invoke(DispatcherPriority.Render, new WebRequestFinishedDelegate(WebRequestFinished), webReadState.memoryStream);
}
} private void GetGifStreamFromHttp(Uri uri)
{
try
{
WebReadState webReadState = new WebReadState();
webReadState.memoryStream = new MemoryStream();
webReadState.webRequest = WebRequest.Create(uri);
webReadState.webRequest.Timeout = 10000; webReadState.webRequest.BeginGetResponse(new AsyncCallback(WebResponseCallback), webReadState);
}
catch (SecurityException)
{
CreateNonGifAnimationImage();
}
}
private void ReadGifStreamSynch(Stream s)
{
byte[] gifData;
MemoryStream memoryStream;
using (s)
{
memoryStream = new MemoryStream((int)s.Length);
BinaryReader br = new BinaryReader(s);
gifData = br.ReadBytes((int)s.Length);
memoryStream.Write(gifData, 0, (int)s.Length);
memoryStream.Flush();
}
CreateGifAnimation(memoryStream);
} private void GetGifStreamFromPack(Uri uri)
{
try
{
StreamResourceInfo streamInfo; if (!uri.IsAbsoluteUri)
{
streamInfo = Application.GetContentStream(uri);
if (streamInfo == null)
{
streamInfo = Application.GetResourceStream(uri);
}
}
else
{
if (uri.GetLeftPart(UriPartial.Authority).Contains("siteoforigin"))
{
streamInfo = Application.GetRemoteStream(uri);
}
else
{
streamInfo = Application.GetContentStream(uri);
if (streamInfo == null)
{
streamInfo = Application.GetResourceStream(uri);
}
}
}
if (streamInfo == null)
{
throw new FileNotFoundException("Resource not found.", uri.ToString());
}
ReadGifStreamSynch(streamInfo.Stream);
}
catch (Exception exp)
{
RaiseImageFailedEvent(exp);
}
}
}
[/code]
Popup p = new Popup();
panel1.Children.Clear();
panel1.Children.Add(XXXX);
p.VerticalOffset = 25;
p.HorizontalOffset = 25;
p.IsOpen = true;
结贴吧!感谢各位的回答。