我想知道是否有可能(在视觉上和功能上)链接两个控件(组件)? (.NET2)将两个控件链接到一个
简化事情,我有两个标签 - 其中一个是主标签(可以用鼠标替换)和另一个 - 描述标签 - 它需要跟随主标签指定的距离。
此外,描述标签应该能够应对事件,如鼠标点击等 也许有使用用户控件的可能性,但标签之间,我需要成为一个“透明”的空间。
谢谢。
==编辑1 ==
我也,而不是创建第二个标签控件,只需使用一个永恒的工具提示。在这种情况下,我想知道显示无限时间的可能性,以及检测工具提示上的点击的可能性。
无论如何,如果我点击标签或工具提示,我需要向用户显示文本框控件(而不是工具提示或标签),以便它能够修改显示的描述(在事实显示时间)
== EDIT 2 ==
alt text http://lh4.ggpht.com/_1TPOP7DzY1E/Sy9Mk8-Z-xI/AAAAAAAACzo/-5huzSd59j4/s800/UserControl.png
这是我的 “透明单位” 用户控件设计
这是我的窗体在运行模式(用户控件“透明”区域覆盖按钮)。
这是用户控件的代码:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsControlLibrary1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;//WS_EX_TRANSPARENT
return cp;
}
}
private int opacity;
public int Opacity
{
get { return opacity; }
set
{
opacity = value;
this.InvalidateEx();
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
Color bk = Color.FromArgb(Opacity, this.BackColor);
e.Graphics.FillRectangle(new SolidBrush(bk), e.ClipRectangle);
}
protected void InvalidateEx()
{
if (Parent == null)
return;
Rectangle rc = new Rectangle(this.Location, this.Size);
Parent.Invalidate(rc, true);
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Location = this.Location + (Size)e.Location;
}
}
Point cursorDownPoint = Point.Empty;
private void label1_MouseDown(object sender, MouseEventArgs e)
{
cursorDownPoint = label1.PointToScreen(e.Location);
}
}
}
=================
*的描述有点简单化。在我的真实情况下,我有一个自定义的圆点组件(:来自Microsoft.VisualBasic.PowerPacks.OvalShape)。该点表示时间位置上的对象 - 在链接的标签中,我需要指定点的时间。用户将能够通过点击时间标签来修改点的时间。
对编辑2的回应:您是否将Opacity设置为零? – 2009-12-21 14:09:10
@Josh:是的...它默认为0。我也把它设置为5,但这并没有改变,但背景颜色的细微差别。 – serhio 2009-12-21 15:18:33