我有一个PictureBox可以有多种不同尺寸的(取决于屏幕分辨率、窗口状态等)。我image想要的是PictureBox当任一image尺寸(宽度或高度)低于PictureBox.
示例:如果 的宽度image大于的宽度PictureBox,但 的高度image小于的高度PictureBox,则将image宽度调整到与 的宽度相等PictureBox,保持原始纵横比,并image垂直居中。
如果PictureBox大于两个image维度,则图像简单地居中。我有做过这部分PictureBoxSizeMode.AutoSize和一些代码到中心image基础上的大小image和PictureBox。
picbx.ImageLocation = "Image path here";
picbx.SizeMode = PictureBoxSizeMode.AutoSize;
picbx.Anchor = AnchorStyles.None;
picbx.Location = new Point((picbx.Parent.ClientSize.Width / 2) - (picImage.Width / 2),
(picbx.Parent.ClientSize.Height / 2) - (picImage.Height / 2));
picbx.Refresh();
Run Code Online (Sandbox Code Playgroud)
我不需要考虑的一件事是在当下调整大小。该窗口不允许调整大小,并且不需要考虑除初始加载之外的任何其他情况。
我发现许多帖子似乎很接近,但没有完全有效的帖子。拉伸偏斜的image,自动调整大小不会根据容器的大小调整和 …
我是 Promises 的新手,我在解决原始承诺之前等待嵌套承诺完成所有执行的概念有点麻烦。
原始代码
function getSomething(text) {
return new Promise(function (resolve, reject) {
getElse(text).then(function (items) {
if (items.length !== 0) {
/* Stuff here */
getElseElse(box).then(function (moreItems) {
/* Stuff here */
return array;
}.then(function (array) {
var promise = new Promise(function (resolve, reject) {
/* anotherFunction() is asynchronous */
result = anotherFunction(array); <-- Spot 1
});
promise.then(function () { });
});
return resolve(result); <--- Spot 2
}
else {
return resolve(null);
}
});
});
};
Run Code Online (Sandbox Code Playgroud)
更新的代码- 更好,但仍然没有像我想要的那样完全工作。
function …Run Code Online (Sandbox Code Playgroud)