我可以承载Windows窗体控件内 [英] Can I host a Windows Form inside a control

查看:176
本文介绍了我可以承载Windows窗体控件内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户它作为一个Visual Basic项目单一实例模式与有线presentation逻辑。

I have a customer which as a Visual Basic Project in single instance mode with a wired presentation logic.

主窗体包含有复式的TabPages TabControl的一个。 如果我点击TabPageA另一种形式示出的形态前和调整为具有相同的尺寸与TabPage的

The main form contains a TabControl with mutliple TabPages. If I click on TabPageA another form is shown in front of the Form and resized to have the same size as the TabPage.

如果我点击TabPageB的第一种形式是隐藏的,则显示另一种形式。 所以基本上用户看起来你有不同的TabPages TabControl的一个是情况并非如此。

If I click on TabPageB the first form is hidden and another form is displayed. So basically for the user it looks like you have a TabControl with different TabPages which is not the case.

我试着转换形式为用户控件,并把他们的TabPage的内部,但是,由于SingleInstance的应用程序,这将需要一个整体大量的重构。我尝试过,但最终放弃了,因为很多很多的运行时错误了,我不希望把更多的精力在此。

I tried converting the Forms to UserControls and put them inside the TabPage, but, thanks to the SingleInstance app, this would take a whole lot of refactoring. I tried it but eventually gave up because of many many runtime errors and I don't want to put any more effort in this.

我Ideam是,在运行时,我可以添加表格到的TabPages,让他们像用户控件,这甚至可能吗?

My Ideam was that, at runtime, I could add the forms to the TabPages and let them act like UserControls, is this even possible?

推荐答案

您可以通过它的顶层属性设置为False把一个Form类回子控件。它成为基本上与一些未使用的开销一个用户控件。使它看起来类似于这样:

You can turn a Form class back to a child control by setting its TopLevel property to False. It becomes essentially a UserControl with some unused overhead. Make it look similar to this:

Public Class Form1
    Public Sub New()
        InitializeComponent()
        Dim frm As New Form2
        frm.TopLevel = False
        frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        frm.Visible = True
        frm.Dock = DockStyle.Fill
        TabPage1.Controls.Add(frm)
    End Sub
End Class

这篇关于我可以承载Windows窗体控件内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