cuốn sách gpt4 ai đã làm

c# - 在组合框中对齐文本

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 08:50:19 25 4
mua khóa gpt4 Nike

我想在组合框中对齐我的文本,以便它显示在组合框的中心告诉我如何做到这一点你也可以看到当组合框处于焦点时它周围有一个默认边框我如何删除那边界也请解决我的两个问题谢谢

câu trả lời hay nhất

本文将为您提供帮助:http://blog.michaelgillson.org/2010/05/18/left-right-center-where-do-you-align/

诀窍是将 ComboBox 的 DrawMode 属性设置为 OwnerDrawFixed 并订阅其事件 DrawItem.

您的事件应包含以下代码:

// Allow Combo Box to center aligned
private void cbxDesign_DrawItem(object sender, DrawItemEventArgs e)
{
// By using Sender, one method could handle multiple ComboBoxes
ComboBox cbx = sender as ComboBox;
if (cbx != null)
{
// Always draw the background
e.DrawBackground();

// Drawing one of the items?
if (e.Index >= 0)
{
// Set the string alignment. Choices are Center, Near and Far
StringFormat sf = new StringFormat();
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;

// Set the Brush to ComboBox ForeColor to maintain any ComboBox color settings
// Assumes Brush is solid
Brush brush = new SolidBrush(cbx.ForeColor);

// If drawing highlighted selection, change brush
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
brush = SystemBrushes.HighlightText;

// Draw the string
e.Graphics.DrawString(cbx.Items[e.Index].ToString(), cbx.Font, brush, e.Bounds, sf);
}
}
}

ComboBox-Preview

要右对齐项目,您只需将 StringAlignment.Center Thay thế bằng StringAlignment.Far.

关于c# - 在组合框中对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11817062/

25 4 0
Bài viết khuyến nghị: android - 应用内计费或许可?
Bài viết khuyến nghị: c# - 在 C# 中使用或不使用 'this' 限定符
Bài viết khuyến nghị: android - NFC Reader <-> Android通信和Android监听器
Bài viết khuyến nghị: c# - 学习.NET
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress