我正在尝试将一些背景图像添加到我的Win Forms应用程序中的几个按钮.这三个图像的大小不同(即像素尺寸不匹配,一个是128x128,另一个是256x256).我需要按钮的大小相同(否则GUI非常不对称).在不更改实际图像文件的情况下,如何使用按钮大小来缩放图像?
我已经尝试创建自己的类,并为按钮resize事件添加事件处理程序,但这似乎不起作用.我的代码:
class CustomButton : Button {
internal void CustomButton_Resize( object sender, EventArgs e ) {
if ( this.BackgroundImage == null ) {
return;
}
var pic = new Bitmap( this.BackgroundImage, this.Width, this.Height );
this.BackgroundImage = pic;
}
}
Run Code Online (Sandbox Code Playgroud)
并以形式:
this.buttonOne.Resize += new System.EventHandler(this.buttonOne.CustomButton_Resize);
Run Code Online (Sandbox Code Playgroud)
忘记提及,上面的代码根本没有调整图像的大小.按钮仍需要具有不同的尺寸才能完全显示图像.
对于我的应用程序,我试图在某个事件之后添加一个Jquery Datepicker(对于这个例子,我们只是说当页面加载时).
我目前正在尝试做这样的事情:
var mealControl = new MealControl();
$(document).ready(function(){
mealControl.createMealForm();
}); //document.ready
function MealControl() {
this.createMealForm = function(){
var currentDate = new Date();
var prettyCurrentDate = currentDate.getFullYear() + '/' + (currentDate.getMonth() + 1) + '/' + currentDate.getDate();
var innerHtml = "<p>Creating meal item data input here</p>" +
"<div>Title:<input id=\"mealTitle\" type=\"text\" align=\"center\" width=\"50\" class=\"ui-input-text ui-body-c ui-corner-all ui-shadow-inset\" />" +
"<br></div>" +
"<div class=\"ui-input-datebox ui-shadow-inset ui-corner-all ui-body-c\">" +
"<div class=\"ui-input-datebox ui-shadow-inset ui-corner-all ui-body-c\">" +
"<input data-options=\"{'mode':'calbox','calHighPicked':false, 'calHighToday':true, 'calHighPicked': false}\" data-role=\"datebox\"id=\"datePicker\" value=\"Enter consumption …Run Code Online (Sandbox Code Playgroud)