我需要将窗体的内容截图存下来,使用下面的代码:
textBox1.BorderBrush = Brushes.Transparent;
FrameworkElement elem = this.Content as FrameworkElement;
RenderTargetBitmap targetBitmap = new RenderTargetBitmap((int)elem.ActualWidth, (int)elem.ActualHeight, 96d, 96d, PixelFormats.Default);
string tmpFileName = "d:\\tempsnap.png";
targetBitmap.Render(this);
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(targetBitmap));
FileStream fs = File.Open(tmpFileName, FileMode.OpenOrCreate);
encoder.Save(fs);
fs.Close();
这个窗体有个TextBox,截图的时候我不想要它的边框,所以第一句代码就是将他的边框设置为透明:
textBox1.BorderBrush = Brushes.Transparent;
可是截出来的图还是有边框的...........
后来我在“textBox1.BorderBrush = Brushes.Transparent”代码之后加了一句MessageBox.Show("A"),让代码停顿片刻,然后继续,边框就没有了。
难道这个设置边框值的操作是异步的吗?有什么方法在它真正生效之后才执行下面的代码?
da jia hao!