c# - Enabled the button only if the picturebox have a picture on it -
i want enabled button if picturebox on windows forms have picture on it. otherwise, button remains false.
i tried below code, when picturebox contains picture, button won't enabled @ (the button enabled true default)
if (picturebox1 == null || picturebox1.image == null) { this.button2.enabled = false; } else if (picturebox1 != null || picturebox1.image != null) { this.button2.enabled = true; } if (picturebox1 == null || picturebox1.backgroundimage == null) { this.button2.enabled = false; } else { this.button2.enabled = true; } your answer appreciated!
if code executed on load event of form , picturebox empty @ point button disabled. if load image later have execute code again. there no event raised when image loaded should write method purpose:
private void setpictureboximage(image img) { this.picturebox1.image = img; this.setbuttonenabledstate(); } private void setbuttonenabledstate() { this.button2.enabled = (this.picturebox1.image != null); } whenever want set or clear image, call first method. can call second method on load event of form well, in case set image in designer, bypass setpictureboximage method.
Comments
Post a Comment