-
Jan 20th, 2013, 05:08 PM
#1
Thread Starter
Lively Member
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?
-
Jan 20th, 2013, 06:51 PM
#2
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!
-
Jan 20th, 2013, 06:59 PM
#3
Thread Starter
Lively Member
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.
-
Jan 20th, 2013, 07:08 PM
#4
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!
-
Jan 20th, 2013, 07:59 PM
#5
Thread Starter
Lively Member
Re: Vb dll help
I'm just playing around with it is all. Is it possible?
-
Jan 21st, 2013, 01:33 AM
#6
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
-
Jan 21st, 2013, 12:20 PM
#7
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|