如何将wpf aplication c#中的代码转换为windown表单应用程序? [英] How to convert code in wpf aplication c# to windown form aplication?
本文介绍了如何将wpf aplication c#中的代码转换为windown表单应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:这是WPF应用程序的代码
string [] arrayMonth = new string [] {January,February,March, 四月,五月,
六月,七月,八月,九月,十月,十一月,十二月};
combobox.ItemsSource = arrayMonth;
我尝试过:
i希望将此代码转换为c#Windown Form应用程序,你能帮助我吗?谢谢所有
for example:this is code into WPF aplication
string[] arrayMonth = new string[] { "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December"};
combobox.ItemsSource = arrayMonth;
What I have tried:
i want convert this code into c# Windown Form aplication, can you help me? thanks all
推荐答案
而不是.ItemsSource
它是.DataSource
对于WinForms-ComboBox:
Instead of.ItemsSource
it's.DataSource
for a WinForms-ComboBox:
combobox.DataSource = arrayMonth;
using System.Globalization;
using System.Linq;
List<string> TheMonths = DateTimeFormatInfo.CurrentInfo.MonthNames.Take(12).ToList();
// in Form Load or somewhere
comboBox1.DataSource = TheMonths;
// use the combobox
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine("{0}: {1}", comboBox1.SelectedIndex, comboBox1.SelectedValue);
}
运行代码:observe。
Run code: observe.
这篇关于如何将wpf aplication c#中的代码转换为windown表单应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文