如何在c#中制作笑脸面板 [英] How To Make smiley panel in c#

查看:167
本文介绍了如何在c#中制作笑脸面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个RichTextBox,用于Jabber聊天室,我得到所有用户和自己的聊天。



我想在我的项目中嵌入表情符号。我想要一个包含所有表情符号的面板。当点击任何笑脸时必须发送。



喜欢:)显示笑脸:@是生气的脸



它们必须以richtextbox的形式显示,也不是像笑脸那样的符号:)



如何在c#中执行此操作。



我在某个网站上找到了这个代码。



 public partial class Form1:Form 
{
public Form1()
{
InitializeComponent();

this.SuspendLayout();

列表<位图> Smiles = new List< Bitmap>(); //添加图片

ToolStripSplitButton _toolStripSplitButton = new ToolStripSplitButton();
_toolStripSplitButton.Size = new Size(23,23);
//_toolStripSplitButton.Image = myImage; //添加stripSplitButton的图像

ToolStrip _toolStrip = new ToolStrip();
_toolStrip.Size = new Size(ClientSize.Width,10);
_toolStrip.Location = new Point(0,this.ClientSize.Height - _toolStrip.Height);
_toolStrip.BackColor = Color.LightGray;
_toolStrip.Dock = DockStyle.Bottom;
_toolStrip.Items.AddRange(new ToolStripItem [] {_toolStripSplitButton});

SmileBox smilebox =新的SmileBox(新点(_toolStripSplitButton.Bounds.Location.X,_toolStrip.Location.Y - 18),6);
smilebox.Visible = false;

Controls.Add(smilebox);

foreach(微笑中的位图bmp)
smilebox.AddItem(bmp);

_toolStripSplitButton.Click + = new EventHandler(delegate(object sender,EventArgs e)
{
smilebox.Visible = true;
});

点击+ = new EventHandler(委托(对象发件人,EventArgs e)
{
smilebox.Visible = false;
});

this.Controls.Add(_toolStrip);
this.ResumeLayout();
}

void Form1_Click(对象发送者,EventArgs e)
{
抛出新的NotImplementedException();
}
}

class SmileBox:Panel
{
public List< Item>物品
{
get;
设定;
}

尺寸_ItemSpace = new尺寸(20,20);
Point _ItemLocation;
int _rowelements = 0;

public SmileBox(Point Location,int RowElements)
{
BackColor = Color.LightGray;

Height = _ItemSpace.Height;
Width = _ItemSpace.Width * RowElements;

this.Location = new Point(Location.X,Location.Y - Height);
_ItemLocation = new Point(0,0);
_rowelements = RowElements;
}

int count = 1;
public void AddItem(Bitmap Image)
{
Item item = new Item(_ItemSpace,_ItemLocation,Image);

if(_ItemLocation.X + _ItemSpace.Width> = Width)
_ItemLocation = new Point(0,_ItemLocation.Y);
else
_ItemLocation = new Point(_ItemLocation.X + _ItemSpace.Width,_ItemLocation.Y);

if(count == _rowelements)
{
_ItemLocation = new Point(_ItemLocation.X,_ItemLocation.Y + _ItemSpace.Height);
高度+ = _ItemSpace.Height;
Location = new Point(Location.X,Location.Y - _ItemSpace.Height);

count = 0;
}

count ++;

Controls.Add(item);
}
}

class项目:PictureBox
{
int _BorderSpace = 2;

公共物品(尺寸大小,点位置,位图图像)
{
this.Size = new Size(Size.Width - 2 * _BorderSpace,Size.Height - 2 * _BorderSpace);
this.Location = new Point(Location.X + _BorderSpace,Location.Y + _BorderSpace);
this.Image = new Bitmap(Image,this.ClientSize);

点击+ = new EventHandler(委托人(对象发件人,EventArgs e)
{
//这里当用户点击微笑时你想做什么
});

MouseEnter + = new EventHandler(delegate(object sender,EventArgs e)
{
Focus();
Invalidate();
});
}

protected override void OnMouseDown(MouseEventArgs e)
{
this.Focus();
base.OnMouseDown(e);
}

protected override void OnEnter(EventArgs e)
{
this.Invalidate();
base.OnEnter(e);
}

protected override void OnLeave(EventArgs e)
{
this.Invalidate();
base.OnLeave(e);
}

protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);

if(this.Focused)
{
ClientRectangle.Inflate(-1,-1);
Rectangle rect = ClientRectangle;
ControlPaint.DrawFocusRectangle(pe.Graphics,rect);
}
}
}









上面的代码对我不起作用,因为它太乱了,无法理解。



提前谢谢。

解决方案

