我正在做一个imageviewer.我已经完成了在图片框中导入图像.
应该使用哪个代码来自动调整图片框中的图像?这是我在查看图片框中的图片中的代码.
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.Filter = "JPEG|*.jpg|Bitmaps|*.bmp";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
pFileNames = openFileDialog.FileNames;
pCurrentImage = 0;
ImageView();
}
}
protected void ImageView()
{
if (pCurrentImage >= 0 && pCurrentImage <= pFileNames.Length - 1)
{
pictureBox1.Image = Bitmap.FromFile(pFileNames[pCurrentImage]);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在做一个询问你姓名的活动,如果输入了一个数字,它应该告诉输入是无效的.
这是我的代码:
try {
Console.Write("Enter your first name: ");
string fname = Console.ReadLine();
Console.Write("You're Name is: " + fname);
}
catch (Exception) {
Console.Write("INVALID NAME");
}
Run Code Online (Sandbox Code Playgroud)
样本输出:
Enter you're first name: 123hjay
INVALID NAME!!
Run Code Online (Sandbox Code Playgroud)
我知道我的例外是错的; 我需要你的帮助.
嗨我正在制作一个简单的c#计算示例Label1.Text = textBox1.Text + textbox2.Text当我尝试输入88.5或80.3并且计算我的程序时,我遇到了问题是继续崩溃得到错误.我已经转换了文本到Int,这是我的代码:
int i;
i = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text);
Label1.Text= i.ToString();
Run Code Online (Sandbox Code Playgroud)
但是,如果我插入88和80,它就会起作用.我知道我想念这个.有人可以帮助我吗?谢谢
我正在做一个简单的c#练习.这就是问题:编写一个名为SquareBoard的程序,它使用两个嵌套的for循环显示以下n×n(n = 5)模式.这是我的代码:
Sample output:
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
for (int row = 1; row <=5; row++) {
for (int col = 1;col <row ; col++)
{
Console.Write("#");
}
Console.WriteLine();
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.任何人都可以帮助我.谢谢..