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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| public partial class Window1 : Window {
public Window1() {
InitializeComponent();
}
private void Btn1_Click( object sender, RoutedEventArgs e ) {
row1.Background = Brushes.AliceBlue;
row2.Background = Brushes.Red;
}
private void row1_MouseMove( object sender, MouseEventArgs e ) {
if( e.LeftButton == MouseButtonState.Pressed ) {
DragDropEffects effects;
DataObject obj = new DataObject();
obj.SetData( typeof( Brush ), this.row1.Background );
effects = DragDrop.DoDragDrop( this.row1, obj, DragDropEffects.Copy | DragDropEffects.Move );
}
}
private void row1_DragOver( object sender, DragEventArgs e ) {
if( e.Data.GetDataPresent( typeof( Brush ) ) ) {
e.Effects = System.Windows.DragDropEffects.Copy;
}
else {
e.Effects = System.Windows.DragDropEffects.None;
}
}
private void row1_Drop( object sender, DragEventArgs e ) {
if( e.Data.GetDataPresent( typeof( Brush ) ) ) {
row1.Background = (Brush)e.Data.GetData( typeof( Brush ) );
}
}
private void row2_MouseMove( object sender, MouseEventArgs e ) {
if( e.LeftButton == MouseButtonState.Pressed ) {
DragDropEffects effects;
DataObject obj = new DataObject();
obj.SetData( typeof( Brush ), this.row2.Background );
effects = DragDrop.DoDragDrop( this.row2, obj, DragDropEffects.Copy | DragDropEffects.Move );
}
}
private void row2_DragOver( object sender, DragEventArgs e ) {
if( e.Data.GetDataPresent( typeof( Brush ) ) ) {
e.Effects = System.Windows.DragDropEffects.Copy;
}
else {
e.Effects = System.Windows.DragDropEffects.None;
}
}
private void row2_Drop( object sender, DragEventArgs e ) {
if( e.Data.GetDataPresent( typeof( Brush ) ) ) {
row2.Background = (Brush)e.Data.GetData( typeof( Brush ) );
}
}
} |
Partager