开发者

The solution to detach a control from a form

I use Java Applet like an example. When you open a website which has a java applet on web page. The java applet application will run in web page. Applet support to detach itself out of the web page and run as a single instance.

I have a question: If I have a control inside a form, or this control maybe in a lot of other controls. On the form will have a Full Screen button. When 开发者_C百科user click on it, I want this control will be full screen. HOw to do it? Please give me the solution.

Thanks.

Note: My application is WinFORM C#, .NET 2.0.


A control can't live outside a form.

In your case the easiest solution would probably to modify the form to make it full screen (i.e. remove borders by changing border style, change position and size to fill the whole screen), and then modify the control to make it fill the form (you can change it's container to be the form).

Then when you exit full screen mode, restore everything to how it was before.


You could try something like this,

private void btnFullScreen(object sender, EventArgs e)
    {
        // save customControl 's location and size first so you can restore later.
        // assuming customControl is your control
        customControl .Width = this.Width;
        customControl .Height = this.Height;
        customControl .Top = 0;
        customControl .Left = 0;
        this.FormBorderStyle = FormBorderStyle.None;
        this.WindowState = FormWindowState.Maximized;
    }


I didn't understand what you are trying to achieve. But you can make a control fullscreen by making the Form full screen, otherwise no otherway I think. Because a control cannot live without a Form. Try this code, which will help you to make a web browser control fullscreen.

//This statement may not require for you. For me the browser control is inside a Panel.
this.webBrowser1.Parent = this; 

this.webBrowser1.Dock = DockStyle.Fill;
this.webBrowser1.BringToFront();
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