2017-03-06 2 views
1

Outlook 사서함에 들어오는 전자 메일에 대한 보고서를 표시하는 응용 프로그램에서 작업하고 있습니다. 필자는 전자 메일 유형에 따라 텍스트의 전면 색 또는 배경색을 서식있는 텍스트 상자로 설정했습니다. 사용자가 디스플레이에서 전자 메일을 선택할 수있는 기능을 추가하고자했습니다.리치 텍스트 서식 기능을 갖춘 목록 상자 기능

간단하게 목록 상자를 사용하고 ... 서식을 유지 ... 소유자가 지정한 고정 된 목록 상자로 만듭니다.

대부분의 경우에는 정상적으로 작동합니다. 사용자가 전자 메일을 선택하려고 시도 할 때까지 여기

더블 클릭에

일어나는 것입니다 :

  1. 명확 선택한 항목
  2. 할 목록에서 outlook.mailItem를 당기는 항목을 선택하고 정보에 캐스팅 얻을 어떤 메일 항목에 (사용자가 무엇을하고 싶은지 사용자가 선택하는 다른 기능으로 전달)
  3. 통화 업데이트

  1. 명확 갱신 목록 상자
  2. 의 항목은 전자 메일을 당기고, 업데이트에

어딘가에 목록 상자에 다시 응용 프로그램의 잠금을 추가하고 이유가 확실하지 않습니다. "정상적인"응용 프로그램 프로세스의 일부로 호출되면 보고서는 잘로드되고 사용자 상호 작용 후에 호출 될 때만 잠 깁니다.

시간의 75 %, 오류 핸들러가 없습니다. Catch (exception e2)가 호출됩니다. 그러나 때로는 -1 값을 던져 색인 오류가 발생합니다.

논리적으로는 한 케이스에서 작동하면 두 번째 케이스에서 작동해야하지만 증거는 그렇지 않을 수도 있음을 보여줍니다.

동일한 목표를 달성하기 위해 오류를 찾는 위치 또는 탐색 할 다른 경로에 대한 제안 사항이 있습니까?

 private void listBox_DrawItem(object sender, DrawItemEventArgs e) 
    { 
     e.DrawBackground(); 
     Graphics g = e.Graphics; 
     SolidBrush textColor = new SolidBrush(Color.Black); 
     SolidBrush backColor = new SolidBrush(Color.White); 
     try 
     { 
      ListBox box = (ListBox)sender; 
      mailInfo email = (mailInfo)box.Items[e.Index]; 
      switch (email.getTypeCode())//based on the e-mail type formats the line 
      { 
       case 1:// ejected 
        textColor = new SolidBrush(Color.LightGray); 
        backColor = new SolidBrush(Color.White); 
        break; 
       case 2://Multi volume 
        textColor = new SolidBrush(Color.SteelBlue); 
        backColor = new SolidBrush(Color.White); 
        break; 
       case 0://success 
        textColor = new SolidBrush(Color.DarkGreen); 
        backColor = new SolidBrush(Color.White); 
        break; 
       case -3://not inserted 
        textColor = new SolidBrush(Color.LightSalmon); 
        backColor = new SolidBrush(Color.White); 
        break; 
       case -2:// not scratch 
       case -1:// fail 
       case -4:// write portected 
       case -5:// not in DB 
        textColor = new SolidBrush(Color.White); 
        backColor = new SolidBrush(Color.Red); 
        break; 
       default: 
        textColor = new SolidBrush(Color.Black); 
        backColor = new SolidBrush(Color.White); 
        break; 
      } 
     } 
     catch (Exception e2) { MessageBox.Show(e2.Message + "\n\ncode\n" + e2.StackTrace, e2.GetType().ToString()); } 
     g.FillRectangle(backColor, e.Bounds); 
     if(e.State == DrawItemState.Selected) { 
      g.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, SystemBrushes.MenuHighlight,new PointF(e.Bounds.X, e.Bounds.Y)); } 
     else { 
      g.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, textColor, new PointF(e.Bounds.X, e.Bounds.Y)); 
     } 
     e.DrawFocusRectangle(); 

    } 


    private void lstEmail_DoubleClick_1(object sender, EventArgs e) 
    { 
     mailInfo email = (mailInfo) lstEmail.SelectedItem; 
     lstEmail.ClearSelected(); 
     frmEmailSelectedOptions userAction = new frmEmailSelectedOptions(); 
     userAction.ShowDialog(this); 
     switch (userAction.value) 
     { 
      case 0://ignore 
       // allow function to close, no action neededd 
       break; 
      case 1://read/unread 
      case 2://open 
       data.performEmailAction(email,userAction.value); 
       MessageBox.Show(userAction.value.ToString()); 
       break; 
      case 3://filter 
       this.filter = new mailFilter(email.getHost().getName(), email.getJobName()); 
       updateEmailList(); 
       break; 
     } 
    }public void updateEmailList()/***/ 
    { 
     lstEmail.Items.Clear(); 
     txtFilter.Text = filter.ToString();// updates the fileter display to the current filter 
     List<mailInfo> emails = data.getMail();// pulls the e-mails from the application memory 
     if (!btnSortByTime.Checked)//checks if the data needs to be re-sorted 
     { 
      emails.Sort((x, y) => x.getHost().getOrder().CompareTo(y.getHost().getOrder())); 
     } 
     foreach (mailInfo email in emails)//iterates over each e-mail in the application memory 
     { 
      if (displayEmail(email))//checks if the e-mails passes all the criteria 
      { 

       lstEmail.Items.Add(email);//adds the e-mail to the list, plus a line return for the next e-mail. 
      } 
     } 
    }` 
+0

예외는 무엇입니까? 실제로는 box.Items [e.Index];에서 예외가 발생합니까? –

+0

InvalidArgument = '-1'값이 'index'에 유효하지 않습니다. 파라미터 명칭 : 인덱스에 System.Windows.FormsListBox.ObjectCollection.get_Item에서 (인덱스 INT32) [...] frmMain.listbox_DrawItem (오브젝트 송신자 drawItemEventArgs E) –

답변

0

목록 상자에 포커스가 있는지 확인하여 문제가 해결되었습니다. 목록 상자에 포커스가 있으면 다른 컨트롤을 선택했습니다. 초점을 그대로 두지 마십시오. 이 문제가 해결되었습니다.

관련 문제