답변
ToolStrip 및 ToolStripSplitButton 컨트롤을 사용하고 나 자신의 컨트롤을 만들어서 그림 상자에 포함 된 미소를 보여주는 패널을 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. C# 트레이 (msn 메신저와 유사)
- 2. WinForm C#
- 3. 문자열의 스마일 코드 대체하기
- 4. 어떻게 이미지 (스마일)
- 5. C#의 WinForm 질문
- 6. C++의 WinForm
- 7. Winform 및 threading (C#)
- 8. HTML에 스마일 삽입하기
- 9. CSS 스마일 얼굴
- 10. Infragistics UltraGrid C# winform
- 11. C# Winform/XNA Question
- 12. C# WinForm Menu Strip
- 13. C# WinForm 호출과 동시성
- 14. C# Generics 및 Winform
- 15. C# 콤보 상자 winform
- 16. C# Winform 이진 아이콘
- 17. C# Winform Datagrid CRUD
- 18. TabControl winform C#
- 19. C# 다른 형식의 WinForm?
- 20. C#에서 winform 인쇄
- 21. Winform (C#) 또는 WPF의 stretchableImageWithLeftCapWidth
- 22. winform 컨트롤 값 저장 C#
- 23. 구글에서와 같은 텍스트 박스 검색
- 24. sms 응용 프로그램에 스마일 추가
- 25. C# Winform ProgressBar 및 BackgroundWorker
- 26. ColdFusion에서 체크 박스 같은 이름
- 27. Gmail과 같은 jquery 체크 박스
- 28. 완전히 최대화 된 C# WinForm
- 29. C# Winform : Print ListView 내용
- 30. C# Winform 숨기기/표시 탭
"ImageSelected"이벤트와 함께 PictureBox Grid를 사용하여 새 양식을 정의해야한다고 생각합니다. – cansik
새 양식으로 할 경우 어떻게해야 기본 단추에 표시 할 수 있습니까? –
View = Tile 인 ListView가 닫습니다. OwnerDraw를 사용하면 정확하게 그걸 얻을 수 있습니다. –