Hi.
First of all, I'm new @ programming.
I've been writing a program in vb .net using Windows Forms Application
In that i use heaps of references from one form to another and modules to simplify the job.
However, i realised that I would need particularly nice UI and looked up.
I came across Expression Blend and other stuff.
On further research I realised I could use WPF for better/custom UI.
So, I decided, if possible, to shift to WPF.
For starters,
I design something random using WPF. It contains a textbox called textbox1 and a button called button1.
I add a module, called module1.
The code in the window form is as follows:
CODE
Class Window1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
event1()
End Sub
End Class
Basically, I call event1 on button click, which can be found in module1.
My module1 is as follows:
CODE
Module Module1
Public Sub event1()
MsgBox(Window1.TextBox1.text)
End Sub
End Module
It gives me the following error, however: Reference to a non-shared member requires an object reference.
You might wonder why i did not put
msgbox(textbox1.text) instead of event1. Let's just say I was trying it out, testing.
Can anyone explain why this is not working?
I found a way to make it work.
Basically, I define a string in the module and make the string take the textbox value and the messagebox displays the string, such that my new module code reads:
CODE
Module Module1
Public string1 As String = ""
Public Sub event1()
MsgBox(string1)
End Sub
End Module
window1 code:
CODE
Class Window1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
string1 = TextBox1.Text
event1()
End Sub
End Class
However, I can't access any of window1's objects directly, and this will be very troublesome for every other purposes I will have.
For instance, say I have a second form called window2 with button being button1 and a textbox named textbox1.
When user clicks button in window1 i want it to display window2 directly (as it is easily done in Window Forms Application) -> I do not know how to show window2 itself directly. Can anyone help, because window2.show does not work for WPF (can anyone help/explain why/or how to make it work). It gives me error: Reference to a non-shared member requires an object reference.
However, let us assume that when the user hits the button, it shows window2_clone as new window2.
In the second form(window2_clone), the user inputs a text in the textbox and hits the button. This closes window2_clone and displays the text input, in the textbox in window1.
My code is as follows:
Window2 code:
CODE
Partial Public Class Window2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Window1.TextBox1.text = TextBox1.Text
Me.Close()
End Sub
End Class
Window1 code:
CODE
Public Class Window1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim window2_clone As New Window2
window2_clone.Show()
End Sub
End Class
However, this does not work. It still gives me: Reference to a non-shared member requires an object reference.
I'm at a complete loss. I tried to look up the net for wpf samples, but I could not find multi-forms samples, nor samples that had modules and stuff.
Please help.
Note that the reason I want to use WPF is just to design the UI to make it look nice. Ideally I want to be able to program everything else just as in WFA. Alternatively, can anyone guide me as to how to switch to WPF.
Thanks in advance