Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > C# 4.0 aka C# 2010 General Discussion
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 10th, 2011, 11:52 AM
Registered User
 
Join Date: Aug 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Clearing an label and making button 2 work

Hello programmers i am a newbie in programming so right now iam trying to write some methodes with Microsoft Visual C# 2010.

I am trying to make button 2 executing a method(by click) and before calling the method it should clear the text within the label.

Right now the label is not being cleared when i push button 2 and button 2 is not executing the method while an other button: btnTafelVijf does work :s.

below the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tafel_van_10
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{


public MainWindow()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{

uitKomst.Items.Clear();
long resultaat = Berekening(5);
}

private void button2_Click(object sender, RoutedEventArgs e)
{
uitKomst.Items.Clear();
label1.Content = "test";
long resultaat = Berekening(2);
}

private long Berekening(int getal)
{

int i;
for (i = 1; i < 11; i=i+1)
{

uitKomst.Items.Add(+i + " x " + getal +" = " +i * getal);
//uitKomst.Items.Add(i*getal);


}
return i;

}

private void comboBox_SelectedItem(object sender, SelectionChangedEventArgs e)
{

int getal = comboBox.SelectedIndex +1;
uitKomst.Items.Clear();

long resultaat = Berekening(getal);

string teken = ((ComboBoxItem)comboBox.SelectedItem).Content.ToSt ring();
label1.Content = BepaalGetal(teken);

}



private void comboBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{

int getal = comboBox.SelectedIndex;
Object selectedItem = comboBox.SelectedItem;

}


private string BepaalGetal(string teken)
{
switch (teken)
{
case "1":
return "Tafel van Één";
case "2":
return "Tafel van Twee";
case "3":
return "Tafel van Drie";
case "4":
return "Tafel van Vier";
case "5":
return "Tafel van Vijf";
case "6":
return "Tafel van Zes";
case "7":
return "Tafel van Zeven";
case "8":
return "Tafel van Acht";
case "9":
return "Tafel van Negen";
case "10":
return "Tafel van Tien";
default:
return "ongekend";
}
}







}
}
 
Old September 7th, 2011, 04:59 PM
Wrox Author
 
Join Date: Sep 2010
Posts: 175
Thanks: 3
Thanked 53 Times in 53 Posts
Default

Quote:
Originally Posted by SteveDoeve View Post
I am trying to make button 2 executing a method(by click) and before calling the method it should clear the text within the label.

Right now the label is not being cleared when i push button 2 and button 2 is not executing the method while an other button: btnTafelVijf does work :s.
For me it's not clear what you say works and what doesn't.
If the click handler of button 2 is not invoked when clicking the button 2, you should check your declaration of the click event in XAML.
__________________
Christian
CN innovation
Visit my blog at: csharp.christiannagel.com
Follow me on twitter: @christiannagel





Similar Threads
Thread Thread Starter Forum Replies Last Post
Making the Page_Load() work iceman90289 ASP.NET 3.5 Basics 8 March 12th, 2009 04:49 PM
Clearing a label in FORM LOAD sweet4511 VB How-To 2 July 19th, 2005 01:22 PM
Making a label blink levinll VB How-To 2 June 23rd, 2004 12:05 PM
making php work? P.Y.sum Beginning PHP 5 November 5th, 2003 10:28 AM
making an .exe work cooky4 VB Databases Basics 2 June 3rd, 2003 11:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.