کاربر مبتدی
شنبه 21 بهمن 1391, 09:30 صبح
باسلام
از اساتید محترم من سعی کردم مباحث کتاب آقای هاشمیان را با wpf پیش بروم ولی گویا بعضی از دستورات با وین اپ متفاوت است لذا خواهشمندم کد برنامه زیر را برایم اصلاح کنید البته خودم سعی کردم موفق نشدم.
در صورت امکان توضیح مبتدی فهم فراموش نشود. مشخصاً خط 39-40 و 72 به بعد
using System;
using System . Collections . Generic;
using System . Linq;
using System . Text;
using System . Threading . Tasks;
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;
using System . Collections;
namespace structureDEMO
{
public partial class MainWindow : Window
{
//++++++++++++++++++++++++++++++++++++++++++++++++++
private ArrayList objCustomers = new ArrayList ( );
//++++++++++++++++++++++++++++++++++++++++++++++++++
private void DisplayCustomer ( Customer objCustomer )
{
// شرح: 188-2
txtName . Text = objCustomer . Name;//شرح: 191
txtFirstName . Text = objCustomer . FirstName;
txtLastName . Text = objCustomer . LastName;
txtEmail . Text = objCustomer . Email;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++
public Customer SelectedCustomer
{
get
{
// return ( Customer ) lstCustomers . Items [ lstCustomers . SelectedIndex ];
ListBoxItem lstitem = lstCustomers . SelectedItem as ListBoxItem;
return ( Customer ) lstitem . Content;
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++
public MainWindow ( )
{
InitializeComponent ( );
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ +
private void btnText_Click ( object sender , EventArgs e )
{
// شرح: 193
CreateCustomer ( "Darrel" , "Hilton" , "dhilton@somecompany.com" );
CreateCustomer ( "Frank" , "Peoples" , "fpeoples@somecompany.com" );
CreateCustomer ( "Bill" , "Scott" , "bscott@somecompany.com" );
}
//+++++++++++++++++++++++++++++++++++++++++++++++++
public void CreateCustomer ( string FirstName ,
string LastName , string Email )
{
// Declare a customer object
Customer objNewCustomer;
// Create the new customer
objNewCustomer . FirstName = FirstName;
objNewCustomer . LastName = LastName;
objNewCustomer . Email = Email;
// Add the new customer to the list
objCustomers . Add ( objNewCustomer );
// Add the new customer to the ListBox control
lstCustomers . Items . Add ( objNewCustomer );
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
private void btnDelete_Click ( object sender , EventArgs e )
{
// If no customer is selected in the ListBox then...
if ( lstCustomers . SelectedIndex == -1 )
{
// Display a message
MessageBox . Show ( "You must select a customer to "+ "delete!" , "Structure Demo" );
// Exit the method
return;
}
// Prompt the user to delete the selected customer
DialogResult result = MessageBox . Show ("Are you sure you want to delete " + SelectedCustomer . Name + "? " , "Structure Demo" ,MessageBoxButton . YesNo , MessageBoxImage . Question );
//MessageBoxButtons . YesNo , MessageBoxIcon .Question );
//if ( result == DialogResult . Yes )
if (result==DialogResult.Yes)
{
// Get the customer to be deleted
Customer objCustomerToDelete = SelectedCustomer;
// Remove the customer from the ArrayList
objCustomers . Remove ( objCustomerToDelete );
// Remove the customer from the ListBox
lstCustomers . Items . Remove ( objCustomerToDelete );
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
}
}
از اساتید محترم من سعی کردم مباحث کتاب آقای هاشمیان را با wpf پیش بروم ولی گویا بعضی از دستورات با وین اپ متفاوت است لذا خواهشمندم کد برنامه زیر را برایم اصلاح کنید البته خودم سعی کردم موفق نشدم.
در صورت امکان توضیح مبتدی فهم فراموش نشود. مشخصاً خط 39-40 و 72 به بعد
using System;
using System . Collections . Generic;
using System . Linq;
using System . Text;
using System . Threading . Tasks;
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;
using System . Collections;
namespace structureDEMO
{
public partial class MainWindow : Window
{
//++++++++++++++++++++++++++++++++++++++++++++++++++
private ArrayList objCustomers = new ArrayList ( );
//++++++++++++++++++++++++++++++++++++++++++++++++++
private void DisplayCustomer ( Customer objCustomer )
{
// شرح: 188-2
txtName . Text = objCustomer . Name;//شرح: 191
txtFirstName . Text = objCustomer . FirstName;
txtLastName . Text = objCustomer . LastName;
txtEmail . Text = objCustomer . Email;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++
public Customer SelectedCustomer
{
get
{
// return ( Customer ) lstCustomers . Items [ lstCustomers . SelectedIndex ];
ListBoxItem lstitem = lstCustomers . SelectedItem as ListBoxItem;
return ( Customer ) lstitem . Content;
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++
public MainWindow ( )
{
InitializeComponent ( );
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ +
private void btnText_Click ( object sender , EventArgs e )
{
// شرح: 193
CreateCustomer ( "Darrel" , "Hilton" , "dhilton@somecompany.com" );
CreateCustomer ( "Frank" , "Peoples" , "fpeoples@somecompany.com" );
CreateCustomer ( "Bill" , "Scott" , "bscott@somecompany.com" );
}
//+++++++++++++++++++++++++++++++++++++++++++++++++
public void CreateCustomer ( string FirstName ,
string LastName , string Email )
{
// Declare a customer object
Customer objNewCustomer;
// Create the new customer
objNewCustomer . FirstName = FirstName;
objNewCustomer . LastName = LastName;
objNewCustomer . Email = Email;
// Add the new customer to the list
objCustomers . Add ( objNewCustomer );
// Add the new customer to the ListBox control
lstCustomers . Items . Add ( objNewCustomer );
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
private void btnDelete_Click ( object sender , EventArgs e )
{
// If no customer is selected in the ListBox then...
if ( lstCustomers . SelectedIndex == -1 )
{
// Display a message
MessageBox . Show ( "You must select a customer to "+ "delete!" , "Structure Demo" );
// Exit the method
return;
}
// Prompt the user to delete the selected customer
DialogResult result = MessageBox . Show ("Are you sure you want to delete " + SelectedCustomer . Name + "? " , "Structure Demo" ,MessageBoxButton . YesNo , MessageBoxImage . Question );
//MessageBoxButtons . YesNo , MessageBoxIcon .Question );
//if ( result == DialogResult . Yes )
if (result==DialogResult.Yes)
{
// Get the customer to be deleted
Customer objCustomerToDelete = SelectedCustomer;
// Remove the customer from the ArrayList
objCustomers . Remove ( objCustomerToDelete );
// Remove the customer from the ListBox
lstCustomers . Items . Remove ( objCustomerToDelete );
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++
}
}