Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to create Textbox with ellipse button Pin
Ravi Bhavnani18-Mar-14 6:33
professionalRavi Bhavnani18-Mar-14 6:33 
AnswerRe: How to create Textbox with ellipse button Pin
Ravi Bhavnani18-Mar-14 5:42
professionalRavi Bhavnani18-Mar-14 5:42 
GeneralRe: How to create Textbox with ellipse button Pin
ahmed_one18-Mar-14 5:51
ahmed_one18-Mar-14 5:51 
GeneralRe: How to create Textbox with ellipse button Pin
Ravi Bhavnani18-Mar-14 6:06
professionalRavi Bhavnani18-Mar-14 6:06 
AnswerMSDN solution Pin
Ravi Bhavnani18-Mar-14 6:08
professionalRavi Bhavnani18-Mar-14 6:08 
AnswerRe: How to create Textbox with ellipse button Pin
BillWoodruff18-Mar-14 6:01
professionalBillWoodruff18-Mar-14 6:01 
GeneralRe: How to create Textbox with ellipse button Pin
ahmed_one18-Mar-14 6:18
ahmed_one18-Mar-14 6:18 
GeneralRe: How to create Textbox with ellipse button Pin
BillWoodruff18-Mar-14 7:00
professionalBillWoodruff18-Mar-14 7:00 
I have no idea if this is usable in a DataGridView in place of the TextBox normally used in a TextBox Column, but it was fun to write. Once you get a feeling for how easy it is to make new Controls (UserControls), or sub-class existing Controls (make Components), you can develop hybrids for special purposes very easily. The "craft" in it is getting the alignments and re-sizing right.
C#
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace March17_StateTracking
{
    public partial class TBEllipse : TextBox
    {
        // necessary to define this in Component scope
        // for MouseHover and MouseLeave EventHandlers
        // to work properly
        private readonly Label tLabel;

        // expose the Label for external use
        public Label TheLabel { set; get; }

        public TBEllipse()
        {
            InitializeComponent();

            tLabel = new Label();
            TheLabel = tLabel;

            tLabel.Text = "…";

            tLabel.FlatStyle = FlatStyle.Flat;
            tLabel.BorderStyle = BorderStyle.None;
            tLabel.BackColor = Color.Gainsboro;
            tLabel.TextAlign = ContentAlignment.TopRight;
            tLabel.Margin = new Padding(0, 0, 0, 0);
            tLabel.AutoSize = true;

            Controls.Add(tLabel);
            tLabel.Left = Width - tLabel.Width;
            tLabel.Show();
            tLabel.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;

            tLabel.MouseClick += tLabel_MouseClick;
            tLabel.MouseHover += tLabel_MouseHover;
        }

        public TBEllipse(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        private void tLabel_MouseClick(object sender, MouseEventArgs e)
        {
            tLabel.BackColor = Color.Gainsboro;
        }

        private void tLabel_MouseHover(object sender, EventArgs e)
        {
            tLabel.BackColor = Color.Lime;
        }
    }
}
After creating an instance of this ... you can test it by drag-dropping it from the ToolBox to a Form after it is compiled ... you can subscribe to the Click Event of the Label. Here's an example of creating an instance in code and adding it to a Form's ControlCollection when a Button on the Form is clicked:
C#
private void TestTBEllipse_Click(object sender, EventArgs e)
{
    TBEllipse testTBEllipse = new TBEllipse();
    testTBEllipse.Text = "some text";
    this.Controls.Add(testTBEllipse);
    testTBEllipse.Location = new Point(400,400);
    testTBEllipse.TheLabel.Click += TheLabel_Click;
}

private void TheLabel_Click(object sender, EventArgs e)
{
    MessageBox.Show("ellipsis label clicked");
}

“The best hope is that one of these days the Ground will get disgusted enough just to walk away ~ leaving people with nothing more to stand ON than what they have so bloody well stood FOR up to now.” Kenneth Patchen, Poet

AnswerRe: How to create Textbox with ellipse button Pin
Alan N18-Mar-14 7:36
Alan N18-Mar-14 7:36 
GeneralRe: How to create Textbox with ellipse button Pin
ahmed_one18-Mar-14 18:12
ahmed_one18-Mar-14 18:12 
QuestionCalculating the area of a self intersecting polygon Pin
Member 1067580817-Mar-14 23:38
Member 1067580817-Mar-14 23:38 
SuggestionRe: Calculating the area of a self intersecting polygon Pin
Richard MacCutchan18-Mar-14 0:47
mveRichard MacCutchan18-Mar-14 0:47 
QuestionHow to solve a non linear Equation is Visual studio 2012/C# Pin
Nadish Anand17-Mar-14 15:06
Nadish Anand17-Mar-14 15:06 
AnswerRe: How to solve a non linear Equation is Visual studio 2012/C# Pin
Bernhard Hiller17-Mar-14 22:14
Bernhard Hiller17-Mar-14 22:14 
AnswerRe: How to solve a non linear Equation is Visual studio 2012/C# Pin
Matt T Heffron18-Mar-14 8:30
professionalMatt T Heffron18-Mar-14 8:30 
QuestionWhat is used to identify a Generic Type Parameter? Pin
Jörgen Andersson16-Mar-14 10:33
professionalJörgen Andersson16-Mar-14 10:33 
AnswerRe: What is used to identify a Generic Type Parameter? Pin
BillWoodruff16-Mar-14 20:01
professionalBillWoodruff16-Mar-14 20:01 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Jörgen Andersson16-Mar-14 20:59
professionalJörgen Andersson16-Mar-14 20:59 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Pete O'Hanlon17-Mar-14 12:06
mvePete O'Hanlon17-Mar-14 12:06 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
BillWoodruff17-Mar-14 18:51
professionalBillWoodruff17-Mar-14 18:51 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Pete O'Hanlon17-Mar-14 21:15
mvePete O'Hanlon17-Mar-14 21:15 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Jörgen Andersson17-Mar-14 21:53
professionalJörgen Andersson17-Mar-14 21:53 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Pete O'Hanlon17-Mar-14 22:42
mvePete O'Hanlon17-Mar-14 22:42 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Jörgen Andersson17-Mar-14 23:43
professionalJörgen Andersson17-Mar-14 23:43 
GeneralRe: What is used to identify a Generic Type Parameter? Pin
Pete O'Hanlon18-Mar-14 0:50
mvePete O'Hanlon18-Mar-14 0:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.