Le caselle di testo winforms hanno proprietà che rendono possibile un pulsante incorporato, alla fine della casella?Pulsante all'interno di una casella di testo winforms
Qualcosa come il pulsante Preferiti sulla barra degli indirizzi di Chrome:
Ho visto anche qualcosa di simile al seguente in alcune forme di Excel:
EDIT
ho seguito la risposta di Hans Passant con l'aggiunta di un gestore di eventi click e sembra funzionare bene:
protected override void OnLoad(EventArgs e) {
var btn = new Button();
btn.Size = new Size(25, textBoxFolder.ClientSize.Height + 2);
btn.Location = new Point(textBoxFolder.ClientSize.Width - btn.Width, -1);
btn.Cursor = Cursors.Default;
btn.Image = Properties.Resources.arrow_diagright;
btn.Click += btn_Click;
textBoxFolder.Controls.Add(btn);
// Send EM_SETMARGINS to prevent text from disappearing underneath the button
SendMessage(textBoxFolder.Handle, 0xd3, (IntPtr)2, (IntPtr)(btn.Width << 16));
base.OnLoad(e);
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
private void btn_Click(object sender, EventArgs e) {
MessageBox.Show("hello world");
}
@Highcore, sei un pony senza troppe pretese. Aggiungi il tag [winforms] ai tag ignorati, non voglio più vedere i tuoi wpf rants. –
@HighCore Ho notato a voi prima la stessa cosa che Hans sta dicendo. Consiglio vivamente di evitare semplicemente le domande di WinForms da ora in poi. –
@HansPassant .... Sono appena tornato dal congedo e sto recuperando le domande - sembra che voi brave persone lo abbiate spaventato! – whytheq