Moving/Positioning an Image in Visual c#New to c# - please help!
Page 1 of 1
10 Replies - 8685 Views - Last Post: 21 October 2009 - 09:23 AM
#1
Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 07:34 AM
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
Replies To: Moving/Positioning an Image in Visual c#
#2
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 07:35 AM
Quote
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
#3
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 08:51 AM
RudiVisser, on 21 Oct, 2009 - 06:35 AM, said:
Quote
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
#4
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 08:53 AM
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?
#5
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:04 AM
RudiVisser, on 21 Oct, 2009 - 07:53 AM, said:
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
#6
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:09 AM
Was just about to ask what a Window was
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.
#7
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:11 AM
RudiVisser, on 21 Oct, 2009 - 08:09 AM, said:
Was just about to ask what a Window was
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
#8
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:15 AM
Turns out that......
Quote
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
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
#9
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:17 AM
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
#10
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:20 AM
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)..
#11
Re: Moving/Positioning an Image in Visual c#
Posted 21 October 2009 - 09:23 AM
David Bowler
|
|

New Topic/Question
Reply




MultiQuote




|