views:

89

answers:

1

Hello, guys!

I wonder if there is a possibility to (visually and functionally) link two controls(components)? (.NET2)

Simplifying the things, I have two labels - one of them is the main label (it can be deplaced with the mouse) and an other - the description label - it needs to follow the main label on a specified distance.

Also, the description label should be able to respond to the events, like mouse click etc. Maybe there is a possibility to use a UserControl but between the labels I need to be a "transparent" space.

Thanks.

==EDIT 1==

I could also, instead of creating the second label control, just use a eternal toolTip. In this case i wonder about possibility of displaying it the Infinite time AND also possibility to detect the click on the tooltip.

Anyway, If I click on the label or tooltip, I will need to display to the user a TextBox control(instead of the tooltip or label), in order that it be able to Modify the displayed description (in fact displaying time)

== EDIT 2 ==

alt text

this is my "transperent" UserControl design

alt text

and this is my Form in running mode(user control "transparent" region covering a button).

this is the usercontrol's code:

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);
        }
    }
}

=================

* The description was a little simplified. In my real case I have a custom circular point component (: from Microsoft.VisualBasic.PowerPacks.OvalShape). The point represents a object in time position - in the linked label I need to specify the point's time. User will be able to modify the point's time by clicking on the time label.

+2  A: 

Create a User Control. A workaround for the transparency issue is outlined here.

Josh Stodola
ok, I evidenced the word *UserControl* in my post in **bold**.
serhio
So create one then, wise guy. It's exactly what you need.
Josh Stodola
Then you should consider addressing the underlying issue. **In bold**. http://social.msdn.microsoft.com/forums/en-US/winforms/thread/a9c78c36-0569-4339-a499-b8411c5bbffb/
Josh Stodola
Answer updated. The label interspace issue is the next problem to focus on. I'll see if I can find anything. One thing at a time :)
Josh Stodola
The invisibility solution does not work. See my edits. Also is problematic(impossible?) the click on the labels interspace. I can't override the HitTest() function of the UserControl.My labels moves on a drawn background. I can't make transparent the userControl background. If I click in the the space between two labels that superposes other labels, these back labels shoud respond also the the click events.
serhio