已经实现鼠标按住左键不放 进行拖拽选定.
问:如何设置选定控件的背景色为红色代码 <Grid Name="grid1" Margin="47,190,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="286" Width="777" MouseLeftButtonDown="grid1_MouseLeftButtonDown" MouseLeftButtonUp="grid1_MouseLeftButtonUp" MouseMove="grid1_MouseMove">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Name="gridContainer1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="286" Width="777" MouseLeftButtonDown="grid1_MouseLeftButtonDown">
</Grid>
</Grid> Line oneTotwo;
Line oneTothree;
Line twoTofour;
Line threeTofour; int clicktimes = 0;
private void grid1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
int x = Convert.ToInt32(e.GetPosition(grid1).X);
int y = Convert.ToInt32(e.GetPosition(grid1).Y); label2333.Content = "x:" + x + " y:" + y;
if (clicktimes > 0)
{
for (int i = 0; i < 4; i++)
{
grid1.Children.RemoveAt(0);
}
clicktimes = 0;
}
if (0 == clicktimes)
{ Point clickPoint = (Point)e.GetPosition(grid1);
oneTotwo = new Line();
oneTotwo.Stroke = Brushes.Red;
oneTotwo.Fill = Brushes.Red;
oneTotwo.StrokeLineJoin = PenLineJoin.Bevel;
oneTotwo.X1 = clickPoint.X;
oneTotwo.Y1 = clickPoint.Y;
oneTotwo.X2 = clickPoint.X + 10;
oneTotwo.Y2 = clickPoint.Y;
oneTotwo.StrokeThickness = 1;
grid1.Children.Insert(0,oneTotwo);
int zindex = grid1.Children.Count;
Grid.SetZIndex(oneTotwo, zindex); oneTothree = new Line();
oneTothree.Stroke = Brushes.Red;
oneTothree.Fill = Brushes.Red;
oneTothree.StrokeLineJoin = PenLineJoin.Bevel;
oneTothree.X1 = clickPoint.X;
oneTothree.Y1 = clickPoint.Y;
oneTothree.X2 = clickPoint.X;
oneTothree.Y2 = clickPoint.Y + 10;
oneTothree.StrokeThickness = 1;
grid1.Children.Insert(1,oneTothree);
zindex = grid1.Children.Count;
Grid.SetZIndex(oneTothree, zindex); twoTofour = new Line();
twoTofour.Stroke = Brushes.Red;
twoTofour.Fill = Brushes.Red;
twoTofour.StrokeLineJoin = PenLineJoin.Bevel;
twoTofour.X1 = clickPoint.X + 10;
twoTofour.Y1 = clickPoint.Y;
twoTofour.X2 = clickPoint.X + 10;
twoTofour.Y2 = clickPoint.Y + 10;
twoTofour.StrokeThickness = 1;
grid1.Children.Insert(2, twoTofour);
zindex = grid1.Children.Count;
Grid.SetZIndex(twoTofour, zindex); threeTofour = new Line();
threeTofour.Stroke = Brushes.Red;
threeTofour.Fill = Brushes.Red;
threeTofour.StrokeLineJoin = PenLineJoin.Bevel;
threeTofour.X1 = clickPoint.X;
threeTofour.Y1 = clickPoint.Y + 10;
threeTofour.X2 = clickPoint.X + 10;
threeTofour.Y2 = clickPoint.Y + 10;
threeTofour.StrokeThickness = 1;
grid1.Children.Insert(3, threeTofour);
zindex = grid1.Children.Count;
Grid.SetZIndex(threeTofour, zindex);
clicktimes++;
} } private void grid1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
int x = Convert.ToInt32(e.GetPosition(grid1).X);
int y = Convert.ToInt32(e.GetPosition(grid1).Y);
label2333.Content = "离开位置: " + Convert.ToString(x) + "," + Convert.ToString(y);
oneTotwo = null;
oneTothree = null;
twoTofour = null;
threeTofour = null;
//获取已选定的表格
object item = e.GetPosition(gridContainer1); //gridContainer1.RowDefinitions[0].
}
private void grid1_MouseMove(object sender, MouseEventArgs e)
{
Point drawPoint = (Point)e.GetPosition(grid1);
if (oneTotwo != null & twoTofour != null & oneTothree != null & threeTofour != null & e.LeftButton == MouseButtonState.Pressed)
{
twoTofour.X1 = oneTotwo.X2 = twoTofour.X2 = threeTofour.X2 = drawPoint.X;
threeTofour.Y1 = threeTofour.Y2 = twoTofour.Y2 = twoTofour.Y2 = oneTothree.Y2 = drawPoint.Y;
}
}WPF控件
问:如何设置选定控件的背景色为红色代码 <Grid Name="grid1" Margin="47,190,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="286" Width="777" MouseLeftButtonDown="grid1_MouseLeftButtonDown" MouseLeftButtonUp="grid1_MouseLeftButtonUp" MouseMove="grid1_MouseMove">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Name="gridContainer1" HorizontalAlignment="Left" VerticalAlignment="Top" Height="286" Width="777" MouseLeftButtonDown="grid1_MouseLeftButtonDown">
</Grid>
</Grid> Line oneTotwo;
Line oneTothree;
Line twoTofour;
Line threeTofour; int clicktimes = 0;
private void grid1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
int x = Convert.ToInt32(e.GetPosition(grid1).X);
int y = Convert.ToInt32(e.GetPosition(grid1).Y); label2333.Content = "x:" + x + " y:" + y;
if (clicktimes > 0)
{
for (int i = 0; i < 4; i++)
{
grid1.Children.RemoveAt(0);
}
clicktimes = 0;
}
if (0 == clicktimes)
{ Point clickPoint = (Point)e.GetPosition(grid1);
oneTotwo = new Line();
oneTotwo.Stroke = Brushes.Red;
oneTotwo.Fill = Brushes.Red;
oneTotwo.StrokeLineJoin = PenLineJoin.Bevel;
oneTotwo.X1 = clickPoint.X;
oneTotwo.Y1 = clickPoint.Y;
oneTotwo.X2 = clickPoint.X + 10;
oneTotwo.Y2 = clickPoint.Y;
oneTotwo.StrokeThickness = 1;
grid1.Children.Insert(0,oneTotwo);
int zindex = grid1.Children.Count;
Grid.SetZIndex(oneTotwo, zindex); oneTothree = new Line();
oneTothree.Stroke = Brushes.Red;
oneTothree.Fill = Brushes.Red;
oneTothree.StrokeLineJoin = PenLineJoin.Bevel;
oneTothree.X1 = clickPoint.X;
oneTothree.Y1 = clickPoint.Y;
oneTothree.X2 = clickPoint.X;
oneTothree.Y2 = clickPoint.Y + 10;
oneTothree.StrokeThickness = 1;
grid1.Children.Insert(1,oneTothree);
zindex = grid1.Children.Count;
Grid.SetZIndex(oneTothree, zindex); twoTofour = new Line();
twoTofour.Stroke = Brushes.Red;
twoTofour.Fill = Brushes.Red;
twoTofour.StrokeLineJoin = PenLineJoin.Bevel;
twoTofour.X1 = clickPoint.X + 10;
twoTofour.Y1 = clickPoint.Y;
twoTofour.X2 = clickPoint.X + 10;
twoTofour.Y2 = clickPoint.Y + 10;
twoTofour.StrokeThickness = 1;
grid1.Children.Insert(2, twoTofour);
zindex = grid1.Children.Count;
Grid.SetZIndex(twoTofour, zindex); threeTofour = new Line();
threeTofour.Stroke = Brushes.Red;
threeTofour.Fill = Brushes.Red;
threeTofour.StrokeLineJoin = PenLineJoin.Bevel;
threeTofour.X1 = clickPoint.X;
threeTofour.Y1 = clickPoint.Y + 10;
threeTofour.X2 = clickPoint.X + 10;
threeTofour.Y2 = clickPoint.Y + 10;
threeTofour.StrokeThickness = 1;
grid1.Children.Insert(3, threeTofour);
zindex = grid1.Children.Count;
Grid.SetZIndex(threeTofour, zindex);
clicktimes++;
} } private void grid1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
int x = Convert.ToInt32(e.GetPosition(grid1).X);
int y = Convert.ToInt32(e.GetPosition(grid1).Y);
label2333.Content = "离开位置: " + Convert.ToString(x) + "," + Convert.ToString(y);
oneTotwo = null;
oneTothree = null;
twoTofour = null;
threeTofour = null;
//获取已选定的表格
object item = e.GetPosition(gridContainer1); //gridContainer1.RowDefinitions[0].
}
private void grid1_MouseMove(object sender, MouseEventArgs e)
{
Point drawPoint = (Point)e.GetPosition(grid1);
if (oneTotwo != null & twoTofour != null & oneTothree != null & threeTofour != null & e.LeftButton == MouseButtonState.Pressed)
{
twoTofour.X1 = oneTotwo.X2 = twoTofour.X2 = threeTofour.X2 = drawPoint.X;
threeTofour.Y1 = threeTofour.Y2 = twoTofour.Y2 = twoTofour.Y2 = oneTothree.Y2 = drawPoint.Y;
}
}WPF控件
解决方案 »
- C# winform程序,怎样加载图标??
- 请问,这个LINQ查询,怎么写
- 菜鸟问题~谁能给解释一下这段程序的详细执行过程
- 数据导入的代码怎么写哦
- 如果数据库中没有数据怎么通过后台知道呢?
- 顶者有分~~!!!导出数据到Excel总是出错。数据量超过三万条,一次性导出到Excel.使用C#语言写
- 高手请进提取登陆后的网页验证码图片?
- 扫描仪扫描出来的打印好的文章,里面的汉字和字符能不能转换到Word或者记事本里面
- 如何取得一个控件(如TextBox)在页面中的绝对位置 100分
- windows窗体应用程序中怎样实现一个控件(比如button)在界面上鼠标控制自由移动
- WPF 怎么实现在窗体1中点击按钮关闭窗体2?
- wpf 控件句柄
if (sender != null)
{
var buttonModel = sender as Button;
buttonModel.Background = = new SolidColorBrush(Colors.Red);//需要的颜色
}