英文:
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?
答案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属性获取行高度。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论