Panel에서 파생 된 사용자 정의 컨트롤을 만들었습니다. 디자이너가 포커스를 잃을 때만 내 컨트롤이 다시 그려지는 것을 제외하면 모든 것이 잘 작동합니다. 내가 무엇이 누락 되었습니까? 이 포커스를 잃었을 전에 여기 디자이너에서 사용자 지정 컨트롤을 업데이트하는 방법은 무엇입니까?
는이 xPanel1 내부 LABEL1를 이동 한 후 촬영 인쇄 화면입니다 CustomControl.csusing System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Picwing
{
public partial class xPanel : Panel
{
private SizeF textSize;
public xPanel() {
InitializeComponent();
}
[Browsable(true)]
public override string Text {
get { return base.Text; }
set { base.Text = value; }
}
protected override void OnPaint(PaintEventArgs pe) {
base.OnPaint(pe);
textSize = pe.Graphics.MeasureString(Text, Font);
pe.Graphics.DrawRectangle(new Pen(ForeColor, 1), pe.ClipRectangle.X, pe.ClipRectangle.Y + textSize.Height/2, pe.ClipRectangle.Width - 1, pe.ClipRectangle.Height - textSize.Height/2 - 1);
pe.Graphics.FillRectangle(new SolidBrush(BackColor), 5, 0, textSize.Width, textSize.Height);
pe.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), pe.ClipRectangle.X + 6, pe.ClipRectangle.Y);
}
}
}
좀 걸릴 수 있습니다? –
통제 코드를 게시하는 것을 잊었습니다. –
'+ = "을 사용하여 OnPaint 이벤트를 등록 했습니까? – jdweng