Autor Beitrag
Rassi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Di 01.09.09 16:04 
Hallo.
Ich erstelle zur Laufzeit ToolStripMenuItem's.
Diese bekommen alle den gleichen EventHandler.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
toolStripMenuItem2.DropDownItems.Clear();
m = new ToolStripMenuItem("(None)"nullnew EventHandler(mnuVideoDevices_Click));
m.Checked = (videoDevice == null);
toolStripMenuItem2.DropDownItems.Add(m);
for (int c = 0; c < filters.VideoInputDevices.Count; c++)
{
  f = filters.VideoInputDevices[c];
  m = new ToolStripMenuItem(f.Name, nullnew EventHandler(mnuVideoDevices_Click));
  m.Checked = (videoDevice == f);
  toolStripMenuItem2.DropDownItems.Add(m);
}
toolStripMenuItem2.Enabled = (filters.VideoInputDevices.Count > 0);


Wenn nun ein Menü gedrückt wurde, komme ich in das Event. Nur müsste ich nun wissen, welchen Index der Menüpunkt hatte.
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
private void mnuVideoDevices_Click(object sender, System.EventArgs e)
{
  try
  {
    // Get current devices and dispose of capture object
    // because the video and audio device can only be changed
    // by creating a new Capture object.
    Filter videoDevice = null;
    Filter audioDevice = null;
    if (capture != null)
    {
       videoDevice = capture.VideoDevice;
       audioDevice = capture.AudioDevice;
       capture.Dispose();
       capture = null;
     }

     // Get new video device
     ToolStripMenuItem m = sender as ToolStripMenuItem;
     videoDevice = (1 > 0 ? filters.VideoInputDevices[1 - 1] : null); 
     // Create capture object
     if ((videoDevice != null) || (audioDevice != null))
     {
        capture = new Capture(videoDevice, audioDevice);
        capture.CaptureComplete += new EventHandler(OnCaptureComplete);
     }

     // Update the menu
     updateMenue();
   }
   catch (Exception ex)
   {
     MessageBox.Show("Video device not supported.\n\n" + ex.Message + "\n\n" + ex.ToString());
   }
}


Hier habe ich in Zeile 19 den benötigten Index mit 1 ersetzt. Eigendlich sollte es in etwa so heißen:
ausblenden C#-Quelltext
1:
videoDevice = (m.Index > 0 ? filters.VideoInputDevices[m.Index - 1] : null);					


Weiß da jemand von euch Rat?

Gruß
Rasmus
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 01.09.09 17:50 
Zwei Lösungswege findest du hier, in deinem speziellen Fall könntest du auch ToolStripItemCollection.IndexOf mit dem sender aufrufen.

_________________
>λ=
Rassi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 79



BeitragVerfasst: Mi 02.09.09 10:17 
Hallo.

Danke hat geklappt mit dem Tip.

Gruß
Rasmus