Results 1 to 2 of 2

Thread: Save picture as......

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006

    Save picture as......

    Im not sure how to ask this question.

    Im creating a easy little app for a video game community, in which the game is an online shooter. I have images of all the levels in the map, and the GUI I create basically has a drop down combo box and radio buttons to select the appropriate map.

    Then you click the button the GUI that says show map, then the map appears in a picture box. I have the images showing well, but Id like for those that I distribute this application to to be able to right click the image, and do an image save as. Just like you would if you wanted to save an image you found on a webpage or whatnot.

    Here is some of the code, nothing special other than a long if statement. Im not a coding expert, so I keep things simple even if it gets long and sloppy.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         If ComboBox1.Text = "Fault" Then
    4.             If RadioButton1.Checked = True Then
    5.                 PictureBox1.Hide()
    6.                 MessageBox.Show("Map not availble")
    7.             ElseIf RadioButton2.Checked = True Then
    9.                 PictureBox1.Image = My.Resources.faultdemo
    10.                 PictureBox1.AutoSize = True
    11.                 Me.PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
    12.                 Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    13.                 PictureBox1.Show()
    14.             ElseIf RadioButton3.Checked = True Then
    15.                 PictureBox1.Hide()
    16.                 MessageBox.Show("Map not availble")
    17.             ElseIf RadioButton4.Checked = True Then
    18.                 PictureBox1.Hide()
    19.                 MessageBox.Show("Map not availble")
    20.             ElseIf RadioButton5.Checked = True Then
    21.                 PictureBox1.Hide()
    22.                 MessageBox.Show("Map not availble")
    23.             ElseIf RadioButton6.Checked = True Then
    24.                 PictureBox1.Hide()
    25.                 MessageBox.Show("Map not availble")
    26.             Else
    27.                 PictureBox1.Hide()
    28.                 MessageBox.Show("Map not availble")
    29.             End If
    32.         ElseIf ComboBox1.Text = "Antenora" Then
    33.         End If
    35.     End Sub
    37. End Class

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: Save picture as......

    You haven't specified which version of VB you're using. Please do so in future. The answer is slightly different in each. You need to add a ContextMenu (2003) or ContextMenuStrip (2005) to your form and add an item for "Save As". You then need to assign that menu to the ContextMenu or ContextMenuStrip property of your PictureBox. That menu will now be displayed when the user right-clicks the PictureBox. Now you need to double-click the menu item in the designer to create an event handler for its Click event. In the event handler you would do something like this:
    VB Code:
    1. If Not Me.PictureBox1.Image Is Nothing Then
    2.             Dim sfd As New SaveFileDialog
    4.             'Set properties of dialogue here, like the title and the file type filters.
    6.             If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
    7.                 Me.PictureBox1.Image.Save(sfd.FileName)
    8.             End If
    10.             sfd.Dispose()
    11.         End If
    You should make your code a bit more sophisticated than that but it's a start.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width