This is visual c# so I'm not sure if this thread should go here.
I am attempting to add a custom event to the event section of properties panel for my custom control. The problem is no event is being added to the panel for me to subscribe to.
I attempted to create the event with,
and then built the solution but still no event appeared in the panel.Code:public event System.EventHandler PositionChanged;
I downloaded the source code for this since it is from a book and the source code didn't have the a event handler for the event and the event wasn't in the event section of properties for the custom control.Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace LabelTextBox { public partial class ctlLabelTextbox : UserControl { public enum PositionEnum { Right, Below } private PositionEnum position = PositionEnum.Right; private int textboxMargin = 0; private string labelText = ""; public event System.EventHandler PositionChanged; public string LabelText { get { return labelCaption.Text; } set { labelCaption.Text = labelText = value; MoveControls(); } } public string TextboxText { get { return textBoxText.Text; } set { textBoxText.Text = value; } } public PositionEnum Position { get { return position; } set { position = value; MoveControls(); } } public int TextboxMargin { get { return textboxMargin; } set { textboxMargin = value; MoveControls(); if (PositionChanged != null) PositionChanged(this, new EventArgs()); } } public ctlLabelTextbox() { InitializeComponent(); } private void ctlLabelTextbox_Load(object sender, EventArgs e) { labelCaption.Text = labelText; Height = textBoxText.Height > labelCaption.Height ? textBoxText.Height : labelCaption.Height; MoveControls(); } private void ctlLabelTextbox_SizeChanged(object sender, EventArgs e) { MoveControls(); } private void MoveControls() { switch (position) { case PositionEnum.Below: textBoxText.Top = labelCaption.Bottom; textBoxText.Left = labelCaption.Left; textBoxText.Width = Width; Height = textBoxText.Height + labelCaption.Height; break; case PositionEnum.Right: textBoxText.Top = labelCaption.Top; if (textboxMargin == 0) { int width = Width - labelCaption.Width - 3; textBoxText.Left = labelCaption.Right + 3; textBoxText.Width = width; } else { textBoxText.Left = textboxMargin + labelCaption.Width; textBoxText.Width = Width - textBoxText.Left; } Height = textBoxText.Height > labelCaption.Height ? textBoxText.Height : labelCaption.Height; break; } } private void textBoxText_KeyDown(object sender, KeyEventArgs e) { OnKeyDown(e); } private void textBoxText_KeyPress(object sender, KeyPressEventArgs e) { OnKeyPress(e); } private void textBoxText_KeyUp(object sender, KeyEventArgs e) { OnKeyUp(e); } } }



LinkBack URL
About LinkBacks


