小编Hoo*_*och的帖子

如何进行HTTP POST Web请求

如何使用该POST方法发出HTTP请求并发送一些数据?我可以做GET请求,但不知道如何制作POST.

.net c# post httpwebrequest httprequest

1033
推荐指数
10
解决办法
147万
查看次数

在C#中将字符串解析为DateTime

我有一个字符串格式的日期和时间:

"2011-03-21 13:26" //year-month-day hour:minute
Run Code Online (Sandbox Code Playgroud)

我怎么解析它System.DateTime

我想使用类似DateTime.Parse()DateTime.ParseExact()尽可能的函数,以便能够手动指定日期的格式.

.net c# string datetime parsing

157
推荐指数
5
解决办法
26万
查看次数

如何将我的应用程序窗口置于前面?

如何将我的应用程序窗口置于前面?例如,我的应用程序需要注意.

这是我的个人计划.我需要这个功能.

这就是我得到的.但它没有 100%的工作时间.

public void BringToFrontToEnterCaptha()
{
    if (InvokeRequired)
    {
        Invoke(new Action(BringToFrontToEnterCaptha));
    }
    else
    {
        this.TopMost = true;
        this.Focus();
        this.BringToFront();
        this.textBox1.Focus();
        this.textBox1.Text = string.Empty;
        System.Media.SystemSounds.Beep.Play();
    }
}

public void BringToBackAfterEnterCaptha()
{
    if (InvokeRequired)
    {
        Invoke(new Action(BringToBackAfterEnterCaptha));
    }
    else
    {
        this.TopMost = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

我从背景工作者那里打电话给他们.

BringToFrontToEnterCaptha();
while (!ready)
{
    Thread.Sleep(100);
}
BringToBackAfterEnterCaptha();
Thread.Sleep(300);
Run Code Online (Sandbox Code Playgroud)

按"接受"按钮后,bool ready设置为true.

我工作得很好,但并不总是.

.net c# winforms

77
推荐指数
7
解决办法
16万
查看次数

如何重新启动WPF应用程序?

如何重新启动WPF应用程序?在我使用的Windows窗体中

System.Windows.Forms.Application.Restart();

如何在WPF中做到这一点?

.net c# wpf .net-4.0

76
推荐指数
6
解决办法
7万
查看次数

字节到二进制字符串C# - 显示全部8位数字

我想在文本框中显示一个字节.现在我正在使用:

Convert.ToString(MyVeryOwnByte, 2);
Run Code Online (Sandbox Code Playgroud)

但是当字节在0开始时,那些0正在被诅咒.例:

MyVeryOwnByte = 00001110 // Texbox shows -> 1110
MyVeryOwnByte = 01010101 // Texbox shows -> 1010101
MyVeryOwnByte = 00000000 // Texbox shows -> <Empty>
MyVeryOwnByte = 00000001 // Texbox shows -> 1
Run Code Online (Sandbox Code Playgroud)

我想显示所有8位数字.

.net c# string byte bits

37
推荐指数
2
解决办法
4万
查看次数

C#管理员权限 - 检查

我知道有一些类似的问题.但我只想检查一件事.

我只想知道程序是否以管理员身份运行.我想检查一下,因为我想编辑一些安全文件.用户不必是管理员.我只想知道我的应用程序是否有权编辑一些在以管理员身份运行时可编辑的安全文件.

.net c# privileges rights administrator

36
推荐指数
2
解决办法
2万
查看次数

C#Byte [] Byte数组到Unicode字符串

我需要从字节数组到字符串的非常快速的转换.字节数组是Unicode字符串.


在此输入图像描述

.net c# memory string bytearray

33
推荐指数
2
解决办法
5万
查看次数

通过正则表达式匹配循环

这是我的源字符串:

<box><3>
<table><1>
<chair><8>
Run Code Online (Sandbox Code Playgroud)

这是我的Regex Patern:

<(?<item>\w+?)><(?<count>\d+?)>
Run Code Online (Sandbox Code Playgroud)

这是我的Item类

class Item
{
    string Name;
    int count;
    //(...)
}
Run Code Online (Sandbox Code Playgroud)

这是我的物品收藏;

List<Item> OrderList = new List(Item);
Run Code Online (Sandbox Code Playgroud)

我想根据源字符串使用Item填充该列表.这是我的功能.它不起作用.

Regex ItemRegex = new Regex(@"<(?<item>\w+?)><(?<count>\d+?)>", RegexOptions.Compiled);
            foreach (Match ItemMatch in ItemRegex.Matches(sourceString))
            {
                Item temp = new Item(ItemMatch.Groups["item"].ToString(), int.Parse(ItemMatch.Groups["count"].ToString()));
                OrderList.Add(temp);
            }
Run Code Online (Sandbox Code Playgroud)

Threre可能是一些小错误,例如在这个例子中丢失信,因为这是我在我的应用程序中更容易的版本.

问题是,最后我在OrderList中只有一个Item.

UPDATE

我搞定了.寻求帮助.

.net c# regex foreach

30
推荐指数
3
解决办法
5万
查看次数

在关闭C#WPF应用程序之前询问用户

我想在关闭申请前询问用户.我是C#.NET 4.0应用程序.我正在使用WPF.我可以在Windows窗体中执行此操作,但不能在WPF中执行.当用户想要关闭应用程序时会触发事件,消息框出现,包子无论按下哪个按钮(是或否)应用程序始终关闭.为什么?哪里出错?

它有效,但只有当用户按"X"时才有效.当用户按下Application.Current.Shutdown()时按钮; 它不起作用.

private void MainWindowDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    MessageBoxResult result = MessageBox.Show("Do you really want to do that?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Question);
    if (result == MessageBoxResult.No)
    {
        e.Cancel = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# wpf events

24
推荐指数
3
解决办法
3万
查看次数

至少有一个DataGridView控件的列没有单元格模板

我得到了那个例外.

System.InvalidOperationException was unhandled
  Message=At least one of the DataGridView control's columns has no cell template.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.DataGridView.CompleteCellsCollection(DataGridViewRow dataGridViewRow)
       at System.Windows.Forms.DataGridView.get_RowTemplateClone()
       at System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)
       at System.Windows.Forms.DataGridView.RefreshColumnsAndRows()
       at System.Windows.Forms.DataGridView.OnBindingContextChanged(EventArgs e)
       at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
       at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
       at System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value)
       at System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value)
       at System.Windows.Forms.ContainerControl.get_BindingContext()
       at System.Windows.Forms.Control.get_BindingContextInternal()
       at System.Windows.Forms.Control.get_BindingContext()
       at System.Windows.Forms.DataGridView.DataGridViewDataConnection.SetDataConnection(Object dataSource, String dataMember)
       at System.Windows.Forms.DataGridView.set_DataSource(Object value)
       at Bloowars_Tools.A1_ResultWnd.A1_ResultWnd_Shown(Object sender, EventArgs e) in D:\Documents\Visual Studio 2010\Projects\Bloowars Tools\Bloowars Tools\A1_ResultWnd.cs:line 72
       at System.Windows.Forms.Form.OnShown(EventArgs e)
       at System.Windows.Forms.Form.CallShownEvent()
       at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
       at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj) …
Run Code Online (Sandbox Code Playgroud)

c# collections datagridview exception winforms

20
推荐指数
3
解决办法
4万
查看次数