UserControl In windoes Application
how to create a user control in windows forms and how to give events to the controls used in usercontrol. How to communicate with the original application
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
kiran kumarRank #3,110 · 461 reputationPosted Feb 17, 2010, 5:46 AM EST
CHECK THE ANSWER IF IT HELPS YOU
Lalit MRank #1,186 · 1.5K reputationPosted Feb 16, 2010, 1:41 AM EST
http://www.akadia.com/services/dotnet_user_controls.html
srinivas137 reputationPosted Feb 16, 2010, 3:03 AM EST
but in my application iam adding n number of usercontrols and in my user control
I have 3 text Boxes and 1 button
and when i click on that button the total user control should delete
and i want to get the index or some tag value of the deleted user control
is there way to do plzzzzzzzzz help
thank you
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 6:46 AM EST
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace removectrls
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Controls.Remove(textBox1);
this.Controls.Remove(textBox2);
this.Controls.Remove(textBox3);
this.button1.Visible = false;
MessageBox.Show("you removed" +" " + textBox1.Name + " " + textBox2.Name + " " + textBox3.Name + "");
}
}
}
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 6:47 AM EST
srinivas137 reputationPosted Feb 16, 2010, 6:27 PM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 6:40 PM EST
i have set the button to be in invisible state after a click on the button..you can also remove that as i deleted textboxes...
you want to delete the controls which are loaded dynamically??
CHECK THE ANSWER IF IT HELPS YOU
srinivas137 reputationPosted Feb 16, 2010, 7:22 PM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 9:12 PM EST
herei am posting you a code which loads the controls dynamically(3 textboxe's)and upon a click on the button those things which are l oaded dynamically will be deleted specifying which things were actually deleted...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace dynamic_remo
{
public partial class Form1 : Form
{
TextBox[] text = new TextBox[3];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0,k=92; i <3; i++)
{
text[i] = new TextBox();
text[i].Name = "textbox"+i+"";
this.text[i].Size = new System.Drawing.Size(100, 20);
this.text[i].Text = "kkk the power";
this.text[i].Anchor = text[i].Anchor | AnchorStyles.Left;
this.text[i].Location = new System.Drawing.Point(29, (k*i)+46);
this.Controls.Add(text[i]);
}
this.button1.Click += new EventHandler(hi);
}
private void hi(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
this.Controls.Remove(text[i]);
}
this.Controls.Remove(button1)
string[] names = new string[3];
for (int j = 0; j < 3; j++)
{
names[j] = text[j].Name;
}
MessageBox.Show("you removed " + names[0] + " " + names[1] + " " + names[2] + " " +button1.name+" ");
}
}
}
mark the answer if it helps you
srinivas137 reputationPosted Feb 16, 2010, 9:52 PM EST
i added 5 custom control and when iam adding a custom control iam giving a Tag value to each control , when i click the delete button of certain custom control then that control should be removed and the remaining controls should shift to the deleted location
i think you got my problem hoping some help from you
thank you
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 11:06 PM EST
kiran kumarRank #3,110 · 461 reputationPosted Feb 16, 2010, 11:42 PM EST
hello srinivas i have grouped textboxes and executed this..check this if it suits your requirements...upon deleting a group previous group will come in that deleted position..i have taken as example of 3 groups here...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace groupdel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.button1.Click += new EventHandler(hi);
this.button2.Click += new EventHandler(button2_click);
this.button3.Click += new EventHandler(button3_Click);
}
private void hi(object sender, EventArgs e)
{
this.Controls.Remove(groupBox1);
this.groupBox2.Location = new System.Drawing.Point(29, 12);
this.groupBox3.Location = new Point(29, 83);
MessageBox.Show("you deleted textboxes " + groupBox1.Name + "");
}
private void button2_click(object sender, EventArgs e)
{
this.Controls.Remove(groupBox2);
this.groupBox3.Location = new Point(29, 83);
MessageBox.Show("you deleted textboxes under" + groupBox2.Name + "");
}
private void button3_Click(object sender, EventArgs e)
{
this.Controls.Remove(groupBox3);
MessageBox.Show("you deleted textboxes under " + groupBox2.Name + "");
}
}
}
CHECK THIS IF IT HELPED YOU
srinivas137 reputationPosted Feb 16, 2010, 11:53 PM EST
but your code helped me a lot now i got solution for my problem by using events to the custom control button and it returns the tagvalue of the custom control