Click here to Skip to main content
15,867,308 members
Home / Discussions / C#
   

C#

 
GeneralRe: best way to license .net application Pin
DaveAuld12-Dec-13 6:16
professionalDaveAuld12-Dec-13 6:16 
AnswerRe: best way to license .net application Pin
thatraja12-Dec-13 6:26
professionalthatraja12-Dec-13 6:26 
GeneralRe: best way to license .net application Pin
PIEBALDconsult12-Dec-13 17:36
mvePIEBALDconsult12-Dec-13 17:36 
AnswerRe: best way to license .net application Pin
jschell13-Dec-13 9:55
jschell13-Dec-13 9:55 
SuggestionHow to set transparent on listbox Pin
Member 1026763012-Dec-13 0:52
Member 1026763012-Dec-13 0:52 
GeneralRe: How to set transparent on listbox Pin
Simon_Whale12-Dec-13 1:03
Simon_Whale12-Dec-13 1:03 
GeneralRe: How to set transparent on listbox Pin
Marco Bertschi12-Dec-13 1:20
protectorMarco Bertschi12-Dec-13 1:20 
GeneralRe: How to set transparent on listbox Pin
Member 1026763012-Dec-13 1:44
Member 1026763012-Dec-13 1:44 
thanks guys.

i find a transparent class in you tube but List box dont have a SCROLL.

C#
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

public class ListBox : Label
{
    public ListBox()
    {
        this.Size = new Size(165, 124);
        this.MinimumSize = new Size(25, 25);
        this.ForeColor = SystemColors.Highlight;
        this.Font = new Font("Microsoft Sans Serif", 8F, FontStyle.Regular, GraphicsUnit.Point, 0);
        this.ScrollAlwaysVisible = true;
    }

    #region Storage
    List<object> lst = new List<object>();
    Color SBorCol = Color.DarkBlue, SelCol = Color.DodgerBlue, BorCol = Color.Navy, InBorCol = Color.SlateBlue;
    string tmp = string.Empty;
    byte SelAlpha = 50;
    Size FSize;
    int _Index = -1, SIndex = 0;
    bool _Focus;
    #endregion

    #region Overrides

    protected override void OnFontChanged(EventArgs e)
    {
        base.OnFontChanged(e);
        FSize = TextRenderer.MeasureText("X", this.Font);
    }

    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);
        this.AutoSize = false;
        this.Text = string.Empty;
        this.BackColor = Color.Transparent;
    }

    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
        if (e.Button == MouseButtons.Left)
        {
            this.Focus();
            _Focus = true;
            _Index = -1;
            Point P = this.PointToClient(MousePosition);
            for (int i = lst.Count; i-- > 0; )
            {
                if (i < MaxCount)
                {
                    if (P.Y >= (FSize.Height * i) + 5 & P.Y < (FSize.Height * i) + (FSize.Height + 5))
                    {
                        this.Refresh();
                        _Index = i + SIndex;
                        this.CreateGraphics().FillRectangle(new SolidBrush(Color.FromArgb(SelAlpha, SelCol)), new Rectangle(5, (FSize.Height * i) + 5, this.Width - 12, FSize.Height));
                        this.CreateGraphics().DrawRectangle(new Pen(SBorCol), new Rectangle(5, (FSize.Height * i) + 5, this.Width - 12, FSize.Height));
                    }
                }
            }
        }
    }

    protected override void OnInvalidated(InvalidateEventArgs e)//
    {
        base.OnInvalidated(e);
        tmp = string.Empty;
        int Co = 0;
        for (int i = SIndex; i < lst.Count; i++)
        {
            if (Co == MaxCount) return;
            tmp += lst[i] + "\n";
            Co++;
        }
    }

    #endregion

    #region Draw

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        e.Graphics.DrawRectangle(new Pen(BorCol, 4), new Rectangle(2, 2, this.Width - 5, this.Height - 5));
        e.Graphics.DrawRectangle(new Pen(InBorCol, 2), new Rectangle(4, 4, this.Width - 9, this.Height - 9));
        TextRenderer.DrawText(e.Graphics, tmp, this.Font, new Point(5, 5), this.ForeColor);
        if (_Index != -1)//Draws item highlight when scrolling
        {
            e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(SelAlpha, SelCol)), new Rectangle(5, (FSize.Height * (_Index - SIndex)) + 5, this.Width - 12, FSize.Height));
            e.Graphics.DrawRectangle(new Pen(SBorCol), new Rectangle(5, (FSize.Height * (_Index - SIndex)) + 5, this.Width - 12, FSize.Height));
        }
    }

    #endregion

    #region UserSettings

    public Color SelectBorderColor
    {
        get { return SBorCol; }
        set { SBorCol = value; }
    }

    [Browsable(false)]
    public new Color BackColor
    {
        get { return base.BackColor; }
        set { base.BackColor = Color.Transparent; }
    }

    public Color BorderColor
    {
        get { return BorCol; }
        set { BorCol = value; }
    }
    public Color BorderColorInner
    {
        get { return InBorCol; }
        set { InBorCol = value; }
    }
    public Color SelectColor
    {
        get { return SelCol; }
        set { SelCol = value; }
    }

    public byte SelectAlpha
    {
        get { return SelAlpha; }
        set
        {
            SelAlpha = value <= 100 ? value : (byte)50;
        }
    }

    #endregion

    #region Functions

    public void Add(object Value)
    {
        if (Value == null) return;
        int i;
        if ((i = lst.IndexOf(Value)) == -1)
        {
            lst.Add(Value);
        }
        this.Invalidate();
        
    }

    [Browsable(false)]
    public int SelectedIndex
    {
        get { return _Index; }
    }

    public void RemoveAt(int Index)
    {
        if (Index != -1 & Index <= lst.Count)
        {
            lst.RemoveAt(Index);
            this.Invalidate();
        }
    }

    public void Remove(object Value)
    {
        if (Value == null) return;
        int i;
        if ((i = lst.IndexOf(Value)) != -1)
        {
            lst.RemoveAt(i);
            this.Invalidate();
        }
    }

    public bool Contains(object Value)
    {
        return lst.Contains(Value);
    }

    public void Clear()
    {
        lst.Clear();
        this.Invalidate();
    }

    int MaxCount
    {
        get
        {
            return ((this.Height - 8) / FSize.Height);
        }
    }

    [Browsable(false)]
    public object SelectedItem
    {
        get
        {
            return SelectedIndex != -1 ? lst[_Index] : null;
        }
    }

    #endregion

    #region Disabled Settings
    [Browsable(false)]
    public override string Text { get; set; }

    [Browsable(false)]
    public override bool AutoSize { get; set; }

    [Browsable(false)]
    public new BorderStyle BorderStyle { get; set; }

    [Browsable(false)]
    public new FlatStyle FlatStyle { get; set; }

    [Browsable(false)]
    public new Image Image { get; set; }

    [Browsable(false)]
    public new Image ImageAlign { get; set; }

    [Browsable(false)]
    public new Image ImageIndex { get; set; }

    [Browsable(false)]
    public new Image ImageKey { get; set; }

    [Browsable(false)]
    public new Image ImageList { get; set; }

    [Browsable(false)]
    public new Size MinimumSize { get; set; }

    [Browsable(false)]
    public new DockStyle Dock { get; set; }

    [Browsable(false)]
    public new HorizontalAlignment TextAlign { get; set; }

    [Browsable(false)]
    public new bool UseWaitCursor { get; set; }
    #endregion

    #region Scroll Code

    protected override void OnMouseWheel(MouseEventArgs e)
    {
        base.OnMouseWheel(e);
        if (_Focus)
        {
            if (e.Delta > 0)
            {
                if (SIndex > 0)
                    SIndex--;
            }
            else
            {
                if ((SIndex + MaxCount) >= lst.Count) return;
                if (SIndex <= (lst.Count - 1))
                    SIndex++;
            }
            this.Refresh();
        }
    }
    

    protected override void OnMouseEnter(EventArgs e)
    {
        base.OnMouseEnter(e);
    }

    protected override void OnMouseLeave(EventArgs e)
    {
        base.OnMouseLeave(e);
        _Focus = false;
    }
    #endregion


    public bool ScrollAlwaysVisible { get; set; }
}


