小编use*_*998的帖子

正则表达式后检测单词

我有一个很长的文字,部分文字是

你好,我是约翰你(1)是(你是)吗?

我用它来检测(1).

string optionPattern = "[\\(]+[0-9]+[\\)]";
Regex reg = new Regex(optionPattern);
Run Code Online (Sandbox Code Playgroud)

但我被困在这里继续如何检测后(1)发现are.

完整代码(感谢falsetru为我带来这么远):

string optionPattern = @"(?<=\(\d+\))\w+";
Regex reg = new Regex(optionPattern);

string[] passage = reg.Split(lstQuestion.QuestionContent);
foreach (string s in passage)
{
    TextBlock tblock = new TextBlock();
    tblock.FontSize = 19;
    tblock.Text = s;
    tblock.TextWrapping = TextWrapping.WrapWithOverflow;
    wrapPanel1.Children.Add(tblock);
}
Run Code Online (Sandbox Code Playgroud)

我假设如果我这样拆分,它将删除(0-9)之后的所有单词,但是当我运行它时它只删除()在最后一次检测之后的单词.

在此输入图像描述

你可以看到(7)之后的单词已经消失,但其余的则没有.

我如何检测are(1)
是否可以用文本框替换(1)之后的单词?

c# regex

15
推荐指数
1
解决办法
706
查看次数

如何在WPF中创建填字游戏?

我创建了10 x 10个TextBox,用户应该将这些单词输入到相关的TextBox中以获取单词的位置.我将所有内容保存到这样的文本文件中:

在此输入图像描述

然后在WPF方面,我阅读文本文件并在面板中填充TextBoxes,但问题是填字游戏已经关闭并且提示会引导您回答,每个提示都会有一个数字来指示哪个是哪个.但是,我想不出一种方法可以将数字的拼图编号与数字和数字之间的提示联系起来.这就是现在的样子:

在此输入图像描述

注意数字(我在油漆中编辑它们以显示我想要的东西)在横向和向下旁边,我需要显示这些数字.

在我的数据库中,我将文件的位置存储在一个表中,并将提示和答案存储在另一个表中,如下所示:

在此输入图像描述

这是提示(横向和向下)和答案:

在此输入图像描述

我正在使用Entity框架lambda表达式来检索横向和向下.

感谢任何有关此问题的帮助,以便将数字分配给拼图的横向和横向.

