【问题标题】:application doesn't show in taskbar with application.run(FRM). Tried multiple things应用程序未使用 application.run(FRM) 显示在任务栏中。尝试了多种方法
【发布时间】:2017-02-17 23:20:43
【问题描述】:

运行框架 4.0 (VB.net)

属性 ShowInTaskbar 设置为 True。

这里是运行主窗口的代码。

 Dim frm As New frmMain
 frm.ShowInTaskbar = True
 Application.Run(frm)

这里是来自 frmMain 的所有代码

  Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
        Application.DoEvents()
        Me.Focus()
        Me.Activate()

        PeutExecuterSynchronisationAutomatique = True
        'placer le bouton d'aide en ligne 
        btnAideToolTip.Location = New Point((btnPreference.Location.X - btnAideToolTip.Width) - 5, btnAideToolTip.Location.Y)
        btnAideToolTip.Visible = True



        Label5.Text = "version(x)"

    Catch ex As Exception
        HandleException(ex)
    End Try
End Sub

这里是继承表单的所有代码

Public Overridable Sub FormBase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try


        If Not designmode AndAlso Not Application.ExecutablePath.ToLower().IndexOf("devenv.exe") > -1 Then
            If EasyDealINI.FichierINIEasyDealTailleDefaut = False Then

                Me.Height = CInt(Me.Height * Ratio)
                Me.Width = CInt(Me.Width * Ratio)
                Me.Font = New Font(Me.Font.FontFamily, (Me.Font.Size * Ratio) - (DIMINUEUR_RATIO_POLICE * Ratio), Me.Font.Style)


                Me.CenterToScreen()

                UC_MenuBottom.AjusterControles()
                UC_MenuBottom.AppliquerTypeBouton()
            End If
        End If


        If Not DesignMode Then
            'Sert à ce qu'EasyDeal en plein écran n'ait pas l'air d'un Transformer qui se déplie.
            'Me.Visible = False --> Suspend le layout dans FormBaseDetailCalcul (voir AjusterControls) - Philippe 2008/06/04

            If Not FormBase.DossierImagesPath Is Nothing Then
                Dim strNomFichier As String = FormBase.DossierImagesPath & "Icone.ico"  'Le signe chinois
                'Dim strNomFichier As String = FormBase.DossierImagesPath & "Logo.ico"   'La terre
                Dim Fichier As New FileInfo(strNomFichier)
                If Fichier.Exists Then
                    Me.Icon = New Icon(strNomFichier)
                End If
            End If
        End If

        Me.MaximizeBox = False
        Me.MinimizeBox = True
        DesactiverCloseBouton()

        'Pour permettre que sur le ENTER la navigation se fasse comme en Access
        '(Agir comme un (TAB)... Voir évenement FormBase_KeyUp
        Me.KeyPreview = True
        Me.ShowInTaskbar = True
        Me.StartPosition = FormStartPosition.CenterScreen

        Me.AppliquerCouleurs(Me)

        'on met Easydeal comme texte de fenêtre 
        Me.Text = DEFAULT_WINDOW_TEXT
        Me.Focus()
        Me.Activate()

    Catch ex As Exception
        HandleException(ex)
    End Try
End Sub

但这无济于事,即使我点击表单,应用程序也不会出现在任务栏上。

然而,真正奇怪的是,如果我设置了一个断点,或者我首先单击任务栏,然后再次单击程序将出现在任务栏上的窗体。

alt-tab 使程序也出现在任务栏中。

谢谢!

【问题讨论】:

  • 请粘贴更多代码。表单加载事件至少
  • 这里是......不过那里没有太多
  • 应用程序有标题吗?

标签: c# .net vb.net winforms taskbar


【解决方案1】:

什么是窗口的 F​​ormBorderStyle?如果是 FixedToolWindow,则不会显示在任务栏中

【讨论】:

  • 固定对话框或固定单曲
  • 将FormBorderStyle设置为FixedSingle并将MaximizeBoxMinimizeBox设置为false可以达到同样的效果
【解决方案2】:

对不起,我只有 C# 示例,但同样的逻辑适用!

在某些情况下,我在 Form_Load 方法中完成了表单调整大小或定位的情况下看到了这个问题。像这样的任何动作:

// Set Size and location of items...
this.MaximumSize = new System.Drawing.Size(1012, 665);
this.MinimumSize = new System.Drawing.Size(1012, 665);
this.MaximizeBox = false;

或类似的东西:

// Centre the main form to centre screen...
this.Location = new Point((Screen.PrimaryScreen.Bounds.Size.Width / 2) - (this.Size.Width / 2), (Screen.PrimaryScreen.Bounds.Size.Height / 2) - (this.Size.Height / 2));

如果您需要执行上述任何操作,请确保在正确的位置完成。我更喜欢我的:

Form1()

方法就在:

// Initialize Components...
InitializeComponent();

方法。这将确保您的表单图标出现并解决您的问题。

【讨论】:

  • 当您说Form的“图标”时,您是指切换到该窗口的标准程序选项卡吗?
  • Windows 窗体应用程序图标,运行时通常位于任务栏中的图标。
【解决方案3】:

使用这两行在我的表单加载事件中切换 ShowInTaskbar:

仅当窗口不是模态窗口时才有效。就目前而言,这有点好。

This.ShowInTaskbar = False;
This.ShowInTaskbar = True;

但是,如果我在模式窗口 showmeintaskbar 上设置为 false,则表单会自行关闭

这里是调用栈:

>   EasyDeal.exe!EasyDeal.Windows.UI.FrmMenuSuivi.FrmMenuSuivi_FormClosing(Object sender, System.Windows.Forms.FormClosingEventArgs e) Line 382 Basic
System.Windows.Forms.dll!System.Windows.Forms.Form.OnFormClosing(System.Windows.Forms.FormClosingEventArgs e) + 0x85 bytes  
System.Windows.Forms.dll!System.Windows.Forms.Form.CheckCloseDialog(bool closingOnly) + 0x8d bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FContinueMessageLoop(int reason, int pvLoopData, System.Windows.Forms.NativeMethods.MSG[] msgPeeked) + 0x148 bytes   
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x1e9 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x16c bytes  
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) + 0x33 bytes    
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) + 0x38f bytes    
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog() + 0x7 bytes 
EasyDeal.exe!EasyDeal.Windows.UI.EasyDealCommon.ShowEasyDealForm(EasyDeal.Windows.UI.FormBase formToShow, EasyDeal.Windows.UI.FormBase formSender, Boolean closeFormSender, Boolean forceDialog) Line 2787 + 0xc bytes  Basic

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2019-09-21
    • 2016-11-17
    • 2011-03-13
    • 1970-01-01
    相关资源
    最近更新 更多