Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3782852
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:08:29+00:00 2026-05-19T11:08:29+00:00

I am new to using Event Handling in C# .NET, and I am trying

  • 0

I am new to using Event Handling in C# .NET, and I am trying to understand the behavior behind some simple code that I am experimenting with. I am working with a more complicated example, but I am hoping I will get a more focused answer if I simplify the example.

I have the following code which defines a main window with a ListBox that is initialized with values, and a panel in the window. I am working with dragging the ListBox Items and dropping them in the panel. To signify that the panel is reading the DragDrop event, I am simply just changing the background color.

My problem is, it is not changing the background color when I drop the values, hence, the DragDrop is not working. I know this is a bit exaggerated, but I am trying to understand why its not working.

Here is the following code that I am using.

     public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //Allow Panel to accept dropped values
        this.panel1.AllowDrop = true;

        //Initialize ListBox with sample values
        listBox1.Items.Add("First Name");
        listBox1.Items.Add("Last Name");
        listBox1.Items.Add("Phone");

        //Setup DragDrop Event Handler - is this correct, or even needed?
        this.panel1.DragDrop += new DragEventHandler(panel1_DragDrop);
    }

    private void listBox1_MouseDown(object sender, MouseEventArgs e)
    {
        ListBox box = (ListBox)sender;
        String selectedValue = box.Text;
        DoDragDrop(selectedValue.ToString(), DragDropEffects.Copy);
    }

    private void panel1_DragDrop(object sender, DragEventArgs e)
    {
        //Change Background color to signify value has been dropped
        ((Panel)sender).BackColor = Color.Black;
    }

}

I realize this is an oversimplified example. If you see what I am doing wrong, then please let me know.

EDIT To give an example of why I am confused, I change this example around to put the dragged ListBox Item text into a Textbox when the DragOver event was fired, and it worked fine, but when I tried to do the same thing when they dropped the values over the textbox, I could not get it to work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T11:08:30+00:00Added an answer on May 19, 2026 at 11:08 am

    Handle the panel’s DragEnter event and set e.Effects to something other than None.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a new event source and logging a message using the code
I'm doing some research in how to implement a event-handling scheme in C++ that
I'm having some problem handling the JS onClick event and Dojo. Waht i'm trying
I still new using Asp.net with vb.net Protected Sub login_Click(ByVal sender As Object, ByVal
I'm trying to implement a quite simple UI using SpringLayout (partly because I, as
Using an asp.net fileupload string in an Server Side onClick event. ASP.Net file upload
I am rather new to WPF. I'm trying to realize a chat app using
I'm facing some weird (at least for me) behavior on using the Common Item
I have a c# COM server defined some delegate for event handling. This is
I'm writting a simple prototype front end using a GridView that is populated via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.