[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

Form to always appear in the front of the worksheet (using VSTO)

Hi Experts, I am writing a VSTO (Excel) application using VB.NET. I have an Excel worksheet as the main interface. When I double-click on the cells, I want to call up my Windows Form - frmMain. I have able to call up the form but the form always goes behind the worksheet despite of me typing frmMain.BringToFront().

In VB6, the instruction frmMain.Show vbModeless, Me will do the job. However in VB.NET, the show method accepts no argument. Please advice me on how to make this frmMain always appear in front of the Excel worksheet.

TIA.
0
bpyeo
Asked:
bpyeo
2 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try setting the TopMost property of frmMain to True.

Idle_Mind
0
 
bpyeoAuthor Commented:
Hi Idle_Mind, thanks for your advice. Now how could I ensure that the user will not pressed ALT-F4 to close this form? I have made the form not to show up in the taskbar and the form does not have any border. However the user can still close the form by pressing ALT-F4. Hope to hear from your expertise advice.

TIA.
0
 
RonaldBiemansCommented:
you could cancel that action in the mousedown event of the form (don't forget to set the keypreview property to true in your form)

Private Sub Form5_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.Alt = True and e.KeyCode = Keys.F4 Then
                e.Handled = True
        End If
    End Sub
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now