我想知道是否有可能(在視覺上和功能上)鏈接兩個控件(組件)? (.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