自定义了一个控件,要在这个自定义控件中写一些方法,在里面有个事件显示个panel,这个panel的位置要在自定义控件内的一个label位置。但是我定义的 int x = this.label1.Location.X;
int y = this.label1.Location.Y + this.label1.Height;
panel.Location = new Point(x, y);结果显示到父窗体中,就直接是0,0,也就是这个label1在自定义控件中的位置坐标。现在怎样,在这个自定义控件中,就能获取的到该自定义控件在父窗体的坐标呢,谢谢啦在线等待... ...
int y = this.label1.Location.Y + this.label1.Height;
panel.Location = new Point(x, y);结果显示到父窗体中,就直接是0,0,也就是这个label1在自定义控件中的位置坐标。现在怎样,在这个自定义控件中,就能获取的到该自定义控件在父窗体的坐标呢,谢谢啦在线等待... ...
解决方案 »
- 求教一个正则表达式...提取字符串内容的。应该很简单。谢谢!!
- 在异地机器建立文件夹!
- vs Dns.GetHostEntry Resolve 获得Aliases为空的问题
- 如何设置窗体控件的属性?
- DataGridView的列如何与数据源的列绑定?
- 高手们来看看啦 ComboBox 相关
- 我在招行下了个安全验证的控件,SQL企业管理器就登陆不了了,如何删除SSL安全验证?
- C#中能否在非托管C++程序传入的HWND所代表的窗口中创建C#控件阿。
- 请问高手,怎样取字符串所在的内存地址.
- 怎麼用一個變量調用幾個不同的類。
- PropertyGrid 控件事件栏的应用
- WebClient.DownloadFile下载exe文件和dll文件报404错误
这貌似不好吧,不符合mvc啊
如: public void UpdatePanelLocation()
{
int x = this.label1.Location.X;
int y = this.label1.Location.Y;
this.panel1.Location = new Point(x, y);
}然后在:
private void Form1_Load(object sender, EventArgs e)
{
this.userControl11.UpdatePanelLocation();
}
换this.Parent.Controls.Add(panel)就行了。
本来我还想换个新的属性用用,结果就成这了。
自定义空间中
public partial class TaskConnten : UserControl
{
public delegate void EventDelegate(object sender, EventArgs e); public event EventDelegate DeleConnten;
public TaskConnten()
{}
private void Coles_Paint(object sender, EventArgs e)
{
MessageBox.Show("你确定要删除该任务吗");
try
{
if (DeleConnten != null)
{
DeleConnten(this, new EventArgs());
}
}
catch(Exception x)
{
}
}
}窗体中
生窗体
public void ShowData()
{
TaskConnten tc = new TaskConnten(T,inter);
tc.DeleConnten += new TaskConnten.EventDelegate(DeleConnten); this.panel1.Controls.Add(tc);
tc.Top = (this.panel1.Controls.count-1) * tc.Size.Height;
tc.Show();
}
触发事件后执行的方法
public void DeleConnten(object sender,EventArgs e)
{
TaskConnten deleObjer = sender as TaskConnten;
this.panel1.Controls.Clear();
for (int i = 0; i < tcs.Count;i++ )
{
if (tcs[i] == deleObjer || tcs[i].IsDisposed)
{
tcs.Remove(tcs[i]);
deleObjer.Dispose();
//i = i - 1;
}
if (tcs.Count > 0)
{
this.panel1.Controls.Add(tcs[i]);
tcs[i].Top = i * tcs[i].Size.Height;
tcs[i].Show();
}
}
}