如何在C# .NET中自动设置组合框的高度?

huangapple go评论79阅读模式
英文:

How to automatically set height of Combo Box in C# .NET?

问题

我正在尝试在我的C# .NET Framework 4.7.2应用程序中,像下面图片所示,使用ComboBox填充TabView中的单元格,但我无法弄清楚如何水平填充它。你能帮助我吗?

问题的图片描述见此处

英文:

I'm trying to fill cell in my TabView in C# .NET Framework 4.7.2 app with ComboBox as shown on the image below, but I can't figure how to fill it horizontally. Can you help me?

combo shown here (image description of a problem)

答案1

得分: 0

ComboBox的高度由其字体大小决定。要更改高度,您必须通过将“DrawMode”属性设置为“OwnerDrawnVariable”来自己绘制完整的ComboBox。但这也意味着您现在负责ComboBox的所有内容,并引入了更多复杂性。

请参考Microsoft Learn文档中的ComboBox.DrawMode属性,网址为https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.drawmode?view=netframework-4.7.2,其中包含执行此操作的代码示例。

要在手动绘制ComboBox后自动在Table Layout Panel上执行此操作,您需要在每次更新行高度时更新ComboBox的高度。您可以从TableLayoutPanel.RowStyles属性获取行高度。

相关链接:c# - 如何设置ComboBox的高度?

英文:

ComboBox height is decided by the font size of it. To change the height you have to draw the complete ComboBox yourself by setting the DrawMode property to OwnerDrawnVariable. But this also means that you are now in-charge of everything of that ComboBox and introduces far more complexity.

Please refer to the Microsoft Learn Documentation on ComboBox.DrawMode property at https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.drawmode?view=netframework-4.7.2 which contains the code example for doing it.

To do it automatically on Table Layout Panel after manually drawing the ComboBox you'll have to update the height each time the row height is updated. You can get the row height from TableLayoutPanel.RowStyles property.

Related: c# - How do I set the height of a ComboBox?

huangapple
  • 本文由 发表于 2023年7月10日 22:40:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定