我在尝试替换匹配某个特定单词的所有文本时遇到问题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)
这很好但我注意到当我尝试用自己和另一个字母替换一个字母时有点故障.
例如我想替换所有e在Welcome to Nigeria用ea.
这就是我得到的Weaalcomeaaaaaaa to Nigeaaaaaaaaaaaaaaria.
并且消息框显示23何时只有三个e.请问我做错了什么,我怎么能纠正它
我正在尝试从已定义结构的数组中添加/删除数据.
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) 我想按下按钮时添加一行新行.在datagridview中它将是:datagridview1.Rows.Add()
gridcontrol中的等效代码是什么?请帮我.
与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) 我正在使用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
我怎样才能做到这一点 ?
我正在开发一个Windows窗体应用程序,它在指定的时间间隔后调用WCF服务,并根据从服务接收的数据显示输出.我有一个计划为此目的使用计时器,在500毫秒后调用该WCF服务方法.但我的一些同事告诉我使用后台工作人员然后Work_Completed重新运行工作人员.我想知道这两者有什么区别?timer还会创建后台线程吗?哪一个最适合长时间运行的任务?
假设我有一个带有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,然后尝试使用键盘更改月份.
我一直试图捕获我在winform之外按下的键,但显然KeyPress事件不起作用.
我没能比KeyPress事件更接近,KeyPress事件只能在表单级别上工作,如指定的那样
我怀疑我必须这样做
[DllImportAttribute( "USER32.DLL")]
,但我几乎没有经验.
还有另一种从快捷方式获取密钥的方法
sc是类型 System.Windows.Forms.Shortcut
var k = (Keys)sc;
Run Code Online (Sandbox Code Playgroud)
我需要为每个键分别使用单独的字符串,因为我使用的是Progress ABL .NET桥,所以上面的代码不起作用(请不要问).
我认为sc应该是一个整数,但显然在.NET中这行代码工作正常.
winforms ×10
c# ×9
.net ×1
combobox ×1
data-binding ×1
datetime ×1
devexpress ×1
keypress ×1
list ×1
mdi ×1
replace ×1
richtextbox ×1
timer ×1
wcf ×1
windows ×1