I've just recently started with C# and as a project I decided I would try and make a image converter, but I can't seem to get the variable "open" accessible in my button1 context, I'm not looking for comments on how bad my code is, I am just starting.. I just want to get this done and add on to it, I will improve the code later on, thanks. So how can I make it accessible?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button2_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
// image filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
// image in picture box
pictureBox1.Image = new Bitmap(open.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
// image file path
string path = Directory.GetCurrentDirectory();
textBox1.Text = Path.GetDirectoryName(open.FileName);
}
}
public void Form1_Load(object sender, EventArgs e)
{
this.AutoSize = true;
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
flowLayoutPanel1 = new FlowLayoutPanel();
flowLayoutPanel1.AutoSize = true;
flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
this.Controls.Add(flowLayoutPanel1);
}
public void button1_Click(object sender, EventArgs e)
{
int selectedIndex = comboBox1.SelectedIndex;
Object selectedItem = comboBox1.SelectedItem;
if ((string)comboBox1.SelectedItem == "*.jpg")
{
pictureBox1.Image.Save(@"" + textBox1.Text + open.FileName + "", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}