MouseEnter
, MouseLeave
, MouseDown
ve MouseUp
olduğunda farklı renklere sahip özel bir düğmem var. Ancak, FolderBrowserDialog
, MouseClick
'dan sonra açıldı ve ondan bir dizin seçildiğinde, farenin düğmesinin dışında olmasına rağmen renk hala MouseEnter
renginde kalıyor. Bunun neden olduğunu anlayamıyorum. Capture
kullanarak sorunu çözmeye çalıştım, ancak benim için çalışmadı. Belki yanlış kullanırdım.Neden folderLrowserdialog açık ve bir dizin seçildiğinde MouseLeave olayı tetiklenmiyor?
MyButton
sınıfta My kodun olaylar kısmı: Ben MouseUp
olay kodu değiştirmeden sorunumu çözmüş
//.....
protected override void OnPaint(PaintEventArgs e)
{
//.....
#region Drawing
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
roundedRect = new RoundedRectangle(Width, Height, radius);
e.Graphics.FillRectangle(Brushes.Transparent, this.ClientRectangle);
int R1 = (active1.R + inactive1.R)/2;
int G1 = (active1.G + inactive1.G)/2;
int B1 = (active1.B + inactive1.B)/2;
int R2 = (active2.R + inactive2.R)/2;
int G2 = (active2.G + inactive2.G)/2;
int B2 = (active2.B + inactive2.B)/2;
Rectangle rect = new Rectangle(0, 0, Width, Height);
if (this.Enabled)
{
if (state == MouseState.Leave)
using (LinearGradientBrush inactiveGB = new LinearGradientBrush(rect, inactive1, inactive2, 90f))
e.Graphics.FillPath(inactiveGB, roundedRect.Path);
else if (state == MouseState.Over)
using (LinearGradientBrush activeGB = new LinearGradientBrush(rect, active1, active2, 90f))
e.Graphics.FillPath(activeGB, roundedRect.Path);
else if (state == MouseState.Down)
using (LinearGradientBrush downGB = new LinearGradientBrush(rect, Color.FromArgb(R1, G1, B1), Color.FromArgb(R2, G2, B2), 90f))
e.Graphics.FillPath(downGB, roundedRect.Path);
using (LinearGradientBrush BorderGB = new LinearGradientBrush(rect, inactive1, inactive2, 90f))
e.Graphics.DrawPath(new Pen(BorderGB), roundedRect.Path);
}
else
{
Color linear1 = Color.FromArgb(190, 190, 190);
Color linear2 = Color.FromArgb(210, 210, 210);
using (LinearGradientBrush inactiveGB = new LinearGradientBrush(rect, linear1, linear2, 90f))
{
e.Graphics.FillPath(inactiveGB, roundedRect.Path);
e.Graphics.DrawPath(new Pen(inactiveGB), roundedRect.Path);
}
}
#endregion
//.....
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
}
protected override void OnEnabledChanged(EventArgs e)
{
Invalidate();
base.OnEnabledChanged(e);
}
protected override void OnMouseEnter(EventArgs e)
{
state = MouseState.Over;
Invalidate();
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
state = MouseState.Leave;
Invalidate();
base.OnMouseLeave(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
state = MouseState.Down;
Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseEventArgs e)
{
state = MouseState.Up;
Invalidate();
base.OnMouseUp(e);
}
#endregion
//.....