Hallo Leute!
Hat jemand eine Idee, wie ich den MouseHover-Effekt , von meinem Steuerelement, beschleunigen kann?
Gruss,
Steff
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace BECRM_GUI_Test_OutlookBar_01
{
/// <summary>
/// Zusammenfassung für BECRM_ControlBar.
/// </summary>
public class BECRMControlBarButton : System.Windows.Forms.Button
{
private Brush brButton_normal;
private Brush brButton_normal_hover;
private Brush brButton;
private Brush brLabel;
private Pen myPen;
public BECRMControlBarButton()
{
this.Width = 200;
this.Height = 32;
brButton_normal = new System.Drawing.Drawing2D.LinearGradientBrush
(this.ClientRectangle, Color.White, Color.Red, 90);
brButton_normal_hover = new System.Drawing.Drawing2D.LinearGradientBrush
(this.ClientRectangle, Color.White, Color.Blue, 90);
brButton = brButton_normal;
brLabel = new SolidBrush(Color.Black);
myPen = new Pen(Color.FromArgb(128, 128, 128), 2);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics gr = pe.Graphics;
//Button füllen
gr.FillRectangle(brButton, this.ClientRectangle);
//Rahmen zeichnen
gr.DrawRectangle(myPen, new Rectangle(new Point(0, 0), this.Size));
//Beschriftungs-Text
gr.DrawString(this.Text, new Font(this.Font, FontStyle.Bold), brLabel, 50, 10);
}
/// <summary>
/// MouseHover
/// </summary>
/// <param name=>e>></param>
protected override void OnMouseHover(EventArgs e)
{
brButton = brButton_normal_hover;
this.Invalidate(this.ClientRectangle);
base.OnMouseHover(e);
}
/// <summary>
/// MouseLeave
/// </summary>
/// <param name=>e>></param>
protected override void OnMouseLeave(EventArgs e)
{
brButton = brButton_normal;
this.Invalidate(this.ClientRectangle);
base.OnMouseLeave(e);
}
}
}
Wenn ich, anstelle von OnMouseHover, OnMouseEnter verwende, funktioniert es so wie ich es mir vorgestellt habe.
Ausserdem habe ich noch Update() für das neu zeichnen vergessen.
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
brButton = brButton_normal_hover;
Invalidate();
Update();
}
Gruss,
Steff