[英]How to change my mouse cursor when my mouse hover on specified area of my control? using c#
[英]How to fill different color for one of my rectangle from my list when the mouse is hover on that particular area?
如果鼠標懸停在我想更改鼠標坐標所在矩形的顏色的矩形區域上,我有矩形列表。 我已經這樣做了,但顏色不夠快,無法改變。 以下方法選擇它是哪個矩形。
void OnMouseMoveOnTheRectangles(MouseEventArgs e)
{
RectangleF[] allRectangles = new RectangleF[aListDrawings.Count];
aListDrawings.CopyTo(allRectangles);
if (allRectangles.Length == 0)
return;
RectangleF currentSelected = RectangleF.Empty;
foreach (RectangleF rec in allRectangles)
{
RectangleF current = GetOffsetRectangle(rec);
if (current.Contains(e.Location))
{
_currentActive = current;
break;
}
}
}
這是我的 RedDraw 函數,你可以調用它
protected virtual void DrawSelection(PaintEventArgs e, RectangleF[] sRegion,
SolidBrush _brush)
{
if (sRegion.Length == 0)
return;
e.Graphics.SetClip(this.GetInsideViewPort(true));
RectangleF[] offsetRectangles = new RectangleF[sRegion.Length];
int x = 0;
foreach (RectangleF r in sRegion)
{
offsetRectangles[x] = this.GetOffsetRectangle(r);
x++;
}
using (Brush brush = _brush)
{
e.Graphics.FillRectangles(brush, offsetRectangles);
}
//This is where i color i tried to change the color for that particular rectangle
if (_currentActive != RectangleF.Empty)
{
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0x90, Color.Red)),
_currentActive);
}
using (Pen pen = new Pen(this.SelectionColor))
{
e.Graphics.DrawRectangles(pen, offsetRectangles);
}
e.Graphics.ResetClip();
}
就像@TaW 所說的那樣,Invalidate 函數可以幫您解決問題。 它將在適當的時間觸發 Paint 事件,您的圖形將被更新。 找到無效的任何控制元素都有它。 因此,您可以使用畫布控件下的 invalidate 方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.