首页 > 代码库 > 运行时手动伸缩控件大小
运行时手动伸缩控件大小
public partial class PanelX : UserControl
{
private Point oldXY;
//private static PanelX instance;
//public DataRow dr = null;
public delegate void RowSelectedEventHandler(object sender, EventArgs e);
public event RowSelectedEventHandler RowSelected;
//.. 必须将它设置为最前 一般这样 this.controls.add (panelx);
public PanelX()
{
InitializeComponent();
//this.BringToFront();
}
//public static PanelX Instance
//{
// get
// {
// if (instance == null)
// {
// instance = new PanelX();
// }
// return instance;
// }
//}
public new void Show()
{
if (!this.Visible)
this.Visible = true;
}
private void btnClose_Click(object sender, EventArgs e)
{
if (this.Visible)
this.Visible = false;
}
private void labResize_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
oldXY = new Point(e.X, e.Y);
}
private void labResize_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Width += e.X - oldXY.X;
this.Height += e.Y - oldXY.Y;
}
}
private void PanelX_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
oldXY = new Point(e.X, e.Y);
}
private void PanelX_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - oldXY.X;
this.Top += e.Y - oldXY.Y;
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
oldXY = new Point(e.X, e.Y);
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Left += e.X - oldXY.X;
this.Top += e.Y - oldXY.Y;
}
}
private void dgvDetail_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
DataRow dr = (dgvDetail.SelectedRows[0].DataBoundItem as DataRowView).Row;
if (RowSelected != null)
RowSelected(dr, null);
this.Dispose();
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData =http://www.mamicode.com/= Keys.Enter && > {
DataRow dr = (dgvDetail.SelectedRows[0].DataBoundItem as DataRowView).Row;
if (RowSelected != null)
RowSelected(dr, null);
this.Dispose();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}