Hello evrybody,
I wanted some help regarding windows form in C# .. I have a label control where i need to put a linkbutton control inside the label control dynamically ,I am able to place a link button but not at the required position inside the label control.. I hav some script written in label contols text field part and in that scripts there are some keywords which are to be replaced with linkbutton im able to find those keywords and replace those keywords with linkbutton but those linkbutton could not be placed in the in the required position thats the problem.... my linkbuttons overlap the text part of label control.

Hope somebody could help me with this....
If my question looks to long or difficult to undrstand please let me know...

Thank you

If I understand what you want to do, it's actually pretty easy. But you need to play some string parsing tricks:

using System;
using System.Windows.Forms;

namespace InannaRocks {
    public class MyProgram {
        public static void Main()
        {
            Application.Run(new MyForm());
        }
    }

    class MyForm: Form {
        FlowLayoutPanel _container = new FlowLayoutPanel();
        LinkLabel _link = new LinkLabel();
        ComboBox _picker = new ComboBox();

        public MyForm()
        {
            SuspendLayout();

            // Fit the form to the contents
            AutoSize = true;
            AutoSizeMode = AutoSizeMode.GrowAndShrink;

            // Make the flow pretty
            _container.AutoSize = true;

            // Initialize the link label
            _link.Parent = _container;
            _link.AutoSize = true;
            _link.Text = "Test link label for gopan";

            // Initialize the combo box
            _picker.Parent = _container;
            _picker.Items.Add("Test");
            _picker.Items.Add("link");
            _picker.Items.Add("label");
            _picker.Items.Add("for");
            _picker.Items.Add("gopan");
            _picker.SelectedIndexChanged += pickerOnSelect;

            // Apply the flow to the form
            Controls.Add(_container);

            ResumeLayout();
        }

        private void pickerOnSelect(object sender, EventArgs e)
        {
            // For notational convenience
            string text = _link.Text;

            // Find the start and length of a whitespace delimited word
            int start = text.IndexOf(_picker.SelectedItem as string);
            int end = start;

            while (end < text.Length && !Char.IsWhiteSpace(text[end]))
                ++end;

            // Match the link area to the word's location
            _link.LinkArea = new LinkArea(start, end - start);
        }
    }
}

Hello Inanna,
Thanks a lot Inanna for the code.. but i didnot find "FlowLayoutPanel" control in VS 2003 i found it in VS 2005 and the project i am currently working are all under VS2003. but still the code you gave was useful..
Thanks a lot once again.

with regards
Lakshmi Priya Gopan

but i didnot find "FlowLayoutPanel" control in VS 2003

It's new in .NET 2.0, but you don't really need it for the method I was showing. It just saved me the effort of making the form look pretty by hand. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.