Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,463 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,671 people online right now. Registration is fast and FREE... Join Now!




Moving from Windows Forms Application(WFA) to WPF

 
Reply to this topicStart new topic

Moving from Windows Forms Application(WFA) to WPF

Ameel
30 Jun, 2008 - 05:09 AM
Post #1

D.I.C Head
**

Joined: 19 Jun, 2008
Posts: 91

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.




User is offlineProfile CardPM
+Quote Post

sam_benne
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 05:19 AM
Post #2

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 298



Thanked: 1 times
Dream Kudos: 400
My Contributions
This is VB6 not VB.net.
User is offlineProfile CardPM
+Quote Post

Ameel
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 05:22 AM
Post #3

D.I.C Head
**

Joined: 19 Jun, 2008
Posts: 91

oops. Can some admin please close this thread. I'll open a new one in vb .net Sorry. Thanks

This post has been edited by Ameel: 30 Jun, 2008 - 05:25 AM
User is offlineProfile CardPM
+Quote Post

Ameel
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 05:25 AM
Post #4

D.I.C Head
**

Joined: 19 Jun, 2008
Posts: 91

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

User is offlineProfile CardPM
+Quote Post

jacobjordan
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 10:29 AM
Post #5

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Don't close the thread, wait for a mod or admin to move it.

QUOTE

This is VB6 not VB.net.

Shouldn't that be the other way around?

This post has been edited by jacobjordan: 30 Jun, 2008 - 10:30 AM
User is offlineProfile CardPM
+Quote Post

sam_benne
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 12:01 PM
Post #6

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 298



Thanked: 1 times
Dream Kudos: 400
My Contributions
i meant forum lol

This post has been edited by sam_benne: 30 Jun, 2008 - 12:01 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 12:48 PM
Post #7

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET
User is online!Profile CardPM
+Quote Post

jacobjordan
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 03:01 PM
Post #8

class Me : Perfection
Group Icon

Joined: 11 Jun, 2008
Posts: 1,163



Thanked: 32 times
Dream Kudos: 1625
My Contributions
Ameel, just so you know, when you make a topic and you post it in the wrong forum, don't create a new topic in the forum it should of gone in. A mod or admin will move it to it's correct forum, which has now been done with this topic. You will find the original in this forum as well.

Mod's: somebody close this topic
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Moving From Windows Forms Application(WFA) To WPF
30 Jun, 2008 - 03:07 PM
Post #9

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Please don't start duplicate topics. If you create one in the wrong forum wait for a Moderator or Admin to move it to the proper forum (or request that they do it). Topics merged smile.gif
User is online!Profile CardPM
+Quote Post

Ameel
RE: Moving From Windows Forms Application(WFA) To WPF
1 Jul, 2008 - 02:55 AM
Post #10

D.I.C Head
**

Joined: 19 Jun, 2008
Posts: 91

Wow. So many replies about my duplicate posts (Sorry about that btw), but none about how to help me sad.gif

mehhhh sad.gif
User is offlineProfile CardPM
+Quote Post

Ameel
RE: Moving From Windows Forms Application(WFA) To WPF
1 Jul, 2008 - 11:14 AM
Post #11

D.I.C Head
**

Joined: 19 Jun, 2008
Posts: 91

No one helped....

After a long while, I managed to find out more stuff though....

So basically, I was still using kinda similar vb6 concepts which vb .net doesn't support, i.e I must create an instance of a class in vb .net to be able to reference stuff. And I have some extra stuff to do to make a form and another form/module communicate.

Basically below is what i wanted to know (but no1 helped out):

window1 contains 2 buttons and 1 textbox
CODE

Class Window1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim window2_ins1 As New Window2
        window2_ins1.window1caller = Me
        window2_ins1.event1()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Module1.window1caller = Me
        event2()

    End Sub
End Class


window2 contains nothing
CODE

Imports System.Windows.Window
Partial Public Class Window2
    Public window1caller As Window1
    Public Sub event1()
        window1caller.TextBox1.Text = "Hello. This is an event from window2"
    End Sub
End Class


module1 is as follows:
CODE

Imports System.Windows.Window
Module Module1
    Public window1caller As Window1
    Public Sub event2()
        window1caller.TextBox1.Text = "This is an event from module1"
    End Sub
End Module



It was so much simpler to do for Windows Forms Application, but mehhh.. WPF seems better...

Anyway, im quite disappointed by the number of views + responses to the fact that i doubleposted, but nothing with regards to my problem.

Solved it myself. Hope this helps anyone else who could not figure out this stuff
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:34PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month