Click here to Skip to main content
15,917,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created an identical scenario in both a windows form and a WPF form (Visual Basic 2008), but only one of them had a problem; the WPF form. It is all centered around 2 Textboxes and one Label. Here is the very straight forward code. I need to use the WPF form so I can get a form height that is not Limited by my monitor.
VB
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
  TextBox13.Text = TextBox17.Text
End Sub

In case you are wondering (and I wouldn’t blame you) I did enter the code in the code view of the WPF form. If you know what code to enter in XAML to do the job, I would love to see that.

The Label1 click event where TextBox13 copies from TextBox17 worked fine in the windows form, but I got an error in the WPF form.
This error:

Handles clause requires a WithEvents variable defined in the containing type or one of it’s base types.

I also noticed that I had to declare the two text boxes in WPF, but did not in the windows form.
I guess the remedy is just a little beyond my experience level.
Posted
Updated 26-Dec-10 5:34am
v4
Comments
JF2015 25-Dec-10 18:11pm    
Edited to add code formatting.

1 solution

I'm not sure how you are getting the error you are getting. The WPF label control doesn't have a click event (in fact it is illogical that the Winforms one does). You should get an error saying Label1 doesn't have a click event to handle or similar.

My advice is, if you need to create the form in WPF, not do the copy and paste handler from Winforms it is a very different model. You should also look into databinding, it will save you a lot of code.

As for this problem, you should also make the control a button (which it is logical to click :-)) but style it like a label. Though on this final point, you have to take into consideration the user experience. It isn't obvious that a label can be clicked, so you might make the form harder for the user to use than necessary.

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900