How to give Windows Vista buttons effects?
Hi,
I am a IT student and I develop a software in C# in that I want to give glowing effects to all the buttons, it look something like windows vista’s button, I know for giving this effect use mouse hover event but I don’t how I implement the code please help me, and I sure here I get the solution for How to give Windows Vista buttons effects?
Re: How to give Windows Vista buttons effects?
Hey I also face this same problem in my project I write code for that but the problem you able to see in following code in that I give Strdate the value on Load event, but the button redraws immediately after drawing the text and the text disappears.
Quote:
private void onlod(object sender, EventArgs e)
{_brush = Brushes.Navy;
Strdate = "Sample Drawing";
}
#endregion
#region properties
private string Strdate
{
get { return _strdate; }
set
{
if (value.Equals(_strdate)) return;
Drwdate(value);
_strdate = value;
}
}
#endregion
#region text painting and stuff
private void Drwdate(string strdate)
{
Graphics g = back.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.DrawString(strdate, Font, Brush, new PointF(0, 0));
//TextRenderer.DrawText(g, "Sample Drawing...", Font, new Point(0, 0), Color.Navy);
g.Dispose();
}
#endregion
Re: How to give Windows Vista buttons effects?
I hopefully this following code will help you I properly edited this code here you have to just override the paint method which on a button to do what you want. And I think after that you able to get whatever you want from this code.
Quote:
class Lbtn : Button
{
[Category("Apranc")]
public string Lbltxt { get; set; }
[Category("Apranc")]
public Point Lbllocton { get; set; }
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
if (pevent != null)
{
pevent.Graphics.DrawString(Lbltxt, this.Font, Brushes.Black, Lbllocton);
}
}
}
Re: How to give Windows Vista buttons effects?
Hey I give you better solution for that because I also want to implement this same glowing effect to buttons in my project I also try many of things but after lots of try I get this code for solving same problem which you correctly face, and for solving your problem you have to use following code.
Quote:
protected override void Mouseover(MouseEventArgs mevn)
{
base.Mouseover(mevn);
Graphics g = this.CreateGraphics();
SizeF strSize = g.MeasureString(m_labelText, this.Font);
RectangleF labelRect = new RectangleF(m_labelLocation, strSize);
if (labelRect.Contains(new Point(mevn.X, mevn.Y)))
}
Re: How to give Windows Vista buttons effects?
Here i give you other option to you use if you want to ceate vista type buttonr in your project then use this code.
private void Drwglow(Graphics g)
{
if (this.ButtonStyle == Style.Flat && this.mButtonState == State.None){return;}
int butn = (mButtonState == State.Pressed) ? 60 : 150;
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height / 2);
using (GraphicsPath r = RoundRect(rect, CornerRadius, CornerRadius, 0, 0))
{
using (LinearGradientBrush lg = new LinearGradientBrush(r.GetBounds(),
Color.FromArgb(butn, this.HighlightColor),
Color.FromArgb(butn / 3, this.HighlightColor),
LinearGradientMode.Vertical))
{
g.FillPath(lg, r);
}
}
}