| re: User Control -> disappear when form.Click
Ah, now I understand. I think a small tweak to what I posted before
does exactly what you want, except with a composite control rather than
a subclass of the linklabel control. I'll give the subclass a try and
post back. This is the composite control version (not pretty to look
at, but basically functional):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Form_Click_Test
{
public partial class UserControl1 : UserControl
{
bool _IsVisible = false;
public delegate void OnClickHandler(object sender, System.EventArgs e);
public event OnClickHandler ClickHandler;
public UserControl1()
{
InitializeComponent();
_IsVisible = false;
this.dataGridView1.Visible = _IsVisible;
DataTable dt = new DataTable();
dt.Columns.Add(\"ID\", System.Type.GetType(\"System.Int32\"));
dt.Columns.Add(\"Desc\", System.Type.GetType(\"System.String\"));
DataRow dr = dt.NewRow();
dr[\"ID\"] = 1; dr[\"Desc\"] = \"Row 1\";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[\"ID\"] = 2; dr[\"Desc\"] = \"Row 2\";
dt.Rows.Add(dr);
this.dataGridView1.DataSource = dt;
}
public bool IsGridVisible
{
get { return _IsVisible; }
set
{
_IsVisible = value;
this.dataGridView1.Visible = _IsVisible;
}
}
private void panel1_Click(object sender, EventArgs e)
{
if (ClickHandler != null)
ClickHandler(this, e);
}
private void linkLabel1_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
{
this.IsGridVisible = true;
}
private void dataGridView1_CellMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{
this.textBox1.Text = dataGridView1[e.ColumnIndex,
e.RowIndex].Value.ToString();
this.IsGridVisible = false;
}
private void UserControl1_Click(object sender, EventArgs e)
{
this.IsGridVisible = false;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Form_Click_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Click(object sender, EventArgs e)
{
this.userControl11.IsGridVisible = false;
}
private void userControl11_Click(object sender, EventArgs e)
{
this.userControl11.IsGridVisible = true;
}
}
}
--
breitak67 |