Jump to content
  • Advertisement
Sign in to follow this  
namingway

C# help

This topic is 3735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a menu item which I want to load an image from file into a picture box. Also is it possible to add scrollbars to picture boxes or will I need a different component?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by namingway
I have a menu item which I want to load an image from file into a picture box.
Also is it possible to add scrollbars to picture boxes or will I need a different component?


I don't understand your first question. About the second one, you can add the picturebox into a panel with autoscroll enabled. That should make scrollbars appear as soon as the picture becomes larger than the containing panel...

EDIT: if you're asking how to ask the user for a file, you need to hasndle the event fired when a click on the menu item is performed, then you must create and show an OpenFileDialog and get the selected file. With the path you can then create a Bitmap with the name as the parameter of the constructor.

Share this post


Link to post
Share on other sites
ah my apologies, I'd like some help on how to setup an openfile dialog then assign the chosen file the picture box's image.

Share this post


Link to post
Share on other sites
Your language is a little unclear. Do you want to:

1) Load the image from the file and display it in the picturebox
2) Save the image from the picturebox to the file

For both options, you begin by hooking up an event to the menu item. In the code for that event, you then create an OpenFileDialog or a SaveFileDialog, use it to get the filename, and then either create a bitmap from that file and set it into the picturebox, or get the image from the picturebox and save it to that file.

You're going to have to ask more specific questions if you want more specific help.

Share this post


Link to post
Share on other sites
Again sorry, I've been in a rush. At this point in time all I'd like to know is how to store the image e.g. .bmp, .png chosen from an open file dialog file and then assign it to a picture box.

Share this post


Link to post
Share on other sites
oh nevermind got it.

A new question, how can I set a limit on the dimensions of the loaded image, say if the image isnt 300x800 then it won't load.

Share this post


Link to post
Share on other sites
simple enough, okay now I have this so far; ofd = openFileDialog ;)

private void loadTilesetToolStripMenuItem_Click(object sender, EventArgs e)
{
ofd.ShowDialog();
_tileset = new Bitmap(ofd.FileName);
if (_tileset.Width == 256 && _tileset.Width == 640)
picTileset.Image = _tileset;
else
{
TilesetError err = new TilesetError();
err.ShowDialog();
}
}



Problem is if the user clicks cancel it brings up the error message as well as if the dimensions arent met, how can I fix it so that if the user cancels the openfile dialog no error will show up?

Thanks for the help so far it is much appreciated.

Share this post


Link to post
Share on other sites
cheers, I have yet another question...
I have dialog for when the user clicks File -> new , this dialog takes in 3 values, how can I transfer the values over to the main form?
I need numHeight, numWidth to be set to the mainForms _columns and _rows properties.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!