Results 1 to 6 of 6

Thread: Multiple Forms Issue - Remaining on one form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    71

    Multiple Forms Issue - Remaining on one form

    Hello,

    I've created two forms - one 'main' and a second 'frmPrint'.
    'frmPrint' has a ListBox for the user to select which printer they want to use.
    Additionally, the 'defaultPrinter' gets shown/selected in the ListBox while on this form.
    I use the .hide, .show and .BringToFront to manage the different forms - this appears to work OK.
    But, what techniques do I use to keep on the 'frmPrint' form window until the user: 1) selects
    a particular printer from the ListBox (other than the defaultPrinter already selected) and,
    2) the user presses the "Select Printer" button on 'frmPrint'?
    At that point, I want to return to the 'main' form and continue on with the code there.

    Currently, my code completes the ListBox on 'frmPrint' form, selects and highlights the defaultPrinter
    then continues back to my main code...essentially back on my 'main' form.

    Thanks for any help provided,
    Grant

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    750

    Re: Multiple Forms Issue - Remaining on one form

    You might like to trying using frmPrint.Showdialog() to make the form "modal" - the user must deal with the options on frmPrint and cannot click on anything else whilst it is visible. When the form closes, control will pass back to your main form.

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Multiple Forms Issue - Remaining on one form

    .ShowDialog is indeed the answer but you do realise that there's a ready made couple of Print dialogs sitting in the toolbox?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    71

    Re: Multiple Forms Issue - Remaining on one form

    Hi Paulg and Dun,

    Thanks for the quick response. I'll try out the .ShowDialog and let you know if I was successful.

    Dun, Yes, I did try the 'built-in' Print Dialogs but was having trouble with changing from the default printer
    to another one I selected. Apparently, either I was doing something wrong (likely) or, there is some sort of bug
    with these dialogs as far as not retaining the changed printer settings.
    If you have any insight here, I'm open for suggestions!

    Thanks again and Regards,
    Grant

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    71

    Re: Multiple Forms Issue - Remaining on one form

    Here's my code for the 'formPrint':

    %CODE%

    Imports System.Drawing.Printing
    '
    Public Class formPrint

    Private Sub formPrint_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    frmMain.Hide()
    Me.Show()
    Me.BringToFront()

    Dim myPrinter As New PrintDocument
    Dim Done As Boolean : Done = False
    Dim defaultPrinter As String
    Dim defaultPrinterIndex As Integer

    Me.Text = "Print and PrintPreview Selection Form"
    'grab available printers...
    For Each strPrinterName As String In PrinterSettings.InstalledPrinters
    Me.selectPrinterLstBox.Items.Add(strPrinterName)
    Next
    Me.selectPrinterLstBox.SelectedItem = myPrinter.DefaultPageSettings.PrinterSettings.PrinterName 'highlight the default printer
    defaultPrinter = myPrinter.DefaultPageSettings.PrinterSettings.PrinterName
    defaultPrinterIndex = Me.selectPrinterLstBox.SelectedIndex
    MsgBox("Selected Item Index = " & Me.selectPrinterLstBox.SelectedIndex & " Default Printer is: " & defaultPrinter)
    Me.ShowDialog()

    End Sub

    %CODE%

    The 'Me.ShowDialog()' doesn't appear to change things.
    My code blows through this section of code then continues back to my main code that called this via 'formPrint.Show()'.

    Grant

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Multiple Forms Issue - Remaining on one form

    Er .. yeah .. it would. You can't show a form or amend its modality from itself. It would be like me calling myself to dinner! The original call should be amended to formPrint.ShowDialog() on the main form! Only Mums get to call you for dinner!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

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