Results 1 to 4 of 4

Thread: [RESOLVED] Have a Class -- want to show a form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Resolved [RESOLVED] Have a Class -- want to show a form

    Very simple item.. or one would think

    I am wanting to make a class that can be referenced in from other applications. In this class I simply want to do a showdialog to a form. That form has a ssrs pre-defined within it and a viewer all set to show the report.
    But when I try and define that action I get that my form is now declaired


    Imports System
    Imports System.Drawing
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Windows.Forms
    Imports System.IO
    Public Class Show_Print_Report
    Dim MyNewForm As New Form1
    MyNewForm.ShowDialog
    (MyNewForm says that a declaration is expected)
    End Class


    but the form1 is indeed in the project......


    gollnick
    William E Gollnick

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Have a Class -- want to show a form

    I wouldn't be calling it Form1, that is just asking for trouble. Every project has a Form1. Technically, there shouldn't be any conflict if you are building this class and the form into a dll, but you weren't quite clear on that.

    Classes don't work that way. The problem that you are running into is that you have that ShowDialog line outside of a method (sub or function). Therefore, you could fix it by adding this to the class:
    Code:
    Public Sub ShowForm
     MyNewForm.ShowDialog
    End Sub
    You would then show the form by creating an instance of Show_Print_Report, and calling the ShowForm method of that instance.
    My usual boring signature: Nothing

  3. #3
    New Member
    Join Date
    Dec 2010
    Posts
    1

    Re: Have a Class -- want to show a form

    Try this:

    Code:
    Dim MyNewForm As New Form1()
    See if that works.

  4. #4
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Have a Class -- want to show a form

    If I understand you correctly, you have a class in an assembly that should show some form, but it doesn't know what. (I'll call this assembly LibAssembly)
    This assembly will be referenced by the assembly containing the form to show. (I'll call this assembly FormAssembly)

    What you will need to do, therefore, is to create an instance of your class and the form inside FormAssembly and pass the reference to the form into the class.

    An alternative, if you don't want to create instances of your form "by hand" would be to pass an instance of Type that is the type of your form into the class. Inside the class you will need to do a call to Activator.CreateInstance() to create the instance of the form without having a reference to it.

    Of course, your class will need to hold a reference to the form as simply Form, because you don't know the exact type of the form at compile-time.


    [Edit: Having said that, I don't see what you're getting by having this class... I assume it does more than simply call ShowDialog, yes?]
    [Edit2: No, reading your original post back, I think I totally misinterpreted. Ignore me and do what they ^^^^ suggested. ]
    Last edited by Evil_Giraffe; Dec 13th, 2010 at 06:05 PM.

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