这是我显示拼图的代码:

  protected void Across()
    {
        IList<ModelSQL.puzzlecontent> lstAcross = daoPuzzleContent.GetAcross();

        foreach (ModelSQL.puzzlecontent lista in lstAcross)
        {
            Label tbA = new Label();
            tbA.Content = lista.Hint;
            tbA.Width = Double.NaN;
            tbA.BorderBrush = Brushes.CadetBlue;
            tbA.BorderThickness = new Thickness(2);
            stackPanel1.Width = Double.NaN;
            stackPanel1.Children.Add(tbA);
            words.Add(lista.Answer);

        }
    }

    protected void AddPuzzle()
    {
        // foldername of the txt file.
        //  using (StreamReader reader = File.OpenText((@daoWordPuzzle.GetfileURL())))
        string[] fileData = File.ReadAllLines(@"C:\Users\apr13mpsip\Desktop\OneOrganizer\OneOrganizer\WordPuzzle\educational.txt");

        string[] lineValues;

        int row = 0;
        int col;
        int hint = …
Run Code Online (Sandbox Code Playgroud)

c# wpf

9
推荐指数
1
解决办法
2069
查看次数

WPF C#PreviewDrop/Drop事件未被触发(使用dragadorner)

我假设当检测到具有元素作为放置目标的拖动目标时,会触发预览/放下事件.在这种情况下,我的放置目标是文本框,我的拖动目标是标签.它们都是从DB动态创建的.我正在使用DragAdorner来克隆我正在拖动的元素,在实现DragAdorner之前,我的DnD运行良好但是在我使用了dragadorner之后,它将无法正常工作.当我尝试调试时,我注意到我的预览事件没有触发.

这是我的代码:

 tbox.Drop += new DragEventHandler(tbox_PreviewDrop); // text box , Drop Target
 tbox.DragOver += new DragEventHandler(tbox_DragOver);

Label lbl = new Label();  // Label , Drag Target 
             lbl.Content = s;
             lbl.Width = Double.NaN;
             lbl.Height = 40;
             lbl.FontSize = 19;
             lbl.PreviewMouseDown += new MouseButtonEventHandler(lbl_MouseDown);
             lbl.PreviewMouseMove += new MouseEventHandler(lbl_MouseMove);
            lbl.PreviewGiveFeedback += new GiveFeedbackEventHandler(lbl_GiveFeedback);


     private void lbl_MouseDown(object sender, MouseButtonEventArgs e)
    {
        startPoint = e.GetPosition(this);
      //  Mouse.OverrideCursor = Cursors.None;

    }

    private void lbl_MouseMove(object sender, MouseEventArgs e)
    {

        if (e.LeftButton == MouseButtonState.Pressed)
        {

          //  Mouse.OverrideCursor = …
Run Code Online (Sandbox Code Playgroud)

c# wpf events drag-and-drop adorner

6
推荐指数
1
解决办法
4385
查看次数

使用数据库中的URL链接在WPF中显示图像

我像这样在数据库中保存了URL

〜/图片/问题/ drink.png

所以,当我在我的WPF应用程序中检索它时,我试图这样做:

            Image img = new Image();
            img.Width = Double.NaN;
            img.Height = Double.NaN;

    //      string fullFilePath = Path.Combine(@"C:\Users\apr13mpsip\Documents\Visual Studio 2010\Projects\iStellarMobile\iStellarMobile\Images\Questions", lstQuestion[i].ImageURL.Substring(1));
            string fullFilePath = @"C:\Users\apr13mpsip\Documents\Visual Studio 2010\Projects\iStellarMobile\iStellarMobile\Images\Questions\drink.png";
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.UriSource = new Uri(fullFilePath, UriKind.Relative); 
            bi.EndInit();


            img.Source = bi;
            wrapPanel1.Children.Add(img);
Run Code Online (Sandbox Code Playgroud)

lstQuestion [i] .ImageURL是我从数据库中检索的URL.但它不会工作......当我运行它时它什么都不显示,所以我通过手动输入整个目录尝试了完整的路径,但它仍然无法工作,我在这里出了什么问题?

当我调试它时,它只显示Images\Questions\drink.png而不是完整路径

当我使用

Path.Combine(@"C:\ Users\apr13mpsip\Documents\Visual Studio 2010\Projects\iStellarMobile\iStellarMobile",lstQuestion [i] .ImageURL.Substring(1));

,它说URL无法确定,当我调试它时,它只读为Images\Questions\drink.png而不是完整路径.

c# url wpf image path

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

WPF C# 拖放

基本上,我通过将标签拖动到文本框来使用文本框和标签进行拖放。文本框和标签是在同一个 for 循环中创建的。

我已经动态创建了文本框(文本框是放置目标),如下所示:

  TextBox tbox = new TextBox();
            tbox.Width = 250;
            tbox.Height = 50;
            tbox.AllowDrop = true;
            tbox.FontSize = 24;
            tbox.BorderThickness = new Thickness(2);
            tbox.BorderBrush = Brushes.BlanchedAlmond;     
            tbox.Drop += new DragEventHandler(tbox_Drop);

            if (lstQuestion[i].Answer.Trim().Length > 0)
            {

                wrapPanel2.Children.Add(tbox);
                answers.Add(lbl.Content.ToString());
                MatchWords.Add(question.Content.ToString(), lbl.Content.ToString()); 

            }
Run Code Online (Sandbox Code Playgroud)

我还动态地创建标签(标签是拖动目标),如下所示:

  Dictionary<string, string> shuffled = Shuffle(MatchWords);
        foreach (KeyValuePair<string, string> s in shuffled)
        {
            Label lbl = new Label();
            lbl.Content = s.Value;
            lbl.Width = 100;
            lbl.Height = 50;
            lbl.FontSize = 24;              
            lbl.DragEnter += new DragEventHandler(lbl_DragEnter);
            lbl.MouseMove += new MouseEventHandler(lbl_MouseMove); …
Run Code Online (Sandbox Code Playgroud)

c# wpf label textbox drag-and-drop

5
推荐指数
1
解决办法
9568
查看次数

使用拖动装饰器进行拖放

我使用拖动装饰器来克隆标签的图像(拖动目标),但现在我无法将标签放入文本框中,

这是我使用的代码(你可能会看到那里的previewdragover,我在previewdragover中写了e.Handled = true,但没有帮助)我还将tbox.AllowDrop设置为true:

文本框 :

  tbox.PreviewDrop += new DragEventHandler(tbox_PreviewDrop);
  tbox.PreviewDragOver += new DragEventHandler(tbox_PreviewDragOver);
Run Code Online (Sandbox Code Playgroud)

文本框的处理程序:

   protected void tbox_PreviewDrop(object sender, DragEventArgs e)
    {
        (sender as TextBox).Text = string.Empty; // Empty the textbox from previous answer.
        (sender as TextBox).Background = Brushes.White;
        e.Handled = true;
    }
Run Code Online (Sandbox Code Playgroud)

标签(拖动目标):

             Label lbl = new Label();
             lbl.Content = s;
             lbl.Width = Double.NaN;
             lbl.Height = 40;
             lbl.FontSize = 19;
             lbl.MouseDown += new MouseButtonEventHandler(lbl_MouseDown);
             lbl.MouseMove += new MouseEventHandler(lbl_MouseMove);
             lbl.GiveFeedback += new GiveFeedbackEventHandler(lbl_GiveFeedback);
             lbl.MouseUp += new MouseButtonEventHandler(lbl_MouseUp); 
             wrapPanel2.Children.Add(lbl);
Run Code Online (Sandbox Code Playgroud)

标签处理程序:

        private …
Run Code Online (Sandbox Code Playgroud)

c# wpf drag-and-drop adorner

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

从用户控制页面访问MainWindow的控件.WPF C#

我在MainWindow中有一个页面转换(一个控件),我有很多用户控制页面,我想从我的用户控制页面访问MainWindow中的页面转换?我怎么做?我试过了 :

        Story page = new Story();
        NavigationService nav = NavigationService.GetNavigationService(this);
        // Navigate to the page, using the NavigationService
      //  if (nav != null)
       // { 
        //    nav.Navigate(page);
            MainWindow test = new MainWindow();
            test.pageTransition1.ShowPage(page);

    //    }
Run Code Online (Sandbox Code Playgroud)

c# wpf controls mainwindow

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

代码后面的WPF C#按钮单击事件

我在后面的代码中创建了一个按钮,但是我如何编写他们的click事件?它是MouseDown吗?像这样 ?基本上我想检测按钮是否被按下然后我用一些文本填充文本框.

Button btn1 = new Button();
btn1.Content = qhm.Option1;
sp1.Children.Add(btn1);

if (btn1.MouseDown = true)
{
   tbox.Text = qhm.Option1;
}
Run Code Online (Sandbox Code Playgroud)

c# wpf onclick button

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

C# lambda 表达式 &amp;&amp; 运算符

我这里有这个代码:

public Model.task GetDelete(int qno , int aid , int tid)
{
   return context.questions.FirstOrDefault(a => a.QuestionNo = qno & a.ActivityID == aid & a.TaskID == tid);
}
Run Code Online (Sandbox Code Playgroud)

我需要适合所有 3 个 id,上面有一个错误,我是编程新手,我怎样才能避免这个错误?基本上我需要检查 3 个 id,这可能吗?有错误说

运算符“&&”不能应用于“int”和“bool”类型的操作数

c# lambda operators

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

字符串写入器写入文本文件

我有 100 个文本框,我试图将这些文本框中的所有文本写入文本文件,这是我的代码:

protected void Page_Load(object sender, EventArgs e)
{
    for (int i = 0; i <= 9; i++)
    {
        for (int j = 0; j <= 9; j++)
        {
            TextBox tb = new TextBox();
            tb.MaxLength = (1);
            tb.Width = Unit.Pixel(40);
            tb.Height = Unit.Pixel(40);
            // giving each textbox a different id  00-99
            tb.ID = i.ToString() + j.ToString();  
            Panel1.Controls.Add(tb);                       
        }
        Literal lc = new Literal();
        lc.Text = "<br />";
        Panel1.Controls.Add(lc);
    }
}

protected void btnShow_Click(object sender, EventArgs e)
{
    StringWriter stringWriter …
Run Code Online (Sandbox Code Playgroud)

c# text-files stringwriter

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

c#操作员!无法应用

我想知道为什么 !无法应用

这是我的代码:

  for (int i = 0; i < rowcol.GetLength(0); i++)
            {
                for (int j = 0; j < rowcol[i].GetLength(0); j++)
                {

                     var top = !((rowcol[i-1][j])) ? rowcol[i-1][j] : '';
                    var bottom = !(rowcol[i+1][j]) ? rowcol[i+1][j] : '';
                    var left = !(rowcol[i][j-1]) ? rowcol[i][j-1] : '';
                    var right = !(rowcol[i][j+1]) ? rowcol[i][j+1] : '';


                }
            }
Run Code Online (Sandbox Code Playgroud)

我有一个锯齿状的数组,我正在从文本文件中读取值.我与操作员有错误!不能应用于字符串,但i和j是int,是的,rowcol正在从文本文件中读取字符串.

请告诉我你是否需要完整的代码.感谢帮助

c# asp.net operators jagged-arrays

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

在网格视图的每一行中只允许检查一个单选按钮

大家好我用网格视图将多行记录插入数据库.这就是我的网格视图的样子在此输入图像描述

问题是可以选择所有单选按钮,我只需要为每一行选择1个单选按钮.我的Web表单的工作方式是用户必须使用单选按钮从两个文本框中选择正确的答案,然后我必须将检查的答案提交给数据库.这可能吗?

aspx:`

             <asp:ButtonField Text="SingleClick" CommandName="SingleClick"
                    Visible="False" />

                    <asp:TemplateField HeaderText="Question">
                        <ItemTemplate>
                            <br />
                            <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Answer">
                        <ItemTemplate>
                            <br />
                            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            <asp:RadioButton ID="RadioButton1" runat="server" />
                            <br />
                            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                            <asp:RadioButton ID="RadioButton2" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ShowHeader="False">
                        <FooterTemplate>
                            <asp:Button ID="btnAdd" runat="server" Text="+" onclick="btnAdd_Click1" />
                        </FooterTemplate>

                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
    </td>
</tr>`
Run Code Online (Sandbox Code Playgroud)

代码背后:

  protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        //Clear the existing selected row 
        foreach (GridViewRow oldrow in GridView1.Rows)
        {
            ((RadioButton)oldrow.FindControl("RadioButton1")).Checked = false;
        } …
Run Code Online (Sandbox Code Playgroud)

c# gridview

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

C#for循环显示所有记录

我在wpf c#中这样做,我试图从数据库中填充一些记录.有21条记录.

以下是我的代码的样子:

private void PopulateQuestion(int activityID, int taskID)
{
    IList<ModelSQL.question> lstQuestion = qn.GetRecords(taskID, activityID);

    for( int i= 0 ; i<=lstQuestion.Count()-1; i++)
    {
        TextBlock tb = new TextBlock();
        tb.FontSize = 19;
        tb.FontWeight = FontWeights.Bold;
        tb.Text = lstQuestion[i].QuestionContent;
        tb.TextWrapping = TextWrapping.WrapWithOverflow;
        wrapPanel1.Children.Add(tb);

        TextBox tbox = new TextBox();
        if (lstQuestion[i].Answer.Trim().Length > 0)
        {
            tbox.FontSize = 19;
            tbox.Width = 100;
            tbox.Height = 40;
            tbox.PreviewDrop += new DragEventHandler(tbox_PreviewDrop);
            tbox.Focusable = false; // Disallow user to input anything into it.
            wrapPanel1.Children.Add(tbox);
        }
        answers.Add(lstQuestion[i].Answer);

        if (lstQuestion[i].QuestionNo …
Run Code Online (Sandbox Code Playgroud)

c# wpf for-loop

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