首页 \ 问答 \ Groovy / grails如何确定数据类型?(Groovy / grails how to determine a data type?)

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
更新时间:2021-11-22 13:11

最满意答案

以下是几个选项:

  1. 简单的方法是在文本框之外创建一个标签 (在左边),使用这些字符。 (用户简单易懂)

  2. 创建一个第二个只读文本框以在开始时使用,将其设置为匹配输入,并将它们彼此对齐。 是的,你会得到一个像素线分割它们,但我认为这将增加用户体验,使其显而易见这不是搞砸(我会亲自选择这个选项)

  3. 如果您需要风格,您可以滚动自己的用户控件 ,使用面板,标签和文本框,并根据需要设置适当的边框样式。 (获得所需的确切样式的最佳方式)

  4. 第四个更烦人的方式是处理文本框本身的一个关键事件(如KeyDown )。 有了这个,你可以做许多检查,改变插入位置使其工作,但相信我,这将使你的头努力使其工作完美! (方式太多努力才能正确)

总而言之,我认为选项2是最好的。 当然,如果你使用WPF,你无疑会有更大的灵活性。


Here are a few options:

  1. 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)

  2. 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)

  3. 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)

  4. 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; } } 验 ...
  • 以下是几个选项: 简单的方法是在文本框之外创建一个标签 (在左边),使用这些字符。 (用户简单易懂) 创建一个第二个只读文本框以在开始时使用,将其设置为匹配输入,并将它们彼此对齐。 是的,你会得到一个像素线分割它们,但我认为这将增加用户体验,使其显而易见这不是搞砸(我会亲自选择这个选项) 如果您需要风格,您可以滚动自己的用户控件 ,使用面板,标签和文本框,并根据需要设置适当的边框样式。 (获得所需的确切样式的最佳方式) 第四个更烦人的方式是处理文本框本身的一个关键事件(如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 ...
  • 设置控件的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
  • 我曾经使用过“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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)