强制画布刷新 [英] force canvas to refresh

查看:85
本文介绍了强制画布刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个大的wpf画布(1920 * 1080),里面有一个小型网页浏览器(400 * 300),我想要复制完全尺寸的浏览器(1920 * 1080)并在其位置设置图像(400 * 300)。



所以首先我得到以前的浏览器大小及其在我的屏幕上的位置

然后我最大化浏览器并将其位置设置为(0,0)

然后我复制屏幕

然后我让浏览器消失并将图像(先前尺寸为400 * 300)设置为上一个位置



我不希望用户看到用户的全尺寸,所以一切都在后面的代码中完成,问题是副本是在小浏览器上完成的窗口



所以我尝试了



I have a big wpf canvas (1920*1080) with a small web browser (400*300) in it, i want to copy the browser at full size (1920*1080) and set an image at its place(400*300) instead.

So first i get the previous size of the browser and its position on my screen
then i maximise the browser and set its position to (0,0)
then i copy the screen
then i make the browser disapear and sets a image (400*300 the previous size) to the previous position

I don't want the user to see the user full size , so all is done in the code behind , the problem is that the copy is done on a small browser window

so I tried

UpdateLayout()

几乎没有成功,它juste移动了浏览器窗口但没有'调整大小

with almost no success, it juste moved the browser window but didn't resize it

推荐答案

当我加载Web浏览器时,我设置一个10s计时器来启动该功能设置为最大尺寸,复制并设置前面的图像



private void webUserControl_Loaded(object sender,RoutedEventArgs e)

{

double widthBefore =宽度;

double heightBefore =高度;

double leftPosBefore = Canvas.GetLeft(this);

double topPosBefore = Canvas.GetTop(this);



计时器webContentTimer = new Timer();

webContentTimer.AutoReset = false;

webContentTimer.Interval = 10000;

webContentTimer.Elapsed + =(oo,ee)=> {

DispatcherOperation dispatcherOp = Dispatcher.BeginInvoke(

DispatcherPriority.ApplicationIdle,new Action(delegate()

{

Canvas.SetLeft(this,0);

Canvas.SetTop(this,0);

containerWeb.setFreshMeasure(screenWidth_,screenHeight_);

宽度= screenWidth_;

高度= screenHeight_;

UpdateLayout();}));



dispatcherOp.Completed + = new EventHandler((ooo,eee)=> {

containerWeb.setImageInFront(true);



Canvas。 SetLeft(this,leftPosBefore);

Canvas.SetTop(this,topPosBefore);

containerWeb.setFreshMeasure(wi dthBefore,heightBefore);

Width = widthBefore;

Height = heightBefore;

webContentTimer.Stop();});

};



webContentTimer.Start();

}
when i load the web browser, i set a 10s timer to launch the function which set to max size, copy and set the image in front

private void webUserControl_Loaded(object sender, RoutedEventArgs e)
{
double widthBefore = Width;
double heightBefore = Height;
double leftPosBefore = Canvas.GetLeft(this);
double topPosBefore = Canvas.GetTop(this);

Timer webContentTimer = new Timer();
webContentTimer.AutoReset = false;
webContentTimer.Interval = 10000;
webContentTimer.Elapsed += (oo, ee) => {
DispatcherOperation dispatcherOp = Dispatcher.BeginInvoke(
DispatcherPriority.ApplicationIdle, new Action(delegate()
{
Canvas.SetLeft(this, 0);
Canvas.SetTop(this, 0);
containerWeb.setFreshMeasure(screenWidth_, screenHeight_);
Width = screenWidth_;
Height = screenHeight_;
UpdateLayout();}));

dispatcherOp.Completed += new EventHandler((ooo,eee) => {
containerWeb.setImageInFront(true);

Canvas.SetLeft(this, leftPosBefore);
Canvas.SetTop(this, topPosBefore);
containerWeb.setFreshMeasure(widthBefore, heightBefore);
Width = widthBefore;
Height = heightBefore;
webContentTimer.Stop();});
};

webContentTimer.Start();
}


其实为了使它工作,有一个我想避免的丑陋。这是设置2个事件:



第一个在加载后10000毫秒发生并最大化浏览器



然后一个等待40毫秒的第二个事件复制屏幕并设置小图像



它很难看
in fact to make it work, there is an ugly one that i'd like to avoid. It is to set 2 events :

the first one happens 10000 millisecond after the loading and maximises the browser

then one waits 40 milliseconds for the second event which copies the screen and sets the small image

it's ugly


这篇关于强制画布刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