Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Probleme mit DragEventHandler

Empfohlene Antworten

Veröffentlicht

Hi,

ich habe Probleme mit meinen drag&drop Event Handler.

Ich habe zwei ToolstripButtons die beide jeweils ein anderes Label auf einem Panel anlegen wenn ich den button per drag&drop bewege. Meinen EventHandler habe ich folgendermaßen registriert:

Toolstripbutton1:


            this.toolStripButton1.AutoSize = false;

            this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;

            this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));

            this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;

            this.toolStripButton1.Name = "toolStripButton1";

            this.toolStripButton1.Size = new System.Drawing.Size(23, 20);

            this.toolStripButton1.Text = "toolStripButton1";

            this.toolStripButton1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.station_MouseDown);


Toolstripbutton2:

           this.toolStripButton2.AutoSize = false;

            this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;

            this.toolStripButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton2.Image")));

            this.toolStripButton2.ImageTransparentColor = System.Drawing.Color.Magenta;

            this.toolStripButton2.Name = "toolStripButton2";

            this.toolStripButton2.Size = new System.Drawing.Size(23, 20);

            this.toolStripButton2.Text = "toolStripButton2";

            this.toolStripButton2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.geraet_MouseDown);

Und auf dem Panel folgendermaßen:

this.splitContainer3.Panel1.AllowDrop = true;

            this.splitContainer3.Panel1.AutoScroll = true;

            this.splitContainer3.Panel1.BackgroundImage = global::Lagerlogistik.Properties.Resources.Gitternetz2;

           this.splitContainer3.Panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragDrop);

           this.splitContainer3.Panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragEnter);

           this.splitContainer3.Panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.geraetAnlageplan_DragDrop);

           this.splitContainer3.Panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.geraetAnlageplan_DragEnter);

Meine Drag&drop EventHandler sehen folgendermaßen aus:

 #region mouseDown

        private void station_MouseDown(object sender, MouseEventArgs e)

        {

            this.DoDragDrop(new DataObject(), DragDropEffects.Copy | DragDropEffects.Move);         

        }

        #endregion


        #region dragEnter

        //tritt das objekt in den anlageplan ein soll eine station angezeigt werden

        private void stationAnlageplan_DragEnter(object sender, DragEventArgs e)

        {

            if ((e.KeyState & 8) == 8)

                e.Effect = DragDropEffects.Copy;

            else

                e.Effect = DragDropEffects.Move;


        }

        #endregion


        #region DragDrop

        //sobald die Maus losgelassen wird

        private void stationAnlageplan_DragDrop(object sender, DragEventArgs e)

        {                       

            Station stationNeu = new Station();

            this.splitContainer3.Panel1.Controls.Add(stationNeu);


            stationNeu.Location = this.PointToClient(new Point(e.X -107 , e.Y -52));

           // stationNeu.setSelected();


        }

        #endregion


#region mouseDown

        private void geraet_MouseDown(object sender, MouseEventArgs e)

        {

            this.DoDragDrop(new DataObject(), DragDropEffects.Copy | DragDropEffects.Move);         


        }

        #endregion



        #region dragEnter

        //tritt das objekt in den anlageplan ein soll eine station angezeigt werden

        private void geraetAnlageplan_DragEnter(object sender, DragEventArgs e)

        {

            if ((e.KeyState & 8) == 8)

                e.Effect = DragDropEffects.Copy;

            else

                e.Effect = DragDropEffects.Move;


        }

        #endregion



        #region DragDrop

        //sobald die Maus losgelassen wird

        private void geraetAnlageplan_DragDrop(object sender, DragEventArgs e)

        {                       

            Geraet geraetNeu = new Geraet();

            this.splitContainer3.Panel1.Controls.Add(geraetNeu);


            geraetNeu.Location = this.PointToClient(new Point(e.X -107 , e.Y -52));

           // stationNeu.setSelected();


        }


Mein Problem ist das jetzt immer egal auf welchen Button ich klicke beide DragEvents aufgerufen werden und beide Objekte angelegt werden (sieht man auch daran das beide panels auf dem label angezeigt werden). Ich will das wenn ich nur auf toolstrip1 klicke ein neues Stationsobjekt angelegt wird und wenn ich auf toolstripbutton2 klicke ein neues Geraetobjekt angelegt wird. Ich vemute das mein Fehler beim registrieren im Panel liegt aber ich habe keine ahnung wie man diesen weg bekommt. Meine einzige Idee ware im DragDrop EventHandler zu überprüfen welcher Typ es ist. Also ob Station oder Gerät. Aber ich habe keine Ahnung wie man das macht. Hat jemand eine Idee oder andere Vorschläge?

