Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何根据WinForms中的切换状态在切换按钮上绘制加号/减号 公共部分类表单1:表单 { 复选框文本复选框; 公共表格1() { 初始化组件(); checkBox=新的CheckBoxExt(); this.Controls.Add(复选框); } } 公共类CheckBoxExt:CheckBox { 公共CheckBoxExt() { 该尺寸=新尺寸(20,20); 该位置=新点(200200); this.Appearance=Appearance.Button; } 受保护的覆盖无效OnPaint(PaintEventArgs e) { 基础漆(e); var point=此.PointToScreen(新点(0,0)); e、 绘图线(新笔(ColorTranslator.FromHtml(“#666666”),2),新点(点X+5,点Y+10),新点(点X+15,点Y+10)); 如果(选中此项) e、 绘图线(新笔(ColorTranslator.FromHtml(“#666666”),2),新点(点X+10,点Y+5),新点(点X+10,点Y+15)); } /// ///删除控件上的焦点虚线边框的步骤 /// 受保护的覆盖布尔显示焦点 { 得到 { 返回false; } } }_Winforms_Togglebutton - Fatal编程技术网

如何根据WinForms中的切换状态在切换按钮上绘制加号/减号 公共部分类表单1:表单 { 复选框文本复选框; 公共表格1() { 初始化组件(); checkBox=新的CheckBoxExt(); this.Controls.Add(复选框); } } 公共类CheckBoxExt:CheckBox { 公共CheckBoxExt() { 该尺寸=新尺寸(20,20); 该位置=新点(200200); this.Appearance=Appearance.Button; } 受保护的覆盖无效OnPaint(PaintEventArgs e) { 基础漆(e); var point=此.PointToScreen(新点(0,0)); e、 绘图线(新笔(ColorTranslator.FromHtml(“#666666”),2),新点(点X+5,点Y+10),新点(点X+15,点Y+10)); 如果(选中此项) e、 绘图线(新笔(ColorTranslator.FromHtml(“#666666”),2),新点(点X+10,点Y+5),新点(点X+10,点Y+15)); } /// ///删除控件上的焦点虚线边框的步骤 /// 受保护的覆盖布尔显示焦点 { 得到 { 返回false; } } }

如何根据WinForms中的切换状态在切换按钮上绘制加号/减号 公共部分类表单1:表单 { 复选框文本复选框; 公共表格1() { 初始化组件(); checkBox=新的CheckBoxExt(); this.Controls.Add(复选框); } } 公共类CheckBoxExt:CheckBox { 公共CheckBoxExt() { 该尺寸=新尺寸(20,20); 该位置=新点(200200); this.Appearance=Appearance.Button; } 受保护的覆盖无效OnPaint(PaintEventArgs e) { 基础漆(e); var point=此.PointToScreen(新点(0,0)); e、 绘图线(新笔(ColorTranslator.FromHtml(“#666666”),2),新点(点X+5,点Y+10),新点(点X+15,点Y+10)); 如果(选中此项) e、 绘图线(新笔(ColorTranslator.FromHtml(“#666666”),2),新点(点X+10,点Y+5),新点(点X+10,点Y+15)); } /// ///删除控件上的焦点虚线边框的步骤 /// 受保护的覆盖布尔显示焦点 { 得到 { 返回false; } } },winforms,togglebutton,Winforms,Togglebutton,这是我的代码,我自定义了复选框,并将其外观设置为按钮,以便它将充当切换按钮 我需要画一条小的水平线,它将在按钮上显示为负号,并画一条小的水平线和垂直线,它将显示为加号按钮。因此,它需要切换,如果它处于选中状态,则需要显示加号,如果未选中,则需要通过切换按钮显示减号 提前感谢我将使用一个图像列表控件,并分别用所需分辨率的加号和减号图像填充它 控件的BackgroundImage属性可用于设置“+”和“-”图像 另外,不要忘记注册控件的CheckedChanged事件,以切换控件的Backgroun

这是我的代码,我自定义了复选框,并将其外观设置为按钮,以便它将充当切换按钮

我需要画一条小的水平线,它将在按钮上显示为负号,并画一条小的水平线和垂直线,它将显示为加号按钮。因此,它需要切换,如果它处于选中状态,则需要显示加号,如果未选中,则需要通过切换按钮显示减号


提前感谢

我将使用一个
图像列表
控件,并分别用所需分辨率的加号和减号图像填充它

控件的
BackgroundImage
属性可用于设置“+”和“-”图像

另外,不要忘记注册控件的
CheckedChanged
事件,以切换控件的
BackgroundImage

像这样的例子-

public partial class Form1 : Form
{
    CheckBoxExt checkBox;
    public Form1()
    {
        InitializeComponent();
        checkBox = new CheckBoxExt();
        this.Controls.Add(checkBox);
    }
}
public class CheckBoxExt : CheckBox
{
    public CheckBoxExt()
    {
        this.Size = new Size(20, 20);
        this.Location = new Point(200, 200);
        this.Appearance = Appearance.Button;
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        var point = this.PointToScreen(new Point(0, 0));
        e.Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#666666"), 2), new Point(point.X + 5, point.Y + 10), new Point(point.X + 15, point.Y + 10));
        if (this.Checked)
            e.Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#666666"), 2), new Point(point.X + 10, point.Y + 5), new Point(point.X + 10, point.Y + 15));
    }
    /// <summary>
    /// to remove the focus dotted border over the control
    /// </summary>
    protected override bool ShowFocusCues
    {
        get
        {
            return false;
        }
    }
}

我将使用
imageList
控件,并分别用所需分辨率的加号和减号图像填充它

控件的
BackgroundImage
属性可用于设置“+”和“-”图像

另外,不要忘记注册控件的
CheckedChanged
事件,以切换控件的
BackgroundImage

像这样的例子-

public partial class Form1 : Form
{
    CheckBoxExt checkBox;
    public Form1()
    {
        InitializeComponent();
        checkBox = new CheckBoxExt();
        this.Controls.Add(checkBox);
    }
}
public class CheckBoxExt : CheckBox
{
    public CheckBoxExt()
    {
        this.Size = new Size(20, 20);
        this.Location = new Point(200, 200);
        this.Appearance = Appearance.Button;
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        var point = this.PointToScreen(new Point(0, 0));
        e.Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#666666"), 2), new Point(point.X + 5, point.Y + 10), new Point(point.X + 15, point.Y + 10));
        if (this.Checked)
            e.Graphics.DrawLine(new Pen(ColorTranslator.FromHtml("#666666"), 2), new Point(point.X + 10, point.Y + 5), new Point(point.X + 10, point.Y + 15));
    }
    /// <summary>
    /// to remove the focus dotted border over the control
    /// </summary>
    protected override bool ShowFocusCues
    {
        get
        {
            return false;
        }
    }
}

你的问题是什么?PointToScreen()错误,请删除它。你的问题是什么?PointToScreen()错误,请删除它。