Penggunaan ToolStripControlHost Class

C Sharp - Windows Control , Posted at : Feb/21/2007   [Click this link to download code sample]
1580 Views   2 Comments

ToolStripControlHost dapat digunakan untuk "host" control pada sebuah ToolStripItem lewat component ContextMenu. Misalnya ketika sebuah control TextBox di klik kanan akan tampil DateTimePicker control yang bisa digunakan untuk memilih tanggal. Jadi ToolStripControlHost akan "menampung" kontrol yang kita tambahkan, kemudian ToolStripControlHost tersebut ditambahkan pada ToolStripItemCollection ContextMenunya...Berikut contohnya :

1. Buat sebuah windows application project template. Design form seperti ini :

2. Tambahkan code dibawah ini pada class Form nya :

   1:  //Deklarasi variabel :
   2:  private DateTimePicker Kalenderku;
   3:  private DateTimePickerFormat FormatKalenderku =
   4:      DateTimePickerFormat.Long;
   5:  private ToolStripControlHost hostToolStripnya;
   6:   
   7:  //Prosedur (Handler) yang dieksekusi ketika Calendar diklik
   8:  private void KetikaKalendarkuDiKlik(object pengirim,
   9:      EventArgs eventnya)
  10:  {
  11:   textBox1.Text = Kalenderku.Value.ToString();
  12:  }
  13:   
  14:  //event handler Form Load
  15:  private void Form1_Load(object sender, EventArgs e)
  16:  {
  17:   Kalenderku = new DateTimePicker();
  18:   Kalenderku.Format = FormatKalenderku;
  19:   Kalenderku.ValueChanged += new EventHandler(
  20:       KetikaKalendarkuDiKlik);
  21:   hostToolStripnya = new ToolStripControlHost(Kalenderku);
  22:   contextMenuStripnya.Items.Add(hostToolStripnya);
  23:  }

here is the screen shot :


[Comments]
geeks  Aug/28/2009 01:20:11 :
Nice post, excelent code specially for beginners Anyway, thanks for the post
Rully  Aug/28/2009 07:56:08 :
You're welcome :)

[Write your comment]
Name (required)
Email (required-will not published)
 
Comment

ycxd
Input code above below (Case Sensitive) :
About Me 
Rully Yulian MF
My Name is Rully Yulian Muhammad Firmansyah. I am an IT Trainer, IT Consultant and Application Developer spesializing in Microsoft .NET technology and SQL Server database. I live in Bandung, Indonesia. My hobby is to play Guitar. [Read More...]
Top Download 
Bagaimana caranya menginstal database ketika deploying sebuah aplikasi? : Downloaded 3175 times  
Change Group,Sort Order, Filtering By Date in Crystal Reports : Downloaded 2592 times  
Mapping Hak Akses User Pada MenuStrip Sampai Control Button : Downloaded 2180 times  
Simple Voice Engine Application With Sound Player Class... : Downloaded 2127 times  
WinForms DataGrid Paging With SqlDataAdapter : Downloaded 1806 times  
Article Category 
Links 
Award 
Certifications 
MOS 2007
MCAS
MCT
MCPD
MCTS
MCAD.NET
ASP.NET Brainbench
Native Enterprise 
Follow Me 
Facebook   LinkedIn   Twitter
Syndication 
Hosted By 
Native Enterprise News