मुझे लगता है कि आयत को चित्रित करने से पहले इसे मूल डेटा को अस्थायी बिटमैप में कॉपी करने के लिए काम करना चाहिए, और उसके बाद बिटमैप को वापस जगह पर खींचें।
अद्यतन
वहां पहले से ही एक स्वीकृत जवाब है, लेकिन मैंने सोचा कि मैं एक कोड नमूना वैसे भी साझा कर सकता। यह एक दिया नियंत्रण पर लाल रंग में दिया आयत ड्रॉ, और 500 एमएस के बाद क्षेत्र पुनर्स्थापित करता है।
public void ShowRectangleBriefly(Control ctl, Rectangle rect)
{
Image toRestore = DrawRectangle(ctl, rect);
ThreadPool.QueueUserWorkItem((WaitCallback)delegate
{
Thread.Sleep(500);
this.Invoke(new Action<Control, Rectangle, Image>(RestoreBackground), ctl, rect, toRestore);
});
}
private void RestoreBackground(Control ctl, Rectangle rect, Image image)
{
using (Graphics g = ctl.CreateGraphics())
{
g.DrawImage(image, rect.Top, rect.Left, image.Width, image.Height);
}
image.Dispose();
}
private Image DrawRectangle(Control ctl, Rectangle rect)
{
Bitmap tempBmp = new Bitmap(rect.Width + 1, rect.Height + 1);
using (Graphics g = Graphics.FromImage(tempBmp))
{
g.CopyFromScreen(ctl.PointToScreen(new Point(rect.Top, rect.Left)), new Point(0, 0), tempBmp.Size);
}
using (Graphics g = this.CreateGraphics())
{
g.DrawRectangle(Pens.Red, rect);
}
return tempBmp;
}
स्रोत
2009-06-11 19:30:46
जानते हैं कि इस मामले में ओवरले पैनल माउस क्लिक रोकना होगा रहें, ताकि आप अंतर्निहित पैनल के लिए सभी प्रासंगिक घटनाओं को आगे करना चाहिए। –