Hi Codeproject..
I got some code from this site in VB.NET,
this code is how to make a LinkLabel with an Icons...
but i Got Some Error...Can u help me to fix it..and tell me what's wrong with it
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Windows.Forms;
namespace IntegratedExpress.Library.UI
{
[Designer(typeof(IconicLinkLabelDesigner)), ToolboxItem(true), ToolboxBitmap(typeof(LinkLabel))]
public class IconicLinkLabel : System.Windows.Forms.Label
{
#region " API "
private const int WM_SETCURSOR = 0x20;
private const int WM_MOUSELEAVE = 0x2a3;
private const int IDC_HAND = 32649;
[DllImport("user32.dll")]
private static extern int LoadCursor(int hInstance, int lpCursorName);
[DllImport("user32.dll")]
private static extern int SetCursor(int hCursor);
#endregion
private Color _ColorNormal = SystemColors.ActiveCaption;
private Color _ColorHover = SystemColors.GradientActiveCaption;
[System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("Color of the text while the mouse is NOT hovering over it.")]
public System.Drawing.Color ColorNormal
{
get { return this._ColorNormal; }
set
{
this.ForeColor = value;
this._ColorNormal = value;
}
}
[System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("Color of the text while the mouse is hovering over it.")]
public System.Drawing.Color ColorHover
{
get { return this._ColorHover; }
set { this._ColorHover = value; }
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_SETCURSOR:
SetCursor(LoadCursor(0, IDC_HAND));
this.Font = new System.Drawing.Font(this.Font.Name, this.Font.Size, System.Drawing.FontStyle.Underline);
this.ForeColor = this._ColorHover;
break;
case WM_MOUSELEAVE:
SetCursor(0);
this.Font = new System.Drawing.Font(this.Font.Name, this.Font.Size, System.Drawing.FontStyle.Regular);
this.ForeColor = this._ColorNormal;
break;
}
}
public IconicLinkLabel()
{
this.ForeColor = this._ColorNormal;
this.AutoSize = false;
this.Height = 16;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Rectangle imageRect = new Rectangle();
Rectangle textRect = new Rectangle();
imageRect.X = 0 + this.Padding.Left;
imageRect.Y = 0 + this.Padding.Top;
if ((this.Image != null))
{
imageRect.Width = this.Image.Width;
imageRect.Height = this.Image.Height;
textRect.X = this.Image.Width + this.Padding.Left + 5;
e.Graphics.DrawImage(this.Image, imageRect);
}
else
{
textRect.X = 0 + this.Padding.Left;
}
textRect.Y = 1.25 + this.Padding.Top;
textRect.Height = this.Height - (this.Padding.Bottom + this.Padding.Top);
textRect.Width = this.Width - textRect.X - this.Padding.Right;
e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(this.ForeColor), textRect);
}
}
public class IconicLinkLabelDesigner : System.Windows.Forms.Design.ControlDesigner
{
private DesignerActionListCollection lists;
public override DesignerActionListCollection ActionLists
{
get
{
if (lists == null)
{
lists = new DesignerActionListCollection();
lists.Add(new IconicLinkLabelActionList(this.Component));
}
return lists;
}
}
//remove the properties that we don
protected override void PreFilterProperties(System.Collections.IDictionary properties)
{
properties.Remove("Cursor");
properties.Remove("ForeColor");
properties.Remove("ImageAlign");
properties.Remove("TextAlign");
properties.Remove("AutoSize");
}
}
public class IconicLinkLabelActionList : System.ComponentModel.Design.DesignerActionList
{
private IconicLinkLabel MyLabel;
private DesignerActionUIService designerActionSvc = null;
public IconicLinkLabelActionList(IComponent component)
: base(component)
{
this.MyLabel = Component;
this.designerActionSvc = (DesignerActionUIService)GetService(typeof(DesignerActionUIService));
}
private PropertyDescriptor GetPropertyByName(string propName)
{
PropertyDescriptor prop = null;
prop = TypeDescriptor.GetProperties(MyLabel)[propName];
if (prop == null)
{
throw new ArgumentException("Invalid property.", propName);
}
else
{
return prop;
}
}
public System.Drawing.Color ColorNormal
{
get { return MyLabel.ColorNormal; }
set { GetPropertyByName("ColorNormal").SetValue(MyLabel, value); }
}
public System.Drawing.Color ColorHover
{
get { return MyLabel.ColorHover; }
set { GetPropertyByName("ColorHover").SetValue(MyLabel, value); }
}
public System.Drawing.Image Image
{
get { return MyLabel.Image; }
set { GetPropertyByName("Image").SetValue(MyLabel, value); }
}
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionHeaderItem("Appearance"));
items.Add(new DesignerActionPropertyItem("Image", "Link Image", "Appearance", "Sets the image to be displayed in the label."));
items.Add(new DesignerActionPropertyItem("ColorNormal", "Normal Color", "Appearance", "Sets the color of the text while the mouse is NOT hovering over it."));
items.Add(new DesignerActionPropertyItem("ColorHover", "Hover Color", "Appearance", "Sets the color of the text while the mouse is hovering over it."));
return items;
}
}
}
it's show error on Cannot implicitly convert type 'System.ComponentModel.IComponent' to 'IntegratedExpress.Library.UI.IconicLinkLabel'. An explicit conversion exists (are you missing a cast?) Line 149
and the second error is Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?) Line 101 I think i understand the second error..but i don't mind how to convert double to integer
Need an Answer soon..
Thx