8 Replies - 2248 Views - Last Post: 28 April 2009 - 07:39 AM Rate Topic: -----

#1 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Modify parameter/controls from another form!

Posted 13 April 2009 - 04:16 PM

Hi

I'm quite new to C# and I'm trying to create an application using multiple forms.
So far I have 5 forms. On the main form, frmMain, I have a panel used to display an image, a map actually.
I managed to set the background image:

private void loadMapToolStripMenuItem_Click(object sender, EventArgs e)										
		{
			try																											 
			{
				OpenFileDialog open = new OpenFileDialog();
				open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";					  
				if (open.ShowDialog() == DialogResult.OK)  // daca totul e OK
				{
					backImg = new Bitmap(open.FileName);																	
					panel1.BackgroundImage = backImg;																	  

					System.Drawing.Image objImage = System.Drawing.Image.FromFile(open.FileName);						   
					Size image_size = new Size();																		   
					image_size.Height = objImage.Height;
					image_size.Width = objImage.Width;

					panel1.Size = image_size;
				}
			}
			catch (Exception)																							   
			{
				throw new ApplicationException("Failed loading image");
			}
		}



Now I need an option to remove the image. Something like this:

			 backImg = null;
			 panel1.BackgroundImage = backImg;



I know how to remove it using a confirmation box but I want to use my own form, frmDelete_Map.
The qustion is how do I access the controls on frmMain from frmDelete_Map.

Plz go easy on me. This is my 1st post here :rolleyes:

Is This A Good Question/Topic? 0
  • +

Replies To: Modify parameter/controls from another form!

#2 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Re: Modify parameter/controls from another form!

Posted 13 April 2009 - 08:07 PM

View Postdaydr3am3r, on 13 Apr, 2009 - 03:16 PM, said:

Hi

I'm quite new to C# and I'm trying to create an application using multiple forms.
So far I have 5 forms. On the main form, frmMain, I have a panel used to display an image, a map actually.
I managed to set the background image:

private void loadMapToolStripMenuItem_Click(object sender, EventArgs e)										
		{
			try																											 
			{
				OpenFileDialog open = new OpenFileDialog();
				open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";					  
				if (open.ShowDialog() == DialogResult.OK)  // daca totul e OK
				{
					backImg = new Bitmap(open.FileName);																	
					panel1.BackgroundImage = backImg;																	  

					System.Drawing.Image objImage = System.Drawing.Image.FromFile(open.FileName);						   
					Size image_size = new Size();																		   
					image_size.Height = objImage.Height;
					image_size.Width = objImage.Width;

					panel1.Size = image_size;
				}
			}
			catch (Exception)																							   
			{
				throw new ApplicationException("Failed loading image");
			}
		}



Now I need an option to remove the image. Something like this:

			 backImg = null;
			 panel1.BackgroundImage = backImg;



I know how to remove it using a confirmation box but I want to use my own form, frmDelete_Map.
The qustion is how do I access the controls on frmMain from frmDelete_Map.

Plz go easy on me. This is my 1st post here :rolleyes:

Quote

Instead of using another form just to delete an image, why not use a frame control and design it like a form so that you may access the controls of the form.

Was This Post Helpful? 0
  • +
  • -

#3 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Modify parameter/controls from another form!

Posted 13 April 2009 - 08:13 PM

I could do that too.
But I'll need to access controls like this not just to delete the image.
So I'll still need to know how to do it. :)

This post has been edited by daydr3am3r: 13 April 2009 - 09:32 PM

Was This Post Helpful? 0
  • +
  • -

#4 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Re: Modify parameter/controls from another form!

Posted 13 April 2009 - 08:29 PM

View Postdaydr3am3r, on 13 Apr, 2009 - 07:13 PM, said:

I could do that to.
But I'll need to access controls like this not just to delete the image.
So I'll still need to know how to do it. :)

what are the other things are you going to do?
Was This Post Helpful? 0
  • +
  • -

#5 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Modify parameter/controls from another form!

Posted 13 April 2009 - 09:15 PM

Well for example, I need to add some data using a form and when I click OK some of the data to be shown in the main form unsing text boxes and labels. :)
I'll also need to use DBs.
Was This Post Helpful? 0
  • +
  • -

#6 newProgram  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 160
  • Joined: 28-October 08

Re: Modify parameter/controls from another form!

Posted 13 April 2009 - 11:20 PM

View Postdaydr3am3r, on 13 Apr, 2009 - 08:15 PM, said:

Well for example, I need to add some data using a form and when I click OK some of the data to be shown in the main form unsing text boxes and labels. :)
I'll also need to use DBs.

Quote

Passing values from another form is usefull, you may also pass dataset value.
create an instance on your program
For example you have Form1 and Form2. we will get the data on Form2 and pass it on Form1.
On Form2 follow this syntax:
frmForm1 view = new frmForm1(value1, value2);
				view.Show();


On Form1 that you will pass the values:
public frmForm1(<datatype> <variable1>, <datatype> <variable2>)
		{
			 <datatype> a = <variable1>
			 <datatype> b = <varible2>
			 InitializeComponent();
		}
		


Note that frmForm1 and frmForm2 is the name of the forms.

Hope this help.

Was This Post Helpful? 0
  • +
  • -

#7 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Modify parameter/controls from another form!

Posted 14 April 2009 - 05:18 AM

Thanks. That helped me passing values from one form to another but I still can't delete the image.
Was This Post Helpful? 0
  • +
  • -

#8 Serial  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 14-April 09

Re: Modify parameter/controls from another form!

Posted 14 April 2009 - 12:15 PM

You can access to all variables and properties declared like "public" in yours form if you declare this form "public".
the better way to do this is to declare all your forms in the header of Program.cs file:
static public frmDirectX frmDirectXForm;
		static public frmControl frmControlForm;
		static public frmAnimation frmAnimationForm;


Then instance it in the main method

static void Main(string[] args)
		{
			Conf = new Configuracion();
			nargs = args.Length;
			if (nargs > 0) { arg1 = args[0]; }
			if (nargs > 1) { arg2 = args[1]; }

			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			frmDirectXForm = new frmDirectX();
			frmControlForm = new frmControl();
			frmAnimationForm = new frmAnimation();
			Application.Run(new MainForm());
		}

and acces it anywhere, for example, creating a function for inicialize one form:
private void LoadControlForm()
		{
			Program.frmControlForm.StartPosition = FormStartPosition.Manual;
			Program.frmControlForm.Left = this.Left;
			Program.frmControlForm.Top = this.Bottom;
			Program.frmControlForm.Show();
			Program.frmControlForm.IniciateVariables(this);
		}

I hope that it can help you ;)
Was This Post Helpful? 0
  • +
  • -

#9 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Modify parameter/controls from another form!

Posted 28 April 2009 - 07:39 AM

Sorry for the late replay. Thanks for the help:).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1