我在C#程序中有以下代码.
DateTime dateForButton = DateTime.Now;
dateForButton = dateForButton.AddDays(-1); // ERROR: un-representable DateTime
Run Code Online (Sandbox Code Playgroud)
每当我运行它时,我都会收到以下错误:
增加或减去的值会导致无法表示的DateTime.
参数名称:value
我以前从未见过这个错误信息,也不明白为什么我会看到它.从我到目前为止阅读的答案来看,我总是相信我可以在添加操作中使用-1来减去天数,但正如我的问题所示,这不是我试图做的事情.
如何计算dgv.Rows.Height
int x = dgv1.Rows.Height
Run Code Online (Sandbox Code Playgroud)
Rows.Height或dgv1.RowsHeight不存在.
我正在尝试将tabSpace插入字符串:
string ab = "a" + "\t" + "b"
Run Code Online (Sandbox Code Playgroud)
但我有一个正方形而不是空间.请帮忙.
string abc = "07:00 - 19:00"
x = int.Parse(only first two characters) // should be 7
y = int.Parse(only 9th and 10th characters) // should be 19
Run Code Online (Sandbox Code Playgroud)
我怎么能这样说呢?
我正在尝试从ComboBox Collection中删除所选项目:
在设计时手动添加项目作为集合.
buttonClick:
cb01.Items.Remove(cb01.SelectedItem);.
Run Code Online (Sandbox Code Playgroud)
这会删除该项目,但下次打开表单时,该项目会再次出现.
我必须有5-6个项目的数据库吗?
请帮忙.
我想在btn1上点击以下内容:
if (btn1.Enabled == false) System.Media.SystemSounds.Beep.Play();
Run Code Online (Sandbox Code Playgroud)
虽然btn1被禁用,有没有办法发出哔哔声?
事实上,我需要这样的东西默认情况下:
foreach (controls c in Form1.Controls)
if (c is clicked && c.Enabled == false)
System.Media.SystemSounds.Beep.Play();
Run Code Online (Sandbox Code Playgroud) foreach (Control c in panPrev.Controls)
{
if (c.Tag == "move")
Run Code Online (Sandbox Code Playgroud)
效果很好,但产生警告:可能的意外参考比较; 得到一个值比较,左侧输入'string'
foreach (Control c in panPrev.Controls)
{
if (c.Tag.ToString() == "move") // this produce NullReferenceException.
Run Code Online (Sandbox Code Playgroud)
该怎么办?
我如何修剪和转换字符串如下:
string abc = "15k34"
int x = first two characters of abc // should be 15
but if abc begins with "0"
for example - string abc = "05k34"
int x = first two characters of abc // should be 5
Run Code Online (Sandbox Code Playgroud)