10 Replies - 8685 Views - Last Post: 21 October 2009 - 09:23 AM Rate Topic: -----

#1 Witter2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-October 09

Moving/Positioning an Image in Visual c#

Post icon  Posted 21 October 2009 - 07:34 AM

Hi All,

I'm new to Visual c# 2008 and need to ask a question regarding images.

I have set up a window with an 'Image'. I have added an 'OpenFileDialog' component and can display images into the 'Image'.
My question is how can I reposition/move this image around the window?
There doesn't appear to be any x/y positions in the properties for an 'Image'.
Is using an 'Image' the correct way?

Thanks for any help

Dave Bowler

Is This A Good Question/Topic? 0
  • +

Replies To: Moving/Positioning an Image in Visual c#

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 07:35 AM

Quote

I have set up a window with an 'Image'.

I'm confused, have you used a PictureBox, or are you drawing the Image object manually??

If you're using a PictureBox, simply create a new Point for the .Location attribute on the PictureBox. If you're drawing it manually, just change the co-ordinates.

This post has been edited by RudiVisser: 21 October 2009 - 07:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 Witter2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-October 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 08:51 AM

View PostRudiVisser, on 21 Oct, 2009 - 06:35 AM, said:

Quote

I have set up a window with an 'Image'.

I'm confused, have you used a PictureBox, or are you drawing the Image object manually??

If you're using a PictureBox, simply create a new Point for the .Location attribute on the PictureBox. If you're drawing it manually, just change the co-ordinates.


Hi RudiVisser,

Thanks for your interest! - I'm using an 'Image' manually. I tried to add a PictureBox but get an error

"The type or namespace name 'PictureBox' could not be found (are you missing a using directive or an assembly reference?)"

Which namespace is PictureBox in? I can't find it anywhere.

Thanks very much

Dave Bowler

This post has been edited by Witter2009: 21 October 2009 - 08:52 AM

Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 08:53 AM

An Image is not a control, you didn't put that on your form.

You need to add using System.Windows.Forms; at the top of your code file to use PictureBox, and if you didn't create a WinForms application, you need to add a reference to that DLL.

I'm curious to see what code you're using?
Was This Post Helpful? 0
  • +
  • -

#5 Witter2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-October 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:04 AM

View PostRudiVisser, on 21 Oct, 2009 - 07:53 AM, said:

An Image is not a control, you didn't put that on your form.

You need to add using System.Windows.Forms; at the top of your code file to use PictureBox, and if you didn't create a WinForms application, you need to add a reference to that DLL.

I'm curious to see what code you're using?


namespace Ink_Pad
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
		
	public partial class Window1 : Window
	{
	  ...
	  ...
	  ...other code...
	  ...
	  
	private void button4_Click(object sender, RoutedEventArgs e)
		{
			//browse
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.InitialDirectory = "c:\\users";
			dlg.Filter = "Image files (*.jpg)|*.jpg|All Files (*.*)|*.*";
			dlg.RestoreDirectory = true;

			Nullable<bool> result = dlg.ShowDialog();
			if( result == true )
			//if( dlg.ShowDialog() == Microsoft.Win32.DialogResult.OK )
			{
				string selectedFileName = dlg.FileName;
				//FileNameLabel.Content = selectedFileName;
				BitmapImage bitmap = new BitmapImage();
				bitmap.BeginInit();
				bitmap.UriSource = new Uri(selectedFileName);
				bitmap.EndInit();
				image1.Source = bitmap; //added in designer
			}
   }
}



Hi Rudi, just to clarify the project I am using was set up as a WPF project.
In the above image1 is an Image added with the designer.
This works (I can load/display a Jpeg etc).
At this point I got stuck as I couldn't find the positional properties for Image...

Thanks

David Bowler
Was This Post Helpful? 0
  • +
  • -

#6 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:09 AM

OH WPF!!! I'm sorry, never properly worked with WPF, can get much better effects with custom WinForms IMO :D

Was just about to ask what a Window was :P

I would love to be able to offer help, but the last time I attempted to work with WPF, I also couldn't position anything via code, so I gave up trying.

Sorry.
Was This Post Helpful? 0
  • +
  • -

#7 Witter2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-October 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:11 AM

View PostRudiVisser, on 21 Oct, 2009 - 08:09 AM, said:

OH WPF!!! I'm sorry, never properly worked with WPF, can get much better effects with custom WinForms IMO :D

Was just about to ask what a Window was :P

I would love to be able to offer help, but the last time I attempted to work with WPF, I also couldn't position anything via code, so I gave up trying.

Sorry.


Lol - no worries - Thanks very much for trying to help me though.

David Bowler
Was This Post Helpful? 0
  • +
  • -

#8 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:15 AM

I did some googling, and eugh, I couldn't live with this rubbish.

Turns out that......

Quote

There is no absolute positioning in WPF. Instead, controls are automatically placed and sized according to their margins, the margins of adjacent controls, and the padding of their container. The system is very similar to that used in web pages.


Taken from here.

I don't understand how he compares that to web pages.. They're not meant to be APPLICATIONS. I stand by my good old "WPF is stupid" argument :P

EDIT: Might be best to post it here.. If it is possible you could get a better response -> http://www.dreaminco...howforum121.htm

This post has been edited by RudiVisser: 21 October 2009 - 09:16 AM

Was This Post Helpful? 0
  • +
  • -

#9 Witter2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-October 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:17 AM

Hi Rudi,

Bang goes my Quake beater in WPF then!!!
Maybe I should stick to WinForms. In your opinion would this be better for games?
I come from a C++ background and am not used to all this 'designer' rubbish!

Thanks

David Bowler
Was This Post Helpful? 0
  • +
  • -

#10 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 994
  • View blog
  • Posts: 3,547
  • Joined: 05-June 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:20 AM

For games, I'd look into XNA if you want DirectX accelleration.

I managed to get a simple Panel control that will pump out about 90FPS, but this is all based on the users' CPU thanks to GDI+'s unaccelerated nature.

It really depends what you want to do.. C++ could well be the better option if you're making an "advanced" game (talking 3D n stuff)..
Was This Post Helpful? 1
  • +
  • -

#11 Witter2009  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 21-October 09

Re: Moving/Positioning an Image in Visual c#

Posted 21 October 2009 - 09:23 AM

Thanks for the advice Rudi.

David Bowler
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1