2009-02-27 13 views

cevap

1

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

EventLogEntryType bir enum olduğunu varsayarsak ve yerelleştirilmesine gerekmez, bu çok kolay yapabiliriz

.

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

Form_Load

yılında

ve üstü

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

Sen enum combobox'dan değeri çevirmek için Enum.Parse kullanabilirsiniz:

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