Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#如何用组合框中的值替换EventLogEntryType?_C# - Fatal编程技术网

C#如何用组合框中的值替换EventLogEntryType?

C#如何用组合框中的值替换EventLogEntryType?,c#,C#,在下面的代码中,我想用从组合框中选择的值替换EventLogEntryType.Warning,组合框值为EventLogEntryType.Warning,EventLogEntryType.Information,EventLogEntryType.Error。组合框只会显示“警告”、“信息”和“错误”。我该怎么做 谢谢 EventLog myLog = new EventLog(); myLog.Source = "Test"; int intEventID =

在下面的代码中,我想用从组合框中选择的值替换EventLogEntryType.Warning,组合框值为EventLogEntryType.Warning,EventLogEntryType.Information,EventLogEntryType.Error。组合框只会显示“警告”、“信息”和“错误”。我该怎么做

谢谢

EventLog myLog = new EventLog(); myLog.Source = "Test";             
int intEventID = int.Parse(txtEventID.Text);            
myLog.WriteEntry(txtDescription.Text, EventLogEntryType.Warning, intEventID);

新手

假设EventLogEntryType是一个枚举,并且不需要本地化,那么可以很容易地完成这项工作

以表格形式装载

  combobox1.Items.Add(EventLogEntryType.Warning);
   combobox1.Items.Add(EventLogEntryType.Information);
   ...
后来

   myLog.WriteEntry(txtDescription.Text, (EventLogEntryType)combobox1.Selecteditem, intEventID);

您可以使用
Enum.Parse
将组合框中的值转换为枚举:

var sv = yourComboBox.SelectedValue;
var entryType = (EventLogEntryType) Enum.Parse(typeof(EventLogEntryType), sv);