when write the class then click build solution and make new listbox in toolbox,

can help me to set Scroll??????
Questionserial port data read Pin
Member 1026351912-Dec-13 0:15
Member 1026351912-Dec-13 0:15 
AnswerRe: serial port data read Pin
Marco Bertschi12-Dec-13 1:22
protectorMarco Bertschi12-Dec-13 1:22 
QuestionHow to create an organizational chart in ASP with C# without api and HTML5 Pin
Member 1039478611-Dec-13 8:11
Member 1039478611-Dec-13 8:11 
AnswerRe: How to create an organizational chart in ASP with C# without api and HTML5 Pin
Dave Kreskowiak11-Dec-13 11:30
mveDave Kreskowiak11-Dec-13 11:30 
AnswerRe: How to create an organizational chart in ASP with C# without api and HTML5 Pin
Richard MacCutchan11-Dec-13 21:18
mveRichard MacCutchan11-Dec-13 21:18 
QuestionHow I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 4:57
delphix510-Dec-13 4:57 
AnswerRe: How I can find selected control on any window from mouse click c# Pin
Abhinav S10-Dec-13 5:09
Abhinav S10-Dec-13 5:09 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 5:16
delphix510-Dec-13 5:16 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
Dave Kreskowiak10-Dec-13 5:43
mveDave Kreskowiak10-Dec-13 5:43 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 6:55
delphix510-Dec-13 6:55 
AnswerRe: How I can find selected control on any window from mouse click c# Pin
Eddy Vluggen10-Dec-13 8:06
professionalEddy Vluggen10-Dec-13 8:06 
AnswerRe: How I can find selected control on any window from mouse click c# Pin
BillWoodruff10-Dec-13 5:52
professionalBillWoodruff10-Dec-13 5:52 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
delphix510-Dec-13 7:03
delphix510-Dec-13 7:03 
GeneralRe: How I can find selected control on any window from mouse click c# Pin
GuyThiebaut10-Dec-13 22:35
professionalGuyThiebaut10-Dec-13 22:35 
QuestionList<> VS Dictionary<,> Pin
HobbyProggy9-Dec-13 22:14
professionalHobbyProggy9-Dec-13 22:14 
AnswerRe: List<> VS Dictionary<,> Pin
Marco Bertschi9-Dec-13 22:24
protectorMarco Bertschi9-Dec-13 22:24 
AnswerRe: List<> VS Dictionary<,> Pin
Pete O'Hanlon9-Dec-13 22:59
subeditorPete O'Hanlon9-Dec-13 22:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.