效果图:

TextBoxButton控件的开发实现

实现代码:

 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         }
View Code

相关文章:

  • 2022-02-17
  • 2021-08-14
  • 2021-11-17
  • 2021-09-21
  • 2022-12-23
  • 2021-12-14
猜你喜欢
  • 2021-12-11
  • 2022-01-07
  • 2022-12-23
  • 2021-07-04
  • 2021-06-15
  • 2022-12-23
  • 2022-02-12
相关资源
相似解决方案