Groovy / grails如何确定数据类型?(Groovy / grails how to determine a data type?)
在groovy中确定数据类型的最佳方法是什么?
如果它是一个日期等,我想格式化输出的方式不同
What is the best way to determine the data type in groovy?
I'd like to format the output differently if it's a date, etc.
原文:https://stackoverflow.com/questions/2060427
最满意答案
以下是几个选项:
简单的方法是在文本框之外创建一个标签 (在左边),使用这些字符。 (用户简单易懂)
创建一个第二个只读文本框以在开始时使用,将其设置为匹配输入,并将它们彼此对齐。 是的,你会得到一个像素线分割它们,但我认为这将增加用户体验,使其显而易见这不是搞砸(我会亲自选择这个选项)
如果您需要风格,您可以滚动自己的用户控件 ,使用面板,标签和文本框,并根据需要设置适当的边框样式。 (获得所需的确切样式的最佳方式)
第四个更烦人的方式是处理文本框本身的一个关键事件(如KeyDown )。 有了这个,你可以做许多检查,改变插入位置使其工作,但相信我,这将使你的头努力使其工作完美! (方式太多努力才能正确)
总而言之,我认为选项2是最好的。 当然,如果你使用WPF,你无疑会有更大的灵活性。
Here are a few options:
The easy way is to just create a label outside the text box (to the left) with those characters. (simple and easy to understand for the user)
Create a second readonly text box to use at the start, style it to match the input one and align them next to each other. Yes, you will get a single pixel line to split them both, but I think this will add to the user experience to make it obvious this is not for messing with (I would personally choose this option)
If you need the style you can roll your own user control that uses a panel, label and textbox with appropriate border styling set as needed. (best way to get the exact style you need)
The fourth, more annoying way, would be to handle one of the key events (such as KeyDown) on the textbox itself. With this you can do numerous checks and alter the caret position to make it work, but trust me this will do your head in trying to get it working perfectly! (way too much hard work to get right)
To summarise, I think option 2 is the best here. Of course if you were using WPF you would undoubtedly have a lot more flexibility in styling.
相关问答
更多-
官方名词是“提示横幅”。 这是另一种方法,只需继承TextBox即可完成工作。 向项目添加一个新类并粘贴以下所示的代码。 编译。 从工具箱的顶部放下新的控件并设置Cue属性。 您可以在设计器中获取Cue值的实时预览,并将其本地化为表单的“语言”属性。 许多爆炸非常小的钱,一个很好的示范Winforms的好的部分。 using System; using System.ComponentModel; using System.Windows.Forms; using System.Runtime.Intero ...
-
使用KeyDown事件( http://www.dotnetperls.com/keycode )。 private void textBox1_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) && textBox1.Text.Length == 7) { e.SuppressKeyPress = true; } } 验 ...
-
如何将WinForms TextBox的前几个字符设置为只读?(How to set the first few characters of a WinForms TextBox to Read-Only?)[2024-02-11]
以下是几个选项: 简单的方法是在文本框之外创建一个标签 (在左边),使用这些字符。 (用户简单易懂) 创建一个第二个只读文本框以在开始时使用,将其设置为匹配输入,并将它们彼此对齐。 是的,你会得到一个像素线分割它们,但我认为这将增加用户体验,使其显而易见这不是搞砸(我会亲自选择这个选项) 如果您需要风格,您可以滚动自己的用户控件 ,使用面板,标签和文本框,并根据需要设置适当的边框样式。 (获得所需的确切样式的最佳方式) 第四个更烦人的方式是处理文本框本身的一个关键事件(如KeyDown )。 有了这个,你可 ... -
在设置TextBox.Text之前,可以使用double.ToString()格式化字符串。 例如: double value = 0.00000000123; string s = value.ToString("#.###E00"); Console.WriteLine(s); 或者只是分配给TextBox.Text: textBox.Text = value.ToString("#.###E00");; You can use double.ToString() to format the st ...
-
@Hans您的问题和提示已经得到了回报。 进一步仔细研究发现,程序环境默认为不同的字体。 当我指定字体时,边距是相同的。 感谢您帮我找到答案。 @Hans Your questions and prompting have paid off. Further and closer examination has revealed that the program environments were defaulting to different fonts. When I specified the fon ...
-
与其他人发布的想法相同,将其放入textChanged事件中: Dim s As SizeF = TextRenderer.MeasureText(txt.Text, txt.Font, txt.ClientRectangle.Size, TextFormatFlags.WordBreak) txt.Height = CInt(s.Height) 你将需要某种最低高度,并可能指定一些填充,但这是行得通的。 Same kind of idea as others have posted, put this ...
-
尝试使用MaskedTextBox并将InsertKeyMode设置为InsertKeyMode.Overwrite。 MaskedTextBox box = ...; box.InsertKeyMode = InsertKeyMode.Overwrite; Try using a MaskedTextBox and set InsertKeyMode to InsertKeyMode.Overwrite. MaskedTextBox box = ...; box.InsertKeyMode = Inse ...
-
如何在Winforms中设置只读文本框的背景颜色?(How do I set the background color of a readonly textbox in Winforms?)[2024-03-03]
设置控件的Background属性。 Set the Background property of the control. -
只需将Microsoft Forms文本框控件添加到您的工具箱即可。 替代文字http://img262.imageshack.us/img262/2989/28550946.png Just add the Microsoft Forms textbox Control to your toolbox. alt text http://img262.imageshack.us/img262/2989/28550946.png
-
WinForms html textBox(WinForms html textBox)[2023-10-19]
我曾经使用过“HtmlTextbox for Windows.Forms”控制一段时间的应用程序。 它完美地满足了我需要完成的目标。 它是CodePlex上的开源软件。 它自2012年以来一直没有更新,但自WPF发布以来,WinForms再次没有太大变化。 尝试一下,希望它适合你。 https://winformhtmltextbox.codeplex.com/ I've used the "HtmlTextbox for Windows.Forms" control a while back for a ...