Results 1 to 6 of 6

Thread: [RESOLVED] My Form is on top of my Word document that I have just opened

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Resolved [RESOLVED] My Form is on top of my Word document that I have just opened

    I am quite a rookie on VB.net, but have been programming one way or another for over 40 years, I still have trouble getting my head around things, hence my probably very simple question ...

    I have the following code that works, but my Form is reappearing on top of the just opened Word document. How can I make the Word document appear on top ?

    I am still in Debug mode, but presume that makes no difference ...

    Thanks in advance ...

    Code:
    Imports Microsoft.Office.Interop.Word
    Imports Microsoft.Office.Interop
    
    Public Class Form2
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.Text = "" Then
                Form3.TextBox1.Text = "Error, you have not entered a name for this Artist or Band ..."
                Form3.TextBox2.Visible = False
                Form3.Button2.Visible = True
                Form3.AcceptButton = Button2
                Form3.Show()
                Exit Sub
            End If
            MusicFile = TextBox1.Text & ".docx"
            If System.IO.File.Exists(MusicFolder & MusicFile) Then
                Form3.TextBox1.Text = "Error, you already have an existing file for this Artist or Band ..."
                Form3.TextBox2.Text = "Do you want to open that file or go back to the previous screen ?"
                Form3.Button1.Visible = True
                Form3.Button3.Visible = True
                Form3.AcceptButton = Button1
                Form3.Show()
            Else
                If SheetOrientation = "Portrait" Then
                    System.IO.File.Copy(MusicFolder & "Portrait.docx", MusicFolder & MusicFile)
                End If
                If SheetOrientation = "Landscape" Then
                    System.IO.File.Copy(MusicFolder & "Landscape.docx", MusicFolder & MusicFile)
                End If
                System.IO.File.SetAttributes(MusicFolder & MusicFile, fileAttributes:=vbNormal)
                WordApp = CreateObject("Word.Application")
                WordApp.Visible = True
                WordDoc = WordApp.Documents.Add(MusicFolder & MusicFile)
                Me.Close()
            End If
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Me.Close()
        End Sub
    End Class
    Attached Images Attached Images  

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,914

    Re: My Form is on top of my Word document that I have just opened

    In the designer, bring up the properties of the form (right-click on the form and click properties or use the shortcut key F4).

    If your TopMost property is true, then change it to false. Here are the docs on the property: https://docs.microsoft.com/en-us/dot...t?view=net-5.0

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: My Form is on top of my Word document that I have just opened

    Quote Originally Posted by dday9 View Post
    In the designer, bring up the properties of the form (right-click on the form and click properties or use the shortcut key F4).

    If your TopMost property is true, then change it to false. Here are the docs on the property: https://docs.microsoft.com/en-us/dot...t?view=net-5.0
    Hi dday9, thanks for your reply, but I have 3 forms and Topmost is set to False in all of them

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,148

    Re: My Form is on top of my Word document that I have just opened

    Maybe it will help to make Form3 an 'Owned Form' of Form2. Assuming that 'Me' refers to Form2:
    Code:
    Form3.Show(Me)
    That will ensure that Form3 stays front of Form2 when shown, and both forms will get out of the way if you Hide, Minimize or Close Form2.

    BB

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: My Form is on top of my Word document that I have just opened

    Quote Originally Posted by boops boops View Post
    I'm a bit uncertain what you mean by "my form": your image shows Form1 in the title, and your code refers only to Form2 and Form3. Anyway, something you can easily try is to provide the "owner" argument in the Form.Show statement. For example:
    Code:
    Form2.Show(Me)
    Assuming "Me" refers to Form1, that statement will ensure that Form1 is the Owner of Form2, with the result that Form2 will always appear in front of Form1.

    EDIT: I guess you can't change how the Word document is shown. Perhaps it will help to make Forms 2 and 3 owned by Form1, and Hide Form1 as soon as you want all 3 forms to get out of the way.

    BB
    boops boops, Form1 has 3 options for the user, Open an existing file, Create a new Portrait File, Create a new Landscape File & Form2 then opens if option 2 or 3 is chosen. Form2 just contains a TextBox for the user to enter the name of his Artist or Band and this is the Code that sits behind Form2. Form3 is an Error box, otherwise I create a new Word document in the Orientation he has requested and open it for him to enter data ... this all worked fine when I was opening an Excel file, I have just realised, but now I have switched it to a Word file, Form1 pops up in front of it and that is all I want to prevent.

    This is just a small program for an old man who has brain damage I am trying to make it easy for him to do what he wants to do, it's so frustratingly annoying to run into such a stupid problem when it's basically finished !!!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    28

    Re: My Form is on top of my Word document that I have just opened

    OK, I have resolved this now by adding
    Code:
    Form1.WindowState = FormWindowState.Minimized
    to the code immediately after the WordDoc command ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width