[VB.Net]可以通过用户的控件更改默认表单吗? [英] [VB.Net]Possible to change the default form with a control by the user?

查看:54
本文介绍了[VB.Net]可以通过用户的控件更改默认表单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望FormA显示为默认表单,但是我想要一个控件,比如要检查复选框以将默认加载的表单更改为FormB,或者至少在下次运行程序时自动隐藏表单如果选中该复选框。我想这会涉及一个设置,如果是这样,我会使用什么类型和值?

Well I want FormA to appear as the default form, but I want a control, like a checkbox to be checked to change the default loaded form to FormB, or to at least automatically hide the form the next time the program is run if the checkbox is checked. I imagine this would involve a setting, if so, what Type and Value would I use?

推荐答案

隐藏对你没什么帮助,会产生其他问题。你应该明白,你几乎总是需要一个主窗口。它的行为与其他行为有些不同。例如,如果关闭主窗口,整个应用程序将关闭。还有其他充分的理由让您始终保持主表单的可操作性。你无法真正改变主要形式。哪种形式主要?在 Application.Run 的调用中使用的那个。



你有两个选择。首先,考虑一下:

Hiding won't help you much, will generate other problems. You should understand that you practically always need a main windows. Its behavior is somewhat different from others. For example, if you close main window, the whole application closes. There are other good reasons to keep you main form operational at all times. And you cannot really change the main form. Which form is main? The one used in the call to Application.Run.

You have about two options. First, consider this:
void Main(string[] args) {

    bool skipWebbrowseWindow = // find it, for example, from args

    //...

    if (skipWebbrowseWindow) 
        Application.Run(new MyGameForm())
    else
        Application.Run(new MyIntroForm()); // and it will create other windows later
}

(哦,对不起C#示例,你希望你可以轻松地将它翻译成VB.NET。当你在.NET中寻求帮助时,你至少需要知道一些C#... ...



我认为更好的选择是:始终只使用一个表格。 (但是,如果你有很少的模态形式/对话框,我不算数,它们就好了。)我认为这个选项要好得多。您计划成为表单的应该是仅控制您的表单,通常是面板,但它们也可以是标签页或其他内容。主窗体的外观取决于哪些面板位于顶部且可见。您可以并行安排两个或更多,两个都可见,您可以一次只显示一个。在这里隐藏会很好地为你服务。而那些形式之间的导航就是你的,你不会依赖于Windows桌面的怪异Z顺序。所有应用程序将立即激活(使用表单,您需要使用所有者所有非邮件表单的属性,忘记这个功能的许多make应用程序Z-order真的很难看, 请试试)。有更多理由以一种形式设计它。特别是对于游戏,人们没有时间搞乱桌面。老实说,选择这种方法。



-SA

(Oh, sorry the C# sample, you hope you can easily translate it into VB.NET. When you look for help in .NET, you need to know at least some C#…)

I think better option is this: work only with one form at all times. (However, I don't count if you have few modal forms/dialogs, they are just fine.) I think this option is much, much better. What you planned to be forms should be controls on you only form, typically panels, but they can be also tab pages or something else. And the look of your main form will depend on which of those panels are on top and visible. You can arrange two or more in parallel, both visible, of you can show only one at a time. Here hiding will serve you well. And the navigation between those wonna-be-forms is all yours, you won't depend on weird Z-order of the Windows desktop. All application will be activated at once (with forms, you would need to use Owner properties of all non-mail forms, forgetting this feature by many make application Z-order really ugly, please try). There are more reasons to design it all in just one form. Especially for gaming, where people don't have time to mess up with the desktop. Honestly, choose this approach.

—SA


我提出了自己的解决方案工作得很好。我创建了一个名为'hidevote'的布尔设置,并在启动器/主窗体下使用此代码加载子



I came up with my own solution that works just fine. I created a boolean setting named 'hidevote' and worked with this code under the launcher/main forms Load sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

 If My.Settings.hidevote = True Then
       CheckBox2.Checked = True
       VOTE4US.Hide()
   ElseIf My.Settings.hidevote = False Then
       VOTE4US.Show()
   End If
End Sub







然后我在收盘/关闭子下写了这个。






Then I wrote this under the closing/closed sub.

Private Sub Main_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
    If CheckBox2.Checked = True Then
        My.Settings.hidevote = True
    End If
End Sub

Private Sub Main_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    If CheckBox2.Checked = True Then
        My.Settings.hidevote = True
    End If

End Sub


你需要关注:



1-我们将创建一个文本文件,其中包含您要保存为默认格式的表格

使用您选择的Checkbox事件



You Need to Focus :

1- we will create a text file with the value of the form you want to save as Default
Withing the Checkbox Event of your Choice

File.writealltext("MySetting", "FormA")
 or
File.writealltext("MySetting", "FormB")





2-然后我们将在主窗体中创建逻辑功能(Page_Load)事件





2- Then We Will Create a Logic Function in the Main Form (Page_Load) Event

Dim Setting as string = file.readalltext("MySetting")
If Setting="FormA" Then 
FormA.Hide 
FormB.Show
End if





将检查FormA是否是默认表格或不,如果不是它将隐藏它并显示FormB,任何其他情况将显示FormA为常用所以没有必要额外如果有条件检查



这是一个快速的,我希望它有助于:)



That Will Check if the FormA is the Default form or Not , If Not it will Hide it and Show the FormB , any other case will Display The FormA as Usual so No Need for Extra If Conditional To Check

That's a Quickie and i Hope it Helped :)


这篇关于[VB.Net]可以通过用户的控件更改默认表单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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