Microsoft
Software
Hardware
Network
Question : Using dragdrop, how to "reset" color of a label when mouse leaves and drop has not occurred?
To create a simple example:
1. Begin a new WinForms project named TEST DragDrop.
2. On Form1, use the toolbox to:
- Add label1 and set Properties to AllowDrop.
- Add label2 and set Properties to AllowDrop.
- Add richTextBox1 and set Properties to EnableAutoDragDrop.
3. Modify the code in Form1 to look like this:
public Form1()
{
InitializeComponent();
}
private void AnyLabel_DragEnter(object sender, DragEventArgs e)
{
//Get sender
Label lbl = (Label)sender;
lbl.BackColor = Color.Green;
if (e.Data.GetDataPresent(Dat
aFormats.T
ext))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void AnyLabel_DragDrop(object sender, DragEventArgs e)
{
//Get sender and insert text string
Label lbl = (Label)sender;
lbl.Text = (string)e.Data.GetData(Dat
aFormats.T
ext, false);
}
}
4. In Properties, for each label click Events and:
- For DragEnter, select AnyLabel_DragEnter
- For DragDrop, select AnyLabel_DragDrop
5. Compile and run. Type some text into the textbox, select the text, and drag the text to label1 and continue dragging to label2. Drop the text on label2.
COMMENTS: The problem is that when the drop is not released and the mouse leaves label1, the BackColor should reset to normal. Then the mouse could travel back and forth between each label (showing "green" then "not green") until the drop is released.
Answer : Using dragdrop, how to "reset" color of a label when mouse leaves and drop has not occurred?
Handle DragLeave for the label and in that handler set the back color back to the default like:
private void AnyLabel_DragLeave(object sender, EventArgs e)
{
Label lbl = (Label)sender;
lbl.BackColor = defaultLabelBackColor;
}
Random Solutions
Exchange 2010. Install Failed, now can't uninstall
transfering a directory with multiple files in parallel
Flex CountDown Timer
asp.net connection string error.
Word 2003 - working with tables, rows, and cells
Outlook not attack shortcut (lnk) attach directly the file
#550 5.3.4 SMTPSEND.OverAdvertisedSiz
e; message size exceeds fixed maximum size ##
Windows batch file to trigger e-mail notification.
SQL Server function to call the excel function gammaln
What is the best Server Antivirus going right now? What are you guys using?