Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Creating a Name seperator Custom Control using C#

0 vue

Publié le

Creating a Name seperator Custom Control using C#

Publié dans : Formation
  • Soyez le premier à commenter

Creating a Name seperator Custom Control using C#

  1. 1. Name.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace custctrl { public partial class Name :TextBox { public Name() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); } private String _FirstName; private String _LastName; public String GetFirstName() { UpdateNames(); return _FirstName; } public String GetLastName() { UpdateNames(); return _LastName; }
  2. 2. private void UpdateNames() { int commapos; int spacepos; string name; name = Text; commapos =Text.IndexOf(","); spacepos =Text.IndexOf(""); string[] flname; if(commapos!=-1) { flname = Text.Split(','); _FirstName = flname[0]; _LastName = flname[1]; } else if(spacepos!=-1) { flname = Text.Split(' '); _FirstName = flname[0]; _LastName = flname[1]; } else { throw new InvalidOperationException(); } return; } private void TxtName_TextChanged(object sender, EventArgs e) { } } }
  3. 3. Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace custctrl { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //LblLast.Text = name1.Text; LblFirst.Text = name1.GetFirstName(); LblLast.Text = name1.GetLastName(); } } }
  4. 4. Output

×