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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
kiran kumarPosted Feb 17, 2010, 10:46 AM
CHECK THE ANSWER IF IT HELPS YOU
srinivasPosted Feb 17, 2010, 4:53 AM
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
kiran kumarPosted Feb 17, 2010, 4:42 AM
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
kiran kumarPosted Feb 17, 2010, 4:06 AM
srinivasPosted Feb 17, 2010, 2:52 AM
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 kumarPosted Feb 17, 2010, 2:12 AM
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
srinivasPosted Feb 17, 2010, 12:22 AM
kiran kumarPosted Feb 16, 2010, 11:40 PM
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
srinivasPosted Feb 16, 2010, 11:27 PM
kiran kumarPosted Feb 16, 2010, 11:47 AM
kiran kumarPosted Feb 16, 2010, 11:46 AM
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 + "");
}
}
}
srinivasPosted Feb 16, 2010, 8:03 AM
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
Lalit MPosted Feb 16, 2010, 6:41 AM
http://www.akadia.com/services/dotnet_user_controls.html