效果图:
实现代码:
1 public TextBoxButton() 2 { 3 _button = new Button 4 { 5 ForeColor = System.Drawing.SystemColors.GrayText, 6 Name = "button1", 7 Padding = new System.Windows.Forms.Padding(3, 1, 0, 0), 8 Text = "…", 9 UseVisualStyleBackColor = true, 10 Size = new System.Drawing.Size(20, 21), 11 Dock = DockStyle.Right 12 }; 13 14 this._button.SizeChanged += (o, e) => OnResize(e); 15 this._button.MouseMove += (o, e) => { this.Cursor = Cursors.Default; }; 16 this.Controls.Add(_button); 17 } 18 19 protected override void OnResize(EventArgs e) 20 { 21 base.OnResize(e); 22 _button.Size = new Size(_button.Width, this.ClientSize.Height + 2); 23 _button.Location = new Point(this.ClientSize.Width - _button.Width, -1); 24 // Send EM_SETMARGINS to prevent text from disappearing underneath the button 25 SendMessage(this.Handle, 0xd3, (IntPtr)2, (IntPtr)(_button.Width << 16)); 26 }