【发布时间】:2021-01-25 00:44:51
【问题描述】:
我对 C# 很陌生,有一个问题。我已经能够通过将它们的 FlatStyle 更改为“Flat”来更改按钮等的边框颜色。使用NumericUpDown,我无法更改平面样式。我希望仍然能够使用向上和向下箭头,因此仅使用其他东西来覆盖边缘是行不通的。这是我在代码中所做的简化版本:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace bordertest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
BackColor = Color.Black;
numericUpDown1.BackColor = Color.Red;
}
}
}
【问题讨论】:
-
顺便说一句,这个控件引发了画图事件,如果有人出于任何原因想要在没有继承的情况下实现相同的行为,他们可以处理画图事件并绘制边框;但是,作为通用解决方案和可重用解决方案,派生控件更有意义。
标签: c# .net winforms numericupdown