10 Replies - 7489 Views - Last Post: 01 July 2008 - 12:14 PM Rate Topic: -----

#1 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 06:09 AM

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:
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:
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:
Module Module1
	Public string1 As String = ""
	Public Sub event1()
		MsgBox(string1)
	End Sub
End Module



window1 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:
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:
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.

Is This A Good Question/Topic? 0
  • +

Replies To: Moving from Windows Forms Application(WFA) to WPF

#2 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 06:19 AM

This is VB6 not VB.net.
Was This Post Helpful? 0
  • +
  • -

#3 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 06:22 AM

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 June 2008 - 06:25 AM

Was This Post Helpful? 0
  • +
  • -

#4 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 06:25 AM

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:
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:
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:
Module Module1
	Public string1 As String = ""
	Public Sub event1()
		MsgBox(string1)
	End Sub
End Module



window1 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:
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:
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
Was This Post Helpful? 0
  • +
  • -

#5 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 11:29 AM

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 June 2008 - 11:30 AM

Was This Post Helpful? 0
  • +
  • -

#6 sam_benne  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 16
  • View blog
  • Posts: 732
  • Joined: 16-January 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 01:01 PM

i meant forum lol

This post has been edited by sam_benne: 30 June 2008 - 01:01 PM

Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 01:48 PM

Moved to VB.NET
Was This Post Helpful? 0
  • +
  • -

#8 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 04:01 PM

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
Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 30 June 2008 - 04:07 PM

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 :)
Was This Post Helpful? 0
  • +
  • -

#10 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 01 July 2008 - 03:55 AM

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

mehhhh :(
Was This Post Helpful? 0
  • +
  • -

#11 Ameel  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 171
  • Joined: 19-June 08

Re: Moving from Windows Forms Application(WFA) to WPF

Posted 01 July 2008 - 12:14 PM

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
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
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:
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
Was This Post Helpful? 1

Page 1 of 1