2016-07-18 4 views
0

私はたくさんの座標を持っており、それらをビットマップイメージ上の座標系として描画します。私は近所の座標を見つけた場合、私は私のCursorShapeを変更したい、近くの座標がある場合、どのようにカーソルの形状を変更できますか?

public void HighLightNearbyDots(Point _mousePosition) 
{ 
    // .. 

    foreach (var point in myDisplayedCoords) 
    { 
     Distance = (int)(MousePosition - point); // this gets the distance between two points and converts it to an int 

     if (Distance < 10) 
      point.Color = Colors.Red; 
     else 
      point.Color = InitialCoordColor; 
    } 
    DrawImage(); 
} 

今:私のイメージの上に私のマウスをホバリングしながら、私は以下のルーチンを使用して、私のMousePositionから一定Distance内にある座標を強調したいですを手にしてください。私はその中で行うことはできませんif (Distance < NearbyCursorDistance);どうして?私はelseで矢印(マイクロ秒を要する)に戻す必要があり、ユーザーはそれを見ないか、または残りの実行のために手元にとどまる。それは動作しますが、MyDisplayedCoordsが、私は今、二回反復する持っている、巨大であれば、それは多くの時間がかかり、ユーザーが意志

public void HighLightNearbyDots(Point _mousePosition) 
{ 
    //.. 

    if (IsThereANearbyDot(MousePosition)) 
     CursorShape = Cursors.Hand; 
    else 
     CursorShape = Cursors.Arrow; 

    foreach (var point in myDisplayedCoords) 
    { 
     Distance = (int)(MousePosition - point); 

     if (Distance < 10) 
      point.Color = Colors.Red; 
     else 
      point.Color = InitialCoordColor; 
    } 
    DrawImage(); 
} 

:だから私はこの実装:

private bool IsThereANearbyDot(CoordPoint _mousePosition) 
{ 
    foreach(var point in MyDisplayedCoords) 
    { 
     if (10 > (int) (_mousePosition - point)) 
      return true; 
    } 
    return false; 
} 

をこのようにそれを使用します画面に遅れがあることに注意してください。どうすればこの問題を解決できますか?

+0

「myDisplayedCoords」の定義は何ですか? –

+0

こんにちは!それは 'List 'であり、 'CordPoint'は' x'と 'y'だけの単純な点です@VisualVincent –

+0

あなたは何をターゲットにしていますか?Winforms、WPF、ASP ..? __Always__あなたの質問に正しくタグを付けてください! – TaW

答えて

2

HighLightNearbyDots()メソッドの開始時にカーソルをデフォルト(矢印)に設定してからdistance < 10句(elseではなく)に設定するだけです。例:

public void HighLightNearbyDots(Point _mousePosition) 
{ 
    // .. 

    CursorShape = Cursors.Arrow; 

    foreach (var point in myDisplayedCoords) 
    { 
     Distance = (int)(MousePosition - point); // this gets the distance between two points and converts it to an int 

     if (Distance < 10) 
     { 
      CursorShape = Cursors.Hand; 
      point.Color = Colors.Red; 
     } 
     else 
      point.Color = InitialCoordColor; 
    } 
    DrawImage(); 
} 

あなたはカーソルのちらつきの問題を持っていないはずですが、あなたが行う場合は、フラグを設定し、ちょうどこのように、この方法では一度カーソルを設定できます

public void HighLightNearbyDots(Point _mousePosition) 
{ 
    // .. 
    bool handCursor = false; 

    foreach (var point in myDisplayedCoords) 
    { 
     Distance = (int)(MousePosition - point); // this gets the distance between two points and converts it to an int 

     if (Distance < 10) 
     { 
      handCursor = true; 
      point.Color = Colors.Red; 
     } 
     else 
      point.Color = InitialCoordColor; 
    } 

    CursorShape = handCursor ? Cursors.Hand : Cursors.Arrow; 
    DrawImage(); 
} 

これにより、HighLightNearbyDots()メソッド(たとえばマウス移動イベントなど)を実行するたびにカーソルが解決され、ドットをハイライトしない限りデフォルトのカーソルになります。場合はそれが手になります。

あなたの質問に対処できない場合は、あなたがやっていることを明確に示してくれるMinimal, Complete, and Verifiable exampleと、コードが何をしているのか、何をしたいのかについて正確な説明を加えてください。具体的にはあなたは問題を理解しています。

+0

こんにちはPeter、正確に正確な状況に対処するこの修正をお寄せいただきありがとうございます。そのため私はOPに追加の不要な情報を投稿しませんでした。私はそれを試してみると、それは意味をなさないと思うし、うまくいくと思う。どうして私はそれを考えなかったのですか?あまりにもアップアップされました:) –

+1

_「どうして私はそれを考えなかったのですか? :)あなたが問題に近づいているときには、明らかにすることは難しいかもしれません。時々、あなたが必要とするのは、それに目を向けた別のセットです。 –

+0

確かに:)私の心は細部に集中していました。私はすぐに仕事をするようになるでしょう:) –

関連する問題