小编tin*_*tes的帖子

selecteditems和selectedindex c#

我是C#的新手,我开始学习如何编程我正在学习编程到我使用WindowsApplication而不是Console的Visual Studio Microsoft Edition.在尝试创建此代码时,我遇到了这个命令:Selected Index和Selected Item,我想知道两者之间的区别.我现在对我的代码很困惑.我要做的代码是在列表框中添加和删除文本.

谢谢你的帮助.

其他问题:在我的代码中我有这一行:

int listBoxSelectedItem = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
Run Code Online (Sandbox Code Playgroud)

我想理解这一部分:第一行,有一个名为"listBoxSelectedItem"的变量,类型为"int".您选择的项目的位置将存储到名为"listBoxSelectedItem"的变量中.那是对的吗?

第二行是,"listBox1.SelectedIndex"是传递给方法的信息,"RemoveAt"我的理解是正确的吗?

谢谢

c# selectedindex selecteditem

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

c#记事本

我是编程的新手,我开始创建一个简单的记事本,只有4个按钮(打开,保存,新建和字体).

如果我打开或保存我收到错误:这是我的代码:

        //Declare save as a new SaveFileDailog
        SaveFileDialog save = new SaveFileDialog();
        //Declare filename as a String equal to the SaveFileDialog's FileName
        String filename = save.FileName;
        //Declare filter as a String equal to our wanted SaveFileDialog Filter
        String filter = "Text Files|*.txt|All Files|*.*";
        //Set the SaveFileDialog's Filter to filter
        save.Filter = filter;
        //Set the title of the SaveFileDialog to Save
        save.Title = "Save";
        //Show the SaveFileDialog
        if (save.ShowDialog(this) == DialogResult.OK)
        {
            //Write all of the text in txtBox to …
Run Code Online (Sandbox Code Playgroud)

c#

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

显示随机数

我正在尝试设计一个猜测数字的代码.我定义了在列表框中显示的数字范围.我开始写随机(1,10),但如果我输入11,它仍然写在我的列表框中.我怎样才能写出从我的范围中选择的数字,即1-10?

我在这里迷路了.有任何想法吗?

谢谢,这是我的代码的一部分:

     private void btnOk_Click(object sender, EventArgs e)
      {

        string yourNumber;
        yourNumber = textBox1.Text.Trim();

        int returnNumber = RandomNumber(1, 10);                 
        int.TryParse(textBox1.Text, out returnNumber);
        listBox1.Items.Add(returnNumber);            
      }
Run Code Online (Sandbox Code Playgroud)

=========另外一个问题,如果我想显示一个数字范围,例如1-10,我怎么能这样做:例如,如果用户输入11,程序将不接受.

我做了这样的事情:

        int returnNumber = RandomNumber(1, 10);    

        string yourNumber;
        yourNumber = textBox1.Text.Trim();  


        if(Int32.TryParse(textBox1.Text>=1)) && (Int32.TryParse(textBox1.Text<=10));
        {
        listBox1.Items.Add(yourNumber);
        textBox1.Text = string.Empty;
        } 
Run Code Online (Sandbox Code Playgroud)

程序中有问题

==============

你好,再次感谢纳撒尼尔的回复.但我试过这个:

int returnNumber=RandomNumber(1,10);
int counter=1;
int yourNumber;

Int32.TryParse(textBox1.Text.Trim(), out yourNumber);
if (yourNumber >=1 && yourNumber <= 10)
{
  listBox1.Items.Add(yourNumber);
}
else
{
  MessageBox.Show("Please enter a number between 1-10");
}
Run Code Online (Sandbox Code Playgroud)

我想做的是设计一个猜测数字的程序.所以这是第一部分.

====

嗨,再次,这是我的最终代码:如果你能提供反馈,我会很高兴我能做得更好.谢谢.我认为我接下来要做的就是限制用户输入输入的次数.这意味着,他们只能猜出正确的数字3次或5次.不知道在哪里实现它 …

c# random

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

参数错误c#

我正在做一本书中的例子:Herbert Schildt撰写的完整参考文献C#3.0.它是关于使用参数在Console.WriteLine中编写的.这是一个例子:我试过这个但是我收到了一个错误:

Project1.exe has encountered a problem and needs to be close. We are sorry for the inconvenience. Please tell Microsoft about this problem. Send Error Report or Don't Send. And if I click, I get another error in the command prompt. "Unhandled Exception: System.Format.Exception input string was not in a correct format. 
at System.Text.StringBuilder.AppendFormatError()
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider,String Format, Object[]args)
at  System.IO.TextWriter.WriteLine(String format, Object arg0)
at  System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
At Example2.Main() in D:\myPath

我不确定这本书是否有错误或是我的代码?我很感激你的帮助.谢谢

