Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
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

VB
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't want the user to change
        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
Posted
Updated 8-Jul-11 6:48am
v3
Comments
DaveyM69 7-Jul-11 14:49pm    
Perhaps you should help us to help you by identifying the line on which the error occurs and what the error message is?

Go here for conversion (it's a free web-based converter).

http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]

It does a fairly good job most of the time, but you may still have to tweak it manually.

If you need it converted "soon", you'll be better of muscling through it - believe me.
 
Share this answer
 
v2
Try debugging your code to see what the error is and where it occurs.
It will probably help you solve it.
 
Share this answer
 
Comments
SunLucDong 7-Jul-11 13:35pm    
i have debug it before and it show an error before i ask this question on this site
fjdiewornncalwe 7-Jul-11 16:09pm    
Tell us what the error is and what line it is on. Then we have something to help you.
SunLucDong 8-Jul-11 12:44pm    
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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900