Hallo,
ich habe einst in VB.Net dies gekonnt:
Nun möchte ich das Ganze in C# haben. Ich bekomme das Zusammenfassen der Handles nicht hin. Hier steht 6× derselbe Code. Könntet ihr mir bitte helfen?
ich habe einst in VB.Net dies gekonnt:
VB.NET-Quellcode
- Private Sub PictureBoxes_DoubleClick(sender As Object, e As EventArgs) Handles PictureBox1.DoubleClick,
- PictureBox2.DoubleClick,
- PictureBox3.DoubleClick,
- PictureBox4.DoubleClick,
- PictureBox5.DoubleClick,
- PictureBox6.DoubleClick
- Dim pb As PictureBox = DirectCast(sender, PictureBox)
- Dim n As Integer = CInt(pb.Tag)
- If NeueListeBitmaps?.Count > n Then
- NeueListeBitmaps.RemoveAt(n)
- Liste_mit_Pfaden.RemoveAt(n)
- pb.Image.Dispose()
- pb.Image = Nothing
- Something_has_actually_changed = True
- End If
- End Sub
Nun möchte ich das Ganze in C# haben. Ich bekomme das Zusammenfassen der Handles nicht hin. Hier steht 6× derselbe Code. Könntet ihr mir bitte helfen?
C#-Quellcode
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- namespace IA
- {
- public partial class FormEdit : Form
- {
- public FormEdit()
- {
- InitializeComponent();
- }
- private readonly List<System.Drawing.Bitmap> ListOfPhotos = new List<System.Drawing.Bitmap>();
- private readonly List<string> ListOfPathsOfThePhotos = new List<string>();
- private void PictureBox1_DoubleClick(object sender, EventArgs e)
- {
- PictureBox pbox = (PictureBox)sender;
- int n = System.Convert.ToInt32(pbox.Tag);
- if (ListOfPhotos?.Count > n)
- {
- ListOfPhotos.RemoveAt(n);
- ListOfPathsOfThePhotos.RemoveAt(n);
- pbox.Image.Dispose();
- pbox.Image = null;
- }
- }
- private void PictureBox2_DoubleClick(object sender, EventArgs e)
- {
- PictureBox pbox = (PictureBox)sender;
- int n = System.Convert.ToInt32(pbox.Tag);
- if (ListOfPhotos?.Count > n)
- {
- ListOfPhotos.RemoveAt(n);
- ListOfPathsOfThePhotos.RemoveAt(n);
- pbox.Image.Dispose();
- pbox.Image = null;
- }
- }
- private void PictureBox3_DoubleClick(object sender, EventArgs e)
- {
- PictureBox pbox = (PictureBox)sender;
- int n = System.Convert.ToInt32(pbox.Tag);
- if (ListOfPhotos?.Count > n)
- {
- ListOfPhotos.RemoveAt(n);
- ListOfPathsOfThePhotos.RemoveAt(n);
- pbox.Image.Dispose();
- pbox.Image = null;
- }
- }
- private void PictureBox4_DoubleClick(object sender, EventArgs e)
- {
- PictureBox pbox = (PictureBox)sender;
- int n = System.Convert.ToInt32(pbox.Tag);
- if (ListOfPhotos?.Count > n)
- {
- ListOfPhotos.RemoveAt(n);
- ListOfPathsOfThePhotos.RemoveAt(n);
- pbox.Image.Dispose();
- pbox.Image = null;
- }
- }
- private void PictureBox5_DoubleClick(object sender, EventArgs e)
- {
- PictureBox pbox = (PictureBox)sender;
- int n = System.Convert.ToInt32(pbox.Tag);
- if (ListOfPhotos?.Count > n)
- {
- ListOfPhotos.RemoveAt(n);
- ListOfPathsOfThePhotos.RemoveAt(n);
- pbox.Image.Dispose();
- pbox.Image = null;
- }
- }
- private void PictureBox6_DoubleClick(object sender, EventArgs e)
- {
- PictureBox pbox = (PictureBox)sender;
- int n = System.Convert.ToInt32(pbox.Tag);
- if (ListOfPhotos?.Count > n)
- {
- ListOfPhotos.RemoveAt(n);
- ListOfPathsOfThePhotos.RemoveAt(n);
- pbox.Image.Dispose();
- pbox.Image = null;
- }
- }
- }
- }