指定格式的最简单方法之一是描述WriteLine()将使用的模板.为此,请显示所需格式的示例,使用#s标记数字位置.您还可以指定小数点和逗号.例如,这是一个更好的方式来显示10除以3:
Console.WriteLine("这里是10/3:{0:#.##}",10.0/3.0);
此语句的输出如下所示:这是10/3:3.33

顺便说一句,这是我的代码看起来像:

   static …
Run Code Online (Sandbox Code Playgroud)

c#

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

在c#中生成word文档

嗨,我想在c#中打开一个单词.我的意思是我想知道如何在c#中嵌入word文档我在网上发现了一些文章,我有疑问.这意味着什么:打开Word应用程序,然后添加新内容.如果我打开Word,我没有看到任何"添加新"是在C#中?我正在使用Microsoft Visual Studio 2008.谢谢

使用Word自动化的所有方法都是从Word.Application或Word.Document类派生的.

我们考虑使用Word应用程序创建文档,最后我们可能会执行以下步骤,

打开Word应用程序.(默认情况下,打开Word应用程序会创建一个新文档,但在自动化中,我们需要手动添加文档)
添加新文档.
编辑文档.
保存

关于C#NewBie

=========

你可以顺便在这里找到相应的文章:http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx ,我想清楚了出来,这不是功课.

c# ms-word

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

切换声明

嗨,我正在练习程序中的"Switch Loop".我正在编写一个用户可以输入整数的代码,在用户输入整数后,它还会显示用户输入的内容.现在我正在尝试实现程序要求用户输入的位置通过选择Y/N再次编号.我已将它包含在我的代码中但是如果我在第一次输入字符时要求我输入一个整数,程序将执行catch部分.我怎样才能说明如果用户输入一个字符,它也会再次显示该消息,"请输入整数:"

谢谢你的帮助,我在这里的某个地方迷路了.

          int enterYourNumber;
          char shortLetter;

            try
            {
                Console.WriteLine("Please enter the integer: ");
                enterYourNumber = Convert.ToInt32(Console.ReadLine());
                WriteNumber(enterYourNumber);

                Console.WriteLine("Do you still want to enter a number? Y/N");
                shortLetter = Convert.ToChar(Console.ReadLine());

                while (shortLetter == 'y' || shortLetter == 'Y')
                {
                    Console.WriteLine("Please enter the integer: ");
                    enterYourNumber = Convert.ToInt32(Console.ReadLine());
                    WriteNumber(enterYourNumber);

                    Console.WriteLine("Do you still want to enter a number? Y/N");
                    shortLetter = Convert.ToChar(Console.ReadLine());
                }

            }
            catch
            {                                        
                Console.WriteLine("Please enter an integer not a character");
            }
        }

            public static void WriteNumber(int wordValue)
            {

            switch …
Run Code Online (Sandbox Code Playgroud)

c# switch-statement

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

从C#编译的exe是否可以集成到网站中?

我是编程的初学者.我刚刚制作了一个名为"猜猜游戏"的程序.它似乎工作正常.我可以将它整合到网站中吗?我正在使用的CMS是Mambo.

===其他信息

谢谢你的所有建议.

我仍然没有任何关于Silverlight,WPF和Java Script的背景,我觉得这听起来不错.我正在使用Windows,我从Microsoft Visual Studio 2008编写了我的"猜测游戏",并使用了Window应用程序表单.

是的,我想,目前我让它开始学习Silverlight或Java Script,以便我可以将它集成到我的网站上:-)感谢所有输入的人:-)

干杯

c# web

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

vba excel 2003中的素数

我正在分析网站上的代码,我也在我身边尝试过,但似乎不起作用.你能告诉我为什么吗?非常感谢你的帮助.

谢谢

Private Sub CommandButton1_Click()
    Dim N, D As Single
    Dim tag As String

    N = Cells(2, 2)
    Select Case N
        Case Is < 2
            MsgBox "It is not a prime number"
        Case Is = 2
            MsgBox "It is a prime number"
        Case Is > 2
            D = 2
            Do
                If N / D = Int(N / D) Then
                    MsgBox "It is not a prime number"
                    tag = "Not Prime"
                    Exit Do
                End If
                D = D + 1
            Loop …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-2003 excel-vba

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

如何在HTML中缩进

我怎么能在这里有一个凹痕:

对不起我的问题含糊不清,我想在"9.00"和左边的边界之间进行缩进.请检查我在这里包含的链接:

http://img714.imageshack.us/i/spacing.png/

<table border="1">
    <col width="100" />
    <col width="300" />
    <tr>
        <td> 9.00 </td>
        <td> Name Name Name Name Name<br/>
            Greetings Greetings 
        </td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

html

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

"追加"一词是什么意思

我正在研究一些代码,我遇到了这个单词"Append",我不明白它是做什么的.

码:

public static void appendData(string data)
    {
        if (isRecording) sb.Append(data + Environment.NewLine);
    }
Run Code Online (Sandbox Code Playgroud)

追加是什么意思?

c#

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