handle for axWebBrowser1 in Form2


D

dawn

Hi,



I'm trying to capture part of Form2 into a bitmap when I click on a button
on the main form (form1). After advice I'm using the following code :



System.IntPtr srcDC=GetDC(Form2.axWebBrowser1.Handle);

Bitmap bm=new Bitmap(50,50);

Graphics g=Graphics.FromImage(bm);

System.IntPtr bmDC=g.GetHdc();


BitBlt(bmDC,250,250,bm.Width,bm.Height,srcDC,0,0,0x00CC0020 /*SRCCOPY*/);

this.pictureBox1.Image = System.Drawing.Image.FromHbitmap(bmDC);


ReleaseDC(srcDC);

g.ReleaseHdc(bmDC);

g.Dispose();



}



Only this doesn't work. cuz on the first line the compiler doesn't recognize
Form2.axWebBrowser1.Handle . I've made it public, but now it says an object
reference is needed for axWebBrowser1.

Is there a way I can get the handle for axWebBrowser1 on Form2??



Thanks.
 
Ad

Advertisements

Ad

Advertisements

N

Nicholas Paldino [.NET/C# MVP]

dawn,

Form2 is the name of a type, and in C#, unlike VB, it does not create a
static instance of Form2 which is accessible. Because of this, you will
have to pass a reference of an instance of Form2 to the routine that is
executing this code.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top