Results 1 to 7 of 7

Thread: Vb dll help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    70

    Vb dll help

    I created a VB.NET and there are two projects in it. One is a class library with one class file (lets say Clas1.vb) and the other is just of a form. I referenced the Class library into the other form so I could use its methods in it. However, the Class1.vb cannot pickup what project is using it. So how would I go about where a button on Form1 is clicked, and the code behind it is say, ClasslibraryInProject.Class1.MaximizeForm() the Class1.vb knows which project/form passed that command to it, and it then performs the Windowstate = FormWindowState.Maximized command on Form1. Any ideas?

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

    Re: Vb dll help

    From the utterly baffling description it's clear that you really don't have the whole concept of programming with external classes and class libraries. If it's not huge, I'd recommend posting your class code here so that we can suggest improvements and show you how to use the class within another project.
    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!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    70

    Re: Vb dll help

    The code for button1 in the main form is:

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    DemoDLL.Class1.MaximizeForm()
    
        End Sub
    And for Class1:

    Code:
     Public Shared Sub Maximize()
    
    
        End Sub
    Yet I don't know what to put for Class1 in order to have Form1 set its state to Maximized.

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

    Re: Vb dll help

    Why would you want an external function (and it would have to be a function) to change a form property?
    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!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    70

    Re: Vb dll help

    I'm just playing around with it is all. Is it possible?

  6. #6
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Vb dll help

    Hi,

    It took me a few goes to understand your question but I got there in the end. To specifically answer your question you would need to pass the calling object as a parameter to the class so that the class knew which Form it was dealing with. i.e:-

    Code:
    Public Class Class1
      Public Shared Function MaximiseForm(ByVal myForm As Form) As Boolean
        myForm.WindowState = FormWindowState.Maximized
        Return True
      End Function
    End Class
    You would then call the class, passing the current Form you were working with as a parameter. i.e:-

    Code:
    Dim MaximiseThisForm As Boolean = Class1.MaximiseForm(Me)
    That said, I do agree with dunfiddlin, that to do this sort of thing in an external class is a bit pointless since it takes unnecessary work and resources to pass this to an external class when you just need to call:-

    Code:
    Me.WindowState = FormWindowState.Maximized
    To finish, external class's have many uses but this is not one of them.

    Hope that helps.

    Cheers,

    Ian

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    70

    Re: Vb dll help

    Thanks for the help, greatly appreciated! I am aware it is pointless, but I am just playing around with external class files. However, this works fine if the class file is in the same project, but if I have the form in one project, and the class file in another, but their both in the same solution, and I referenced the class files project in the forms project, how would I go about getting this to work? As it picks up the "Form" in "(ByVal myForm as Form)" as an error.

Tags for this Thread

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