首页 \ 问答 \ WinForms文本框中的按钮(Button inside a winforms textbox)

WinForms文本框中的按钮(Button inside a winforms textbox)

winforms文本框是否有可以在框的结尾处生成嵌入式按钮的属性?

就像Chrome地址框上的收藏夹按钮一样:

在这里输入图像描述

我在一些Excel表格中也看到了类似下面的内容:

在这里输入图像描述


编辑

我跟着Hans Passant的答案加入了一个点击事件处理程序,它似乎可以正常工作:

    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");
    }

Do winforms textboxes have any properties that make an embedded button, at the end of the box, possible?

Something like the favorites button on the Chrome address box:

enter image description here

I've also seen something like the following in some Excel forms:

enter image description here


EDIT

I've followed Hans Passant's answer with the addition of a click event handler and it seem to work ok:

    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");
    }

原文:https://stackoverflow.com/questions/15868817
更新时间:2023-08-16 21:08

最满意答案

这个需要更改 shell分隔符为换行
在for循环之前修改IFS变量
IFS=$'\n' 

OLDIFS="$IFS"

for  i in `find . `

do
echo "$i"
done
IFS="$OLDIFS"

这样循环就会以换行作为单词分界.你的文件名如果出现换行,那就无能为力。
虽然linux 支持文件名包含特殊字符
但并不推荐,会导致别的脚本出错误。通常用下划线或短线代替空格。

还有一种用
find some|while read i
do
echo "$i"
done
用read i,每个循环读取一行,等价与用换行作为分隔符。

记得采纳

其他回答

你应该在一般模式,所以打不了空格,你按一下 i 键,就到了编辑模式,然后直接按空格键就行了。。。

相关问答

更多
  • linux ftp[2023-07-06]

    linux的系统特权帐户是root,可以使用sudo设置特权账号,可以针对某一账号设置一定的权限
  • linux试题!!![2022-03-29]

    一.基础命令: 1.linux系统文件类型:普通文件(-),目录(d),字符设备文件(c),块设备文件(b),符号链接文件(l),套接口文件(s)等。 2.linux的内核是linux操作系统的核心部分,它会定期地更新。每次更新都有一个版本号,这个版本号就是linux的内核版本。linux内核版本有两种:稳定版和开发版。linux内核版本号由三组数字组成。内核主版本.内核此版本(偶数表示稳定版本,奇数表示开发中版本).错误修补的次数。一般通过lsb_release -a,getconf LONG_BIT和u ...
  • 重定向能够实现Linux命令的输入输出与文件之间重定向,以及实现将多个命令组合起来实现更加强大的命令。这部分涉及到的比较多的命令主要有: cat:连接文件 sort:排序文本行 uniq:忽略或者报告重复行 wc:统计文件的行数、词数、字节数 grep:打印匹配制定模式的行 head:输出文件的头部 tail:输出文件的尾部 tee:从标准输入读,并往标准输出或者文件写 1. 重定向标准输出 使用>可以将本来出现在屏幕的标准输出信息重定向到一个文件中。 使用>>可以在实现重定向时不覆盖原有内容,而是在文件末 ...
  • Linux必学命令[2023-06-25]

    必学的嘛 有很多了,不过以我的实际使用的经验以下命令经常用到(括号里是常用的选项): 文件操作命令cd,ls( -l -d -a)简写ls-l = ll,mkidr (-p),rm (-rf),cp,mv,chmod,chown 文件查看命令cat,more,less,tail(-f),head,file 时间有关命令date(-s HH:MM:SS),ntpupdate,clock (-w) 用户有关命令useradd(-g -s),groupadd 文件系统有关命令:mount(-a -o),unmou ...
  • 你的问题太多,让人无法全面回答!每个问题都可以列个专题! 1,只要你想用他就可以被改成你想用的!(ps2的系统也是linux为核心的) 2,在服务器领域应用最为广泛! 3,在服务器领域最为多的就是web服务器这个词你可以搜索一下!(互联网帝国google的服务器所运行的操作系统就是以linux为核心的) 4,这个问题就不好说了太多了手机,pda,机顶盒等等 5,我不明白你这个问题问的是什么!?开发linux内核的工具?还是linux平台上的开发工具? ******补充 6,你的补充问题也够多的! ...
  • "\"在这里是一个转义字符,'xxxx\|xxxx'表示的意思是'xxxx|xxxx'。其中的“|”是一个特殊字符,有“或”的功能,所以需要进行转义。
  • cd ~/ ::cd /home/user/ 在user目录下搜索目录 cd ::cd ./ 代表在当前路径搜索目录 cd / ::代表进入根目录
  • 这个需要更改 shell分隔符为换行 在for循环之前修改IFS变量 IFS=$'\n' OLDIFS="$IFS" for i in `find . ` do echo "$i" done IFS="$OLDIFS" 这样循环就会以换行作为单词分界.你的文件名如果出现换行,那就无能为力。 虽然linux 支持文件名包含特殊字符 但并不推荐,会导致别的脚本出错误。通常用下划线或短线代替空格。 还有一种用 find some|while read i do echo "$i" done 用read i,每个循 ...
  • 行为是正确的,并且“按预期”。 for file in $InputDir'*'表示assign "/home/XXX/*" to $file (注意引号)。 既然你引用了星号,它现在不会被执行。 当shell看到echo $file ,它首先展开变量,然后进行glob扩展。 所以在第一步之后,它就会看到 echo /home/XXX/* 在全局扩展之后,它会看到: echo /home/XXX/fileA /home/XXX/fileB 直到现在,它才会执行命令。 在第二种情况下,在执行for之前扩展 ...
  • 如果你可以使用bash ,则不需要使用awk : read和shell参数扩展可以结合起来解决你的问题 : while read -r name rest; do # Drop the '= ' part, if present. [[ $rest == '= '* ]] && value=${rest:2} || value=$rest # $value now contains the line's value, # but *including* any enclosing ' cha ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。