(艹皿艹 ) 2020-03-21 20:17 采纳率: 0%
浏览 148

【求助】WTL中如何去除ComboBox白色的边框?

在combobox里响应了onpaint消息,但去除不了组合框的白色边框
图片说明

  • 写回答

1条回答 默认 最新

  • 码农阿豪@新空间代码工作室 Java领域优质创作者 2024-07-25 17:31
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    问题描述:在combobox中响应了onpaint消息,但不能去除组合框的白色边框。 解决方案:要去除combobox的白边框,可以在combobox的OnPaint方法中进行自定义绘制。下面是一个示例代码:
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    public class CustomComboBox : ComboBox
    {
        public CustomComboBox()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
            DrawMode = DrawMode.OwnerDrawFixed;
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            // 绘制背景
            e.Graphics.FillRectangle(new SolidBrush(BackColor), ClientRectangle);
            // 绘制文本
            StringFormat sf = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment = StringAlignment.Center
            };
            RectangleF rect = new RectangleF(2, 2, ClientRectangle.Width - 4, ClientRectangle.Height - 4);
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), rect, sf);
        }
    }
    

    使用上面的代码替换原来的ComboBox控件,即可自定义绘制combobox的外观,从而去除白色边框。 希望以上解决方案对您有所帮助。

    评论

报告相同问题?

悬赏问题

  • ¥15 求网页搭建平台会的联系我
  • ¥15 尼康光电绝对值编码器(相关搜索:绝对值|编码器)
  • ¥20 INCA标定工具ER亮红灯
  • ¥15 hive on spark
  • ¥15 星穹铁道中的ai自动战斗逻辑
  • ¥15 国产浪潮电脑跳转个别网页有问题
  • ¥15 SimpleHook 一下android fake模块的VIP日期
  • ¥15 如何在VBA中利用word的错词提示功能识别word文本中的错别字并标注
  • ¥15 jupyter notebook无法识别的空格,如何解决?(语言-python)
  • ¥15 自动回复评论的小插件