|
I see what you are getting at, but could you give me a look at the code, just a simple snippet?
|
|
|
|
|
It's even easier than I thought:
Rectangle rc1 = new Rectangle(0, 0, 20, 20);
Rectangle rc2 = new Rectangle(19, 21, 5, 5);
if (rc2.IntersectsWith(rc1))
{
// match
}
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Are you serious?
|
|
|
|
|
Wait, but when I run the program, you can't see the rectangles. It's probably supposed to do that, but how do you use both collision and drawing? I get them seperate, but... Thnks for the help so far though.
|
|
|
|
|
Please see my response to your other post to get an idea on how to do this.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Like I said, Invalidate() forces a paint. And what Pete said, I was gong to say, too. You should have a collection of objects that know how to draw themselves. Your paint event should step over that collection, and pass the drawing to them. This lets you easily add as many rectangles as you like, and your paint event stays clean, no matter how many shapes you add in the future.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I only said it because you are busy racking up about 1000 posts a day now (at least that's how it seems to us mortals).
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
LOL - either way, I thought to say it and didn't, so it was a fair addition to what I posted, I should have mentioned it.
It's nice to see MasterSharp both taking my advice to read some books, and starting to ask more complex questions ( which I assume means he's learning something from the books he's reading ). I feel pretty happy to think that someone actually came here wanting to learn and not just to be given code.
BTW, Nish pointed out to me that I've gone over the 40,000 post mark. That's got to be a sign that I need to get a life.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: It's nice to see MasterSharp both taking my advice to read some books, and starting to ask more complex questions ( which I assume means he's learning something from the books he's reading ). I feel pretty happy to think that someone actually came here wanting to learn and not just to be given code.
I know - it's always nice to see them grow up. BTW - I haven't forgotten your CD, it's just that we're stuck in the middle of a damn postal strike here in the UK. I don't want it to "get lost" in the post.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
OK, cool. LMK when that resolves itself.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
What are you talking about 100 posts a day. I know I'm VERY questioning, but not that many even for exagerations (probably killed that), and I've calmed down a bit and took to a book!
|
|
|
|
|
MasterSharp wrote: What are you talking about 100 posts a day
Not you - Chris. He's the most prolific poster on CodeProject.
MasterSharp wrote: I've calmed down a bit and took to a book!
That's the spirit. I buy (and read) 3 or 4 computer texts every other month. Hopefully that helps to keep me sharp.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
FYI - If you are interested in theory with a little code - mind you it is C++ but that's not important, check out the book "Beginning Math and Physics for Game Programmers" by Wendy Stahler. It is pretty good and might help you with game development. ISBN is 0-7357-1390-1. Anyhow, I found it to be invaluable in my game/physics programming.
Good Luck!
“You can't teach people to be lazy - either they have it, or they don't.”
-Dagwood Bumstead
|
|
|
|
|
|
Okay, I have just one more question about the this whole mess. After you assign the graphics...
private void Form1_Paint(object sender, PaintEventArgs e)<br />
{<br />
Graphics G = e.Graphics;<br />
<br />
G.DrawRectangle(new Pen(Color.Black, 3), 15, 15, 200, 150);<br />
<br />
G.DrawRectangle(new Pen(Color.Red, 3), 15, 15, 200, 150);<br />
(for example)
... how do you name those rectangles?
|
|
|
|
|
Hello,
You have to be carefull with the GDI objects here (memory leak)!
If you want to hold the instance of your pens for further use, you have to hold the m as local members of your class.
Same to Rectangles.
But you have to dispose (free the resourcess) them in the dispose method of your class (Form).
System Drawing.Rectangle rectangle1 = System Drawing.Rectangle.Empty;
System Drawing.Rectangle rectangle2 = System Drawing.Rectangle.Empty;
System.Drawing.Pen penBlack = new Pen(Color.Black, 3);
System.Drawing.Pen penRed = new Pen(Color.Red, 3);
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics actGraphics = e.Graphics;
rectangle1 = new System Drawing.Rectangle(15, 15, 200, 150);
rectangle2 = new System Drawing.Rectangle(35, 35, 200, 150);
actGraphics.DrawRectangle(penBlack , rectangle1);
actGraphics.DrawRectangle(penRed , rectangle2);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
if(penBlack !=null)
penBlack.Dispose();
if(penRed !=null)
penRed.Dispose();
}
base.Dispose( disposing );
}
If you not want to hold the instances (not suggested in this case), you would have to dispose the pens write after usage in your Paint event. A using block will do that automaticaly.
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics actGraphics = e.Graphics;
using(System.Drawing.Pen penBlack = new Pen(Color.Black, 3))
using(System.Drawing.Pen penRed = new Pen(Color.Red, 3))
{
rectangle1 = new System Drawing.Rectangle(15, 15, 200, 150);
rectangle2 = new System Drawing.Rectangle(35, 35, 200, 150);
actGraphics.DrawRectangle(penBlack , rectangle1);
actGraphics.DrawRectangle(penRed , rectangle2);
}
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
Hey thanks, that's just what I needed!
|
|
|
|
|
That just helped a lot, and there's SIMPLE collision detection! All I fond was 50 lines of code that was... extremely confusing and hard, but thatnks again to everyone who replied... Time to continue reading.
|
|
|
|
|
Hello all,
I'm working on a project in C# where i don't want the user to be able to resize the application's form past the desktop's taskbar. Is there a command that prevents resizing beyond any of the sides of the desktop's working area? If not, what would be the best way to approach this issue?
|
|
|
|
|
You can restrict form's maximum size by setting its MaximumSize property. You can retrieve the size you need by using Screen class
|
|
|
|
|
oops, never mind, had the formborderstyle set to sizabletoolwindow instead of just sizable.
|
|
|
|
|
The big picture of what I'm trying to do is to allow all users of an active directory global group to log in to an ASP.net/C# website on my intranet. I have no idea how to do this. Lol. Can someone point me in a direction? thanks.
|
|
|
|
|
theory:
I think you need something like "Forms" authorization in your ASP.NET website set in web.config;
second step for you will be "custom membership provider" to write; i saw a few days ago example on msdn in C#.
third step is to create database for your custom membership provider, at this point you can google for the AD examples in C# [or maybe i can post you some, or simply take a look on System.DirectoryServices namespace] ...
some code which you've got to do is to obtain all info about users and/or groups and put it to your membership db. These 'DirectoryServices' then you can always use for password checking, etc.
mail me if you need further assistance
VirtualVoid.NET
|
|
|
|
|
I need help on how to add a string to the value in a dictionary type based on a particular key
when the value is a list of strings to be added to
So far I have something like this going on:
<pre>
Dictionary<string, List<string>> grammar = new Dictionary<string, List<string>>();
List<string> value = new List<string>();
const char space = ' ';
string element = "my big blue brown dog";
string key = "myString";
foreach(string word in element.Split(space))
{
//I get problems here
grammar.Add(key, value.Add(word));
}
</pre>
Any help is greatly appreciated.
Onward and Upward,
Ryan R.
|
|
|
|