C#实现类似QQ的弹起面板

2009年4月27日星期一

C#实现类似QQ的弹起面板

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using System.Threading;
using System.Collections;

namespace client
{
    public class IconShow : Panel
    {
        public ValueButton button;
        private Label label;
        private string MyString;
        public string STRING
        {
            get { return MyString; }
            set { MyString = value; }
        }
        public IconShow(int w, int h, string content, string ImagePath)
        {
            this.Width = w;
            this.Height = h;
            button = new ValueButton();
            label = new Label();
            //

            button.Location = new Point(0, 0);
            button.Width = w;
            button.Height = w;
            if (!string.IsNullOrEmpty(ImagePath))
            {
                button.Image = Image.FromFile(ImagePath, true);
            }
            //

            label.Location = new Point(0, w + 10);
            label.Width = w;
            label.TextAlign = ContentAlignment.TopCenter;
            if (!string.IsNullOrEmpty(content))
            {
                label.Text = content;
                button.STRING = content;
            }
            this.Controls.Add(button);
            this.Controls.Add(label);
        }
    }

    public class ValueButton : Button
    {
        private int MyValue;
        private string MyString;
        public int VALUE
        {
            get { return MyValue; }
            set { MyValue = value; }
        }
        public string STRING
        {
            get { return MyString; }
            set { MyString = value; }
        }
    }

    public class FrameItem : Panel
    {
        public ValueButton button;
        public SortedList<int, IconShow> IconList = null;
        private int number = 0;
        public FrameItem(int h, int w, string content)
        {
            button = new ValueButton();
            button.Width = w;
            button.Text = content;
            button.Location = new Point(0, 0);
            this.Controls.Add(button);
            Height = h;
            Width = w;
            IconList = new SortedList<int, IconShow>();
            //this.scro

        }

        public void SetSize(int h, int w)
        {
            Height = h;
            Width = w;
        }

        public void AddToList(int h, int w, string content, string ImagePath)
        {
            IconShow ics = new IconShow(w, h, content, ImagePath);
            IconList.Add(number, ics);
            number++;
        }

        public void HideButton()
        {
            for (int i = 0; i < IconList.Count; i++)
            {
                IconList[i].Hide();
            }
        }
        public void ShowButton()
        {
            for (int i = 0; i < IconList.Count; i++)
            {
                IconList[i].Show();
            }
        }
        public void AddToControl()
        {
            int h = Height;
            int w = Width;
            int x = 10;
            int y = 30;
            for (int i = 0; i < IconList.Count; i++)
            {
                if (x + 5 + IconList[i].Width >= Width)
                {
                    x = 10;
                    y += IconList[i].Height + 5;
                }
                IconList[i].Location = new Point(x, y);
                this.Controls.Add(IconList[i]);
                x += IconList[i].Width + 5;
            }
        }
    }
    //左侧控制栏

    public class LeftFrame : Panel
    {
        private SortedList<int, FrameItem> ItemFiList = null;
        private int ItemHeight = 20;
        private int ItemWidth;
        private int LastHeight = 0;
        //

        private int ItemNumber = 0;
        public LeftFrame(int h, int w)
        {
            this.Dock = DockStyle.Fill;
            this.Height = h;
            this.Width = w;
            ItemWidth = w;
            this.BackColor = Color.White;
            ItemFiList = new SortedList<int, FrameItem>();
        }

        public void AddToControl()
        {
            int x = 0;
            int showH = Height - (21 * ItemFiList.Count + 19);
            for (int i = ItemFiList.Count - 1; i >= 0; i--)
            {
                ItemFiList[i].SetSize(showH, Width);
                ItemFiList[i].Location = new Point(x, 21 * i);
                ItemFiList[i].button.Click += new System.EventHandler(buttont_click);
                this.Controls.Add(ItemFiList[i]);
            }
        }

        public void AddToList(FrameItem fi)
        {
            fi.button.VALUE = ItemNumber;
            ItemFiList.Add(ItemNumber, fi);
            ItemNumber++;
        }

        private void buttont_click(object sender, EventArgs e)
        {
            ValueButton bt = (ValueButton)sender;
            int ck = bt.VALUE;
            int up = 0;
            int down = this.Height - ItemHeight - 1;
            for (int i = 0; i < ck; i++, up += 21)
            {
                //ItemFiList[i].SetSize(20, Width);

                ItemFiList[i].Location = new Point(0, up);
                ItemFiList[i].AutoScroll = false;
            }
            //

            ItemFiList[ck].Location = new Point(0, up);
            ItemFiList[ck].SetSize(Height - LastHeight, Width);
            ItemFiList[ck].AutoScroll = true;
            //

            for (int i = ItemFiList.Count - 1; i > ck; i--)
            {
                ItemFiList[i].Location = new Point(0, down);
                ItemFiList[i].AutoScroll = false;
                //ItemFiList[i].SetSize(20, Width);

                down = down - ItemHeight - 1;
            }
        }
    }
}


0 评论:

发表评论