I have a RichTextBox in my project which is for Jabber chatroom where i get all chat of users and maself.

I want to embed smileys in my project.i want a panel containing all smileys.and when click any smiley it must be sent.

like :) displays smile face :@ is angry face

They must be shown in richtextbox also in form of smiley not symbols like :)

How can i do this in c#.

I had found this code on some website.

public partial class Form1 : Form
{
public Form1()
{
    InitializeComponent();

    this.SuspendLayout();

    List<Bitmap> Smiles = new List<Bitmap>(); //Add images

    ToolStripSplitButton _toolStripSplitButton = new ToolStripSplitButton();
    _toolStripSplitButton.Size = new Size(23, 23);
    //_toolStripSplitButton.Image = myImage; //Add the image of the stripSplitButton

    ToolStrip _toolStrip = new ToolStrip();
    _toolStrip.Size = new Size(ClientSize.Width, 10);
    _toolStrip.Location = new Point(0, this.ClientSize.Height - _toolStrip.Height);
    _toolStrip.BackColor = Color.LightGray;
    _toolStrip.Dock = DockStyle.Bottom;
    _toolStrip.Items.AddRange(new ToolStripItem[] { _toolStripSplitButton });

    SmileBox smilebox = new SmileBox(new Point(_toolStripSplitButton.Bounds.Location.X, _toolStrip.Location.Y - 18), 6);
    smilebox.Visible = false;

    Controls.Add(smilebox);

    foreach (Bitmap bmp in Smiles)
        smilebox.AddItem(bmp);

    _toolStripSplitButton.Click += new EventHandler(delegate(object sender, EventArgs e)
    {
        smilebox.Visible = true;
    });

    Click += new EventHandler(delegate(object sender, EventArgs e)
    {
        smilebox.Visible = false;
    });

    this.Controls.Add(_toolStrip);
    this.ResumeLayout();
}

void Form1_Click(object sender, EventArgs e)
{
    throw new NotImplementedException();
}
}

 class SmileBox : Panel
{
    public List<Item> Items
{
    get;
    set;
}

Size _ItemSpace = new Size(20, 20);
Point _ItemLocation;
int _rowelements = 0;

    public SmileBox(Point Location, int RowElements)
{
    BackColor = Color.LightGray;

    Height = _ItemSpace.Height;
    Width = _ItemSpace.Width * RowElements;

    this.Location = new Point(Location.X, Location.Y - Height);
    _ItemLocation = new Point(0, 0);
    _rowelements = RowElements;
}

int count = 1;
public void AddItem(Bitmap Image)
{
    Item item = new Item(_ItemSpace, _ItemLocation, Image);

    if (_ItemLocation.X + _ItemSpace.Width >= Width)
        _ItemLocation = new Point(0, _ItemLocation.Y);
    else
        _ItemLocation = new Point(_ItemLocation.X + _ItemSpace.Width, _ItemLocation.Y);

    if (count == _rowelements)
    {
        _ItemLocation = new Point(_ItemLocation.X, _ItemLocation.Y + _ItemSpace.Height);
        Height += _ItemSpace.Height;
        Location = new Point(Location.X, Location.Y - _ItemSpace.Height);

        count = 0;
    }

    count++;

    Controls.Add(item);
}
}

 class Item : PictureBox
{
int _BorderSpace = 2;

public Item(Size Size, Point Location, Bitmap Image)
{
    this.Size = new Size(Size.Width - 2 * _BorderSpace, Size.Height - 2 * _BorderSpace);
    this.Location = new Point(Location.X + _BorderSpace, Location.Y + _BorderSpace);
    this.Image = new Bitmap(Image, this.ClientSize);

    Click += new EventHandler(delegate(object sender, EventArgs e)
    {
        //Here what do you want to do when the user click on the smile
    });

    MouseEnter += new EventHandler(delegate(object sender, EventArgs e)
    {
        Focus();
        Invalidate();
    });
}

protected override void OnMouseDown(MouseEventArgs e)
{
    this.Focus();
    base.OnMouseDown(e);
}

protected override void OnEnter(EventArgs e)
{
    this.Invalidate();
    base.OnEnter(e);
}

protected override void OnLeave(EventArgs e)
{
    this.Invalidate();
    base.OnLeave(e);
}

protected override void OnPaint(PaintEventArgs pe)
{
    base.OnPaint(pe);

    if (this.Focused)
    {
        ClientRectangle.Inflate(-1, -1);
        Rectangle rect = ClientRectangle;
        ControlPaint.DrawFocusRectangle(pe.Graphics, rect);
    }
}
}





The above code is not working for me as its too messy to understand.

Thanks in advance.

解决方案

这篇关于如何在c#中制作笑脸面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