سلام ب همه میخواستم توی کلاس زیر این قابلیت ها رو بزارم ممنون میشم دوستان راهنمایی کنن
1- برای رویداد KeyPress چجوری کد بنویسم؟
2- میخوام مقداری رو هم تعیین کنم مثلا اگه true گرفت اون کار توی رویداد KeyPress انجام بشه
3- مقدار عددی و یا حرفو و کاراکتر دریافت کنه و بتونه به یه رویدادی بفرسته مثلا تو یه متغییر بریزه
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Tmp
{
class PS_Txt:TextBox
{
private string nulltext = "";
public string NullText
{
get
{
return nulltext;
}
set
{
if (Text.Equals(nulltext)) Text = "";
nulltext = value;
}
}
private void SetNullText()
{
if (string.IsNullOrEmpty(Text))
{
Text = nulltext;
}
}
protected override void OnEnter(EventArgs e)
{
base.OnEnter(e);
if (Text == nulltext)
{
Text = "";
}
}
protected override void OnLeave(EventArgs e)
{
base.OnLeave(e);
SetNullText();
}
}
}
4- میخواستم بوردر تکست باکس هم تغییر بدم و من اومدم از این کد استفاده کردم ولی این یوزر کنترل هست و تمام خاصیت های تکست باکس رو نمیاره و من بخوام تو نمونه بالا استفاده کنم نمیتونم اگه بخوام این رو تو نمونه کدی که بالا هست وارد کنم به چه شکلی هست؟
public class BorderedTextBox : UserControl
{
TextBox textBox;
public BorderedTextBox()
{
textBox = new TextBox
{
BorderStyle = BorderStyle.FixedSingle,
Location = new Point(-1, -1),
Anchor = AnchorStyles.Top | AnchorStyles.Bottom |
AnchorStyles.Left | AnchorStyles.Right
};
Control container = new ContainerControl()
{
Dock = DockStyle.Fill,
Padding = new Padding(-1)
};
container.Controls.Add(textBox);
this.Controls.Add(container);
DefaultBorderColor = SystemColors.ControlDark;
FocusedBorderColor = Color.Red;
BackColor = DefaultBorderColor;
Padding = new Padding(1);
Size = textBox.Size;
}
public Color DefaultBorderColor { get; set; }
public Color FocusedBorderColor { get; set; }
public override string Text
{
get { return textBox.Text; }
set { textBox.Text = value; }
}
protected override void SetBoundsCore(int x, int y,
int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, textBox.PreferredHeight, specified);
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// BorderedTextBox
//
this.Name = "BorderedTextBox";
this.Size = new System.Drawing.Size(108, 27);
this.ResumeLayout(false);
}
}