在c#中调整图片框大小的代码是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13377026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:21:47  来源:igfitidea点击:

What is the code to resize a picturebox in c#?

c#resizesizepicturebox

提问by sookie

I'm only a beginner in C#, so simple answers would really help.

我只是 C# 的初学者,所以简单的答案真的很有帮助。

I'm trying to make a very simple game that detects a MouseClickon a PictureBoxof size 50,50 (at the beginning of the game). After each successful MouseClick on the PictureBox (which has a blue BackgroundImage), I want to change to Sizeof the PictureBox so that it is 1 pixel smaller in Widthand Height. I will then have the PictureBox move to a random location (which I already know how to do, so no help is needed for that part).

我试图做一个非常简单的游戏,检测MouseClickPictureBox尺寸50,50(在游戏的开始)。在 PictureBox(有一个蓝色BackgroundImage)上每次成功 MouseClick 之后,我想更改为SizePictureBox 的 ,以便它在Width和中小 1 个像素Height。然后,我将把 PictureBox 移动到一个随机位置(我已经知道该怎么做,因此该部分不需要帮助)。

I think it may have something to do with picturebox.Resizebut I'm not very sure.

我认为这可能与此有关,picturebox.Resize但我不太确定。

采纳答案by Vloxxity

This is a total general question you should look it up in the internet and dont ask it here.. btt:

这是一个一般性的问题,您应该在互联网上查找,不要在这里问.. btt:

Size size = new Size(100,100);
pictureBox1.Size = size;

http://msdn.microsoft.com/de-de/library/system.windows.forms.picturebox.aspxh

http://msdn.microsoft.com/de-de/library/system.windows.forms.picturebox.aspxh

http://msdn.microsoft.com/de-de/library/system.windows.forms.control.size.aspx

http://msdn.microsoft.com/de-de/library/system.windows.forms.control.size.aspx

in your case this would be your code:

在您的情况下,这将是您的代码:

Size size = pictureBox1.Size;
size.Height--;
size.Width--;
pictureBox1.Size = size;

or just:

要不就:

pictureBox1.Height--;
pictureBox1.Width--;

or for the cool ones:

或者对于酷的:

private int size = 50;
private void button5_Click(object sender, EventArgs e)
{
    size--;
    pictureBox1.Height = pictureBox1.Width = size;
}

resp.:

分别:

private void button5_Click(object sender, EventArgs e)
{
    pictureBox1.Height = pictureBox1.Width = pictureBox1.Width - 1;
}

回答by Mr_Green

This should work..

这应该工作..

int newSize = 50; //Global variable

PictureBox1_ClickEvent

PictureBox1_Click事件

pictureBox1.Size = new Size(newSize--,newSize--);