回答
我會使用ToolStrip和ToolStripSplitButton控制,然後我會創建自己的控件inhrited形式的面板顯示包含在圖片框中的微笑何時會發生點擊ToolStripSplitButton。
我試圖模擬你想要做的行爲。因此,這裏是一些代碼:
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);
}
}
}
這裏是什麼創建這個代碼的快照:
而當你過了一個微笑:
而且在這裏你可以點擊單個項目。
當我點擊它,微笑框不開放? –
對不起,我編輯了我的代碼...現在它應該可以工作。 –
對不起,但它還沒有工作 –
創建一個用戶控件或一個新窗體(如果你想浮動的東西),每個表情符號的圖片框。每當用戶點擊一個圖片框(點擊事件)時,您可以註冊點擊並將笑臉粘貼到適當的位置。
實際上,您可以創建一個新的圖片框類,它繼承了內置圖片框的所有內容,並添加一個公共字符串,其中包含笑臉代碼。您在事件中獲取發件人對象,因此您只需在Click事件的函數中讀取該字符串即可。
- 1. 臉譜「我喜歡」問題
- 2. 定製Facebook喜歡盒子
- 3. 移動笑臉C#
- 4. 臉書,如何獲得更多關於喜歡的信息?
- 5. 更改臉部的喜歡按鈕
- 6. Facebook喜歡的按鈕和顏色盒
- 7. Rails根據臉書排序喜歡
- 8. 流體臉譜「喜歡」按鈕?
- 9. 通過臉書訂購喜歡(PHP)
- 10. Java笑臉替代字符串笑臉
- 11. 是否有可能轉移個人網頁臉書喜歡到網站臉譜喜歡
- 12. 我喜歡在臉書上使用圖表api的對象
- 13. 喜歡在使用restfb的臉上留言
- 14. Facebook喜歡信使開始腳本
- 15. 在Facebook上顯示喜歡的喜歡數量喜歡按鈕
- 16. 使用「喜歡」
- 17. PHP - 用笑臉
- 18. Java:笑臉
- 19. CSS笑臉
- 20. SQL不喜歡和喜歡
- 21. mySQL喜歡,但不喜歡
- 22. 喜歡但不喜歡
- 23. 在我喜歡的盒子上強制使用白色背景
- 24. Android使用笑臉鍵盤
- 25. 笑臉的DOS字符?
- 26. 喜歡和喜歡的按鈕爲Drupal
- 27. 喜歡/不喜歡Firebase的交易?
- 28. Instagram的喜歡使用JavaScript
- 29. 喜歡使用PHP
- 30. JAutodoc喜歡插件爲C + +
我認爲你必須爲它定義一個新的Form,其上有一個PictureBox Grid和一個「ImageSelected」事件。 – cansik
如果我使用新形式,我如何在主按鈕上顯示它? –
具有View = Tile的ListView已關閉。你需要OwnerDraw才能得到它。 –