c# - Trying to get message alert for empty text box -
i developing steganography program.
the problem is, whenever user not take image, error occurs. decided prompt error message every time user fails take image, did not work.
the error occurs at,
bitmap img = new bitmap(filetext.text);
it says, argument exception unhandled, path not of legal form.
private void encodebtn_click(object sender, eventargs e) { if (!string.isnullorwhitespace(filetext.text)) { messagebox.show("abc"); return; } bitmap img = new bitmap(filetext.text); (int = 0; < img.width; i++) { (int j = 0; j < img.height; j++) { color pixel = img.getpixel(i, j); if (i < 1 && j < msgtext.textlength) { char letter = convert.tochar(msgtext.text.substring(j, 1)); int value = convert.toint32(letter); img.setpixel(i, j, color.fromargb(pixel.r, pixel.g, value)); } if (i == img.width - 1 && j == img.height - 1) { img.setpixel(i, j, color.fromargb(pixel.r, pixel.g, msgtext.textlength)); } } }
you should check whether file name right , whether or not file exist:
string filename = filetext.text; if(string.isnullorwhitespace(filename) || !system.io.file.exists(filename)) { messagebox.show("wrong file name"); return; }
c#
No comments:
Post a Comment