标签: winforms

替换富文本框中的所有文本

我在尝试替换匹配某个特定单词的所有文本时遇到问题rich text box.这是我使用的代码

    public static void ReplaceAll(RichTextBox myRtb, string word, string replacer)
    {
        int index = 0;

        while (index < myRtb.Text.LastIndexOf(word))
        {
            int location = myRtb.Find(word, index, RichTextBoxFinds.None);
            myRtb.Select(location, word.Length);
            myRtb.SelectedText = replacer;
            index++;
        }
        MessageBox.Show(index.ToString());
    }

    private void btnReplaceAll_Click(object sender, EventArgs e)
    {
        Form1 text = (Form1)Application.OpenForms["Form1"];
        ReplaceAll(text.Current, txtFind2.Text, txtReplace.Text);
    }
Run Code Online (Sandbox Code Playgroud)

这很好但我注意到当我尝试用自己和另一个字母替换一个字母时有点故障.

例如我想替换所有eWelcome to Nigeriaea.

这就是我得到的Weaalcomeaaaaaaa to Nigeaaaaaaaaaaaaaaria.

并且消息框显示23何时只有三个e.请问我做错了什么,我怎么能纠正它

c# replace richtextbox winforms

2
推荐指数
1
解决办法
7184
查看次数

将数据添加到struct数组中

我正在尝试从已定义结构的数组中添加/删除数据.

struct process
{
    public int Proc_Id;
    public int Proc_BurstTime;
    public int Proc_Priority;
    public override string ToString()
    {
        return "ID: " + Proc_Id.ToString() + " Time: " + Proc_BurstTime.ToString() + " Prior: " + Proc_Priority.ToString();
    }
};

readonly process[] ProcessList = new process[]
{
    new process{ Proc_Id = 1, Proc_BurstTime = 3000, Proc_Priority = 1},
    new process{ Proc_Id = 2, Proc_BurstTime = 5000, Proc_Priority = 2},
    new process{ Proc_Id = 3, Proc_BurstTime = 1000, Proc_Priority = 3},
    new process{ Proc_Id …
Run Code Online (Sandbox Code Playgroud)

c# winforms

2
推荐指数
1
解决办法
2403
查看次数

如何在devexpress gridcontrol中添加新行?(WinForms C#)

我想按下按钮时添加一行新行.在datagridview中它将是:datagridview1.Rows.Add()

gridcontrol中的等效代码是什么?请帮我.

c# devexpress winforms

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

绑定到List &lt;string&gt;的ComboBox的MemberValue是什么?

ValueMambera ComboBox绑定的a是List<string>什么?

我正在使用Windows窗体和.NET Framework 4。

  cmbForms.DataSource = Forms;
  cmbForms.ValueMember="System.String";
  if (!string.IsNullOrWhiteSpace(PhotoDescription.Details.Form))
  {
      cmbForms.SelectedValue = PhotoDescription.Details.Form;
  }
Run Code Online (Sandbox Code Playgroud)

哪里Forms是:

 public List<string> Forms { get; set; }
Run Code Online (Sandbox Code Playgroud)

c# data-binding combobox list winforms

2
推荐指数
1
解决办法
3075
查看次数

如何避免或限制MDI子窗体菜单条与MDI父窗体菜单条合并?

有可能这样做,如果是的话怎么样?

我的应用程序的屏幕截图

图片

.net c# windows mdi winforms

2
推荐指数
1
解决办法
4637
查看次数

在datetime变量中获取24小时时间格式

我正在使用DateTime.TryParseExact函数使用以下代码获取变量中的datetime值

 DateTime dt;
 CultureInfo provider = CultureInfo.InvariantCulture;
 System.Globalization.DateTimeStyles style = DateTimeStyles.None;
 string[] format = new string[] { "d/MMM/yy H:m:s tt","d-MMM-yy H:m:s tt" }; 
 string strDate = "24-May-13 12:03:03 AM";
 DateTime.TryParseExact(strDate, format, provider, style, out dt);
Run Code Online (Sandbox Code Playgroud)

现在它做了什么它正确解析日期时间并给我结果24-May-2013 12:03:03 但我希望它应该像这样返回我24-May-2013 00:03:033

我怎样才能做到这一点 ?

c# datetime winforms

2
推荐指数
1
解决办法
8195
查看次数

计时器与重复的背景工作者

我正在开发一个Windows窗体应用程序,它在指定的时间间隔后调用WCF服务,并根据从服务接收的数据显示输出.我有一个计划为此目的使用计时器,在500毫秒后调用该WCF服务方法.但我的一些同事告诉我使用后台工作人员然后Work_Completed重新运行工作人员.我想知道这两者有什么区别?timer还会创建后台线程吗?哪一个最适合长时间运行的任务?

c# wcf multithreading timer winforms

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

使用DateTimePicker CustomFormat MMM-yyyy时避免不可表示的DateTime

假设我有一个带有MMM-yyyy CustomFormat的DateTimePicker,它已被初始化为2013年10月31日的值,这将显示为2013年10月.

如果选择控件的Oct部分并按向上或向下箭头,则会生成ArgumentOutOfRangeException - Year,Month和Day参数描述不可表示的DateTime.

据推测,它正在改变月份而不改变一天,9月和11月只有30天.请注意,如果CustomFormat为dd-MMM-yyyy,则不会引发任何错误,因为该日期会自动更改为30日.

如何避免或发现此错误?

我可以添加代码以确保DateTimePicker始终初始化为一个月的第一天,但​​我想允许用户从日历下拉列表中选择月份和日期,因此我需要应对用户手动操作的情况选择了31,然后尝试使用键盘更改月份.

datetimepicker winforms

2
推荐指数
1
解决办法
1465
查看次数

如何在表单之外捕获按键?

我一直试图捕获我在winform之外按下的键,但显然KeyPress事件不起作用.

我没能比KeyPress事件更接近,KeyPress事件只能在表单级别上工作,如指定的那样

我怀疑我必须这样做

[DllImportAttribute( "USER32.DLL")]

,但我几乎没有经验.

c# keypress winforms

2
推荐指数
1
解决办法
4987
查看次数

从ShortCut获取密钥

还有另一种从快捷方式获取密钥的方法

sc是类型 System.Windows.Forms.Shortcut

var k = (Keys)sc;
Run Code Online (Sandbox Code Playgroud)

我需要为每个键分别使用单独的字符串,因为我使用的是Progress ABL .NET桥,所以上面的代码不起作用(请不要问).

我认为sc应该是一个整数,但显然在.NET中这行代码工作正常.

c# winforms

2
推荐指数
1
解决办法
318
查看次数