如何在文本框中添加两个按钮? [英] How to add two button to textbox?

查看:152
本文介绍了如何在文本框中添加两个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我正在尝试用右侧的两个按钮制作一个TextBox。

我该怎么办?

谢谢。



我的尝试:



protected override void OnLoad(EventArgs e){

var btn = new Button();

btn.Size = new Size(25,textBox1.ClientSize。高度+ 2);

btn.Location = new Point(textBox1.ClientSize.Width - btn.Width,-1);

btn.Cursor = Cursors.Default;

btn.Image = Properties.Resources.star;

textBox1.Controls.Add(btn);

//发送EM_SETMARGINS以防止文本从消失在按钮下面

SendMessage(textBox1.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);

解决方案

我这样做的方法是创建一个UserControl,其中包含一个文本框和两个按钮。

 ____________ __ __ 
|文本框|| B1 || B2 |
------------ - -

文本框的Anchor属性设置为Top,Left和Right,按钮有Anchor Top和Right 。



这样,文本框总是将按钮放在文本框右侧的相同位置 - 无论整个控件发生了什么。

添加一些属性来访问文本,设置按钮标题,以及一些事件来表示按钮已被点击,你就完成了。

我讨厌降价! :狂:[/编辑]


Hi.
I'm trying to make a TextBox with two button on the right side.
How do i do?
thank you.

What I have tried:

protected override void OnLoad(EventArgs e) {
var btn = new Button();
btn.Size = new Size(25, textBox1.ClientSize.Height + 2);
btn.Location = new Point(textBox1.ClientSize.Width - btn.Width, -1);
btn.Cursor = Cursors.Default;
btn.Image = Properties.Resources.star;
textBox1.Controls.Add(btn);
// Send EM_SETMARGINS to prevent text from disappearing underneath the button
SendMessage(textBox1.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);

解决方案

The way I would do it is to create a UserControl, which contains a textbox and two buttons.

 ____________  __  __
|  Text box  ||B1||B2|
 ------------  --  --

The textbox has it's Anchor property set to Top, Left, and Right, and the buttons have Anchor Top and Right.

That way, the textbox always has the buttons in the same position - to the right of the textbox - regardless of what happens to the control as a whole.
Add a few properties to access the text, set the button captions, and a few events to signal that the buttons have been clicked, and you are done.
[edit]I hate markdown! :mad:[/edit]


这篇关于如何在文本框中添加两个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