resizing icon image inside control dynamic isn’t working when resizing the height. how to make the icon to resize smaller with the control?

when i drag the control a custom slider to the form1 designer and then resize the slider control on the height if i resize it bigger it’s working as expected and the gear icon png is also resize and getting bigger with the slider.

but if i resize the slider control to be smaller on the height at some point the gear icon stop resizing and get overlap on the slider value 4.

the gear icon is on the slider value when changing the slider control size on the height to be smaller.

How to make that even if resizing the slider control more down on the height the gear icon will keep the ratio and will get also smaller ?

at the top:

the top of the code:

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Screen_Recorder
{

    public class CustomSlider : Control
    {
        private float _radius;
        private PointF _thumbPos;
        private SizeF _barSize;
        private PointF _barPos;
        private Icon settingsIcon;
        private Rectangle iconArea;

        public event EventHandler ValueChanged;

        public CustomSlider()
        {
            InitializeSettingsIcon();
            DoubleBuffered = true;
            _startsFromZero = true;  // Set the initial state to false
            Min = _startsFromZero ? 0.0f : 1.0f;  // Set Min based on _startsFromZero
            Max = _startsFromZero ? 4.0f : 5.0f;  // Set Max based on _startsFromZero
            Value = Min;  // Start with the minimum value
            UseIntegerValues = true;  // Set to true if you need integer values
            ShowTickLabels = true;  // Set to true to show labels

            // Load your settings icon
            this.Resize += CustomControlWithSettings_Resize;
            this.MouseClick += CustomControlWithSettings_MouseClick;
        }

the method that init the gear icon:

private void InitializeSettingsIcon()
{
    // Convert the PNG image from resources to an icon
    using (Bitmap bmp = new Bitmap(Properties.Resources.icons8_gear_50))
    {
        settingsIcon = Icon.FromHandle(bmp.GetHicon());
    }

    // Define the initial area for the icon (top-right corner)
    iconArea = new Rectangle(this.Width - 20, 0, 20, 20);
}

the OnPaint event code

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

    // Dynamic sizing of the icon based on control size
    int iconSize = Math.Max(20, this.Height / 5); // Example: icon size is 20 or 20% of height
    iconArea = new Rectangle(this.Width - iconSize - 5, 5, iconSize, iconSize); // 5 pixels padding

    // Draw the track
    e.Graphics.FillRectangle(Brushes.DimGray, _barPos.X, _barPos.Y, _barSize.Width, _barSize.Height);

    // Draw the filled part of the track
    e.Graphics.FillRectangle(Brushes.Red, _barPos.X, _barPos.Y, _thumbPos.X - _barPos.X, _barSize.Height);

    // Draw the thumb
    e.Graphics.FillCircle(Brushes.White, _thumbPos.X, _thumbPos.Y, _radius);
    e.Graphics.FillCircle(Brushes.Red, _thumbPos.X, _thumbPos.Y, ThumbSize * _radius);

    // Draw ticks
    DrawTicks(e.Graphics);

    // Draw the settings icon at the dynamic position and size
    if (settingsIcon != null)
    {
        e.Graphics.DrawIcon(settingsIcon, iconArea);
    }
}

other events that i’m not sure if needed. the whole code is bit longer.
the problem is that everything in the code is connected , the gear icon with the control.

protected override void OnResize(EventArgs e)
{
    base.OnResize(e);
    RecalculateParameters();
}

protected override void OnMouseMove(MouseEventArgs e)
{
    if (iconArea.Contains(e.Location))
    {
        // Possibly change cursor to indicate clickable area
        this.Cursor = Cursors.Hand;
    }
    else
    {
        this.Cursor = Cursors.Default;
        if (e.Button == MouseButtons.Left)
        {
            float newValue = ((e.X - _barPos.X) / _barSize.Width) * (Max - Min) + Min;
            Value = newValue;  // Update value while moving
        }
    }
}

protected override void OnMouseDown(MouseEventArgs e)
{
    if (!iconArea.Contains(e.Location))
    {
        base.OnMouseDown(e);
        float newValue = ((e.X - _barPos.X) / _barSize.Width) * (Max - Min) + Min;
        Value = newValue;  // Set value based on click position
    }
    else
    {
        OpenSettingsForm();  // Open settings form when icon is clicked
    }
}

protected override void OnMouseUp(MouseEventArgs e)
{
    base.OnMouseUp(e);
}

private void CustomControlWithSettings_Resize(object sender, EventArgs e)
{
    // Keep the icon in the top right corner
    iconArea = new Rectangle(this.Width - 20, 0, 20, 20);
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật