c3_balu

c3_balu

  • NA
  • 2
  • 0

How can I create the Thumbnail view from the form?

Mar 16 2005 9:15 AM
Thumbnail Problem ============= How can I create the Thumbnail view from the form? In the following approach we tried but we are facing some limitations to get the thumbnail image of the form alone. Can any body help in this regard, Thanks, Balu Ramachandran Approach - I - Bitmap (screen capture method) ============================================= Can able to create the thumbnail image using Bitmap and BitBlt. Code Sample: ========== Graphics g1 = this.CreateGraphics(); Image MyImage = new Bitmap(this.ClientRectangle.Width,this.ClientRectangle.Height, g1); Graphics g2 = Graphics.FromImage(MyImage); IntPtr dc1 = g1.GetHdc(); IntPtr dc2 = g2.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376); g1.ReleaseHdc(dc1); g2.ReleaseHdc(dc2); MyImage.Save(@"c:\BaluCaptured.jpg", ImageFormat.Jpeg); MessageBox.Show("Finished Saving Image"); Limitations Facing: ============== 1) Not able to capture the non visible portion of the form. 2) If the specified region size is beyond the visible portion in the screen, then remaining portions are in black color. Approach - II - Metafile ================ Can able create the image using Metafile approach. How can we create the metafile for user controls drawn objects (Example: Graphs, Gauges). Graphics grph = this.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(@"d:\TestBalu.emf", ipHDC, EmfType.EmfPlusDual); //grph.ReleaseHdc(ipHDC); //grph.Dispose(); grph = Graphics.FromImage(mf); grph.DrawRectangle(Pens.Blue, 10, 10, 100, 120); Point p1 =new Point(20,60); Point p2 =new Point(40,80); Point p3 =new Point(100,120); Point p4 =new Point(120,260); Rectangle re=new Rectangle(30,20,60,90); grph.DrawBezier(Pens.Gold, p1,p4,p3,p2); grph.DrawBezier(Pens.Gold, p2,p4,p3,p2); grph.Dispose(); Limitations Facing: ============== 1) This can be possible for regular Graphics objects like creating Rectangle, Ellipse... using System.Drawing class. 2) It is not supporting for 3rd Party controls like Dundas gauge controls. When we try to create the metafile (emf) the file size shows 0KB. It is not writing the data in to the file. Approach – III – Scale down the Form ========================== How to clone the form which contains the graphics objects like rectangle, user controls? When we are trying to clone, it is only referring the memory; it is not actually cloning the object. Code Sample: ========== Form2 obj = new Form2(); obj.Width = 640; obj.Height = 480; obj.BackColor = Color.Green; obj.Show(); Form obj1 = new Form2(); obj1 = obj; obj1.MaximizeBox = false; obj1.MinimizeBox = false; obj1.ControlBox = false; obj1.FormBorderStyle = FormBorderStyle.None; obj1.Scale(0.2f, 0.2f); obj1.Show(); Limitations Facing: ============= In .net we don’t have direct clone method to clone the form object. How can we clone the form object?

Answers (2)