473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating images and manipulating them

Hello, I'm new to Windows Forms development in C#, and I'm having some trouble with a college project.

Simply put, it is a paint-like application, that has a toolbox to draw shapes where the mouse points.
However, these shapes must be selectable and moveable. Also, there is a tricky tool that draw a line between 2 shapes and when one of the linked shapes moves, the line must still be linked to both shapes.
I tried to do this using Graphics.FillEllipse (and such) and managed to draw lines and shapes on a PictureBox, however, I don't know how could I make them selectable nor moveable... I'm trying to use Regions now to do so, but I'd like to know if there is another way to do these things...
Any ideas?

Thanks in advance
Jun 18 '09 #1
4 3169
IanWright
179 100+
Sounds like you are almost there. What you probably want to do is create classes of shapes that know their position and size.

Using these you can do some collision detection (is mouse within the given shape?) and each class can know how to draw itself given a Graphics context.

As for the lines, you'll need to maintain some form of collection of lines that are connected, and translate their end point whenever the shape moves.
Jun 18 '09 #2
tlhintoq
3,525 Expert 2GB
@rduarte
Sounds like the difference between a 'paint' program where you have one layer and once you change the pixels you're done, and a 'draw' program that has objects on screen. Think of Photoshop versus Illustrator.

As Ian pointed out you will need to actually track each object individually so you can grab and move it again later. If you are only working by painting on a single layer that is considered "destructive". I.e. if you make a circle, half covering a square you actually replace those pixels. There would be no way to then re-create those replaced pixels to pick up the square again.
Jun 18 '09 #3
Thanks for the quick response! Much appreciated =]

So, the way to go is by Region (to detect collision). I will keep on the same track then...

For every shape that is drawn, I also create a Region object with the same size and position of the shape. Then, I use the Regions to determine wheter a click happened in some region or in a blank space. I guess this will solve the moving problem.

What about the textbox problem? Every line has a label on it, and this label must be editable... Drawing pixels is one thing, but how do I create component in run-time?
Perhaps I should just draw the word and save a Region, and when the region is selected the new text is prompted.I don't know how to make a textbox appear there either...

To create a component in run-time I tried the following:
1- Declared a new component (a Label for example)
2- Set position, text, name, font, color, etc of the component
3- Added the component to PictureBox.Controls

But the component won't show... Do I have to refresh or update the display somehow?


In the following picture, the "AB" text above the line must be editable on onclick event (sorry about the quality of the picture, it's just a concept hehe)



Thanks again for the fast and useful answers.
Jun 18 '09 #4
IanWright
179 100+
In the picture you've got. Don't attempt to use a control to store your text.

Again this wants to be in a shape class and behave in a similar way, then you can use Graphics.DrawString(). The region around it should basically be the bounding box of the text given it's font and size.

I'm not sure about the editing, you might be able to do this via a dialog? If not then you'll have to find some way to use a textbox control floating over the picture box at the correct location. (I'm not 100% sure how thats gonna work out).
Jun 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jason | last post by:
Hi, I wish to create a little game where you drag pieces onto a board. I have been playing around with a picture box: Private Sub Picture1_DblClick() Picture1.Left = Picture1.Left + 50 End...
4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
4
by: Francois Keyeux | last post by:
hello everyone: i have a web site built using vbasic active server scripting running on iis (it works on either iis 50 and 60, but is designed for iis 50) i know how to create a plain text...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
4
by: rachel | last post by:
Hello, I am currently contracted out by a real estate agent. He has a page that he has created himself that has a list of homes.. their images and data in html format. He wants me to take...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
1
by: David Lozzi | last post by:
Hello, I'm wondering whats the best method to use for displaying several photos' thumbnails. One method I know is to dynamically resize the photo at the time the page is loaded. What does this...
0
sicarie
by: sicarie | last post by:
I've finally created all the proof-of-concept code for the features my boss wants in an application, now all I need to do is create a single program with all of them together. I don't believe it will...
0
by: jonyoung | last post by:
I think I need to use WIA Windows Image Acquisition to load an image file and create a thumbnail of it and write it out again. Can anyone think of a better way to do it in ASP? I need to upload...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.