LG

sunny

Hi,

ich habe es auch folgendermaßen probiert.


        private void station_MouseDown(object sender, MouseEventArgs e)

        {

            this.splitContainer3.Panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragDrop);

            this.splitContainer3.Panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragEnter);

            this.DoDragDrop(new DataObject(), DragDropEffects.Copy | DragDropEffects.Move);


        }


        //tritt das objekt in den anlageplan ein soll eine station angezeigt werden

        private void stationAnlageplan_DragEnter(object sender, DragEventArgs e)

        {

            if ((e.KeyState & 8) == 8)

                e.Effect = DragDropEffects.Copy;

            else

                e.Effect = DragDropEffects.Move;


        }


        //sobald die Maus losgelassen wird

        private void stationAnlageplan_DragDrop(object sender, DragEventArgs e)

        {                       

            Station stationNeu = new Station();

            this.splitContainer3.Panel1.Controls.Add(stationNeu);


            stationNeu.Location = this.PointToClient(new Point(e.X -107 , e.Y -52));

           // stationNeu.setSelected();


        }


        private void geraet_MouseDown(object sender, MouseEventArgs e)

        {

            this.splitContainer3.Panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.geraetAnlageplan_DragDrop);

            this.splitContainer3.Panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.geraetAnlageplan_DragEnter);

            this.DoDragDrop(new DataObject(), DragDropEffects.Copy | DragDropEffects.Move);


        }


        //tritt das objekt in den anlageplan ein soll eine station angezeigt werden

        private void geraetAnlageplan_DragEnter(object sender, DragEventArgs e)

        {

            if ((e.KeyState & 8) == 8)

                e.Effect = DragDropEffects.Copy;

            else

                e.Effect = DragDropEffects.Move;


        }


        //sobald die Maus losgelassen wird

        private void geraetAnlageplan_DragDrop(object sender, DragEventArgs e)

        {                       

            Geraet geraetNeu = new Geraet();

            this.splitContainer3.Panel1.Controls.Add(geraetNeu);


            geraetNeu.Location = this.PointToClient(new Point(e.X -107 , e.Y -52));

           // stationNeu.setSelected();


        }


Aber das funktioniert nur solange bis ich den anderen button angeklickt habe. Dann macht er es wieder falsch. Also wenn ich toolstripbutton1 anklicke dann kann ich beliebig viele stationen anlegen. sobald ich aber dann toolstrip2 anklicke macht er mir wieder eine station und ein gerät. Andersherum ist es genauso. wenn ich toolstripbutton2 anklicke legt er mir beliebig viele geräte an aber sobald ich toolstripbutton1 anklicke legt er mir wieder beides an.

Hat irgendjemand einen anderen Vorschlag?

LG

sunny

Hi,

habe es selber hinbekommen. Für alle die es interessiert man musste den DragEventHandler unten wieder deaktivieren.


        private void station_MouseDown(object sender, MouseEventArgs e)

        {

            this.splitContainer3.Panel1.DragDrop += new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragDrop);

            this.splitContainer3.Panel1.DragEnter += new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragEnter);

            this.DoDragDrop(new DataObject(), DragDropEffects.Copy | DragDropEffects.Move);


        }


        private void stationAnlageplan_DragEnter(object sender, DragEventArgs e)

        {

            if ((e.KeyState & 8) == 8)

                e.Effect = DragDropEffects.Copy;

            else

                e.Effect = DragDropEffects.Move;


        }


        private void stationAnlageplan_DragDrop(object sender, DragEventArgs e)

        {                       

            Station stationNeu = new Station();

            this.splitContainer3.Panel1.Controls.Add(stationNeu);


            stationNeu.Location = this.PointToClient(new Point(e.X -107 , e.Y -52));

           // stationNeu.setSelected();

            this.splitContainer3.Panel1.DragDrop -= new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragDrop);

            this.splitContainer3.Panel1.DragEnter -= new System.Windows.Forms.DragEventHandler(this.stationAnlageplan_DragEnter);



        }

LG

sunny

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.