Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
GeneralRe: Persist text of a textBox Pin
Tom Deketelaere15-Dec-08 21:33
professionalTom Deketelaere15-Dec-08 21:33 
AnswerRe: Persist text of a textBox Pin
jas0n2315-Dec-08 22:11
jas0n2315-Dec-08 22:11 
GeneralRe: Persist text of a textBox Pin
Maddie from Dartford15-Dec-08 23:42
Maddie from Dartford15-Dec-08 23:42 
QuestionLog4net buffer size Pin
devvvy15-Dec-08 17:22
devvvy15-Dec-08 17:22 
Questioncode problem Pin
bhatted15-Dec-08 15:51
bhatted15-Dec-08 15:51 
AnswerRe: code problem Pin
Christian Graus15-Dec-08 16:31
protectorChristian Graus15-Dec-08 16:31 
GeneralRe: code problem Pin
bhatted16-Dec-08 5:06
bhatted16-Dec-08 5:06 
QuestionDisplaying Graphics in Windows Form Pin
ejohns8515-Dec-08 9:33
ejohns8515-Dec-08 9:33 
Hello,

I'm a bit of a newbie here, so would appreciate some help on this one!

I want to write a program that will display a map on a windows form. The map is built up of a 2-dimensional array of objects (either Land or Water), of size [1000, 1000], which represent whether that area of the map is land, or water. Eg. at Map[30, 50] there is a Land object, which means that at coordinates (30, 50), there is one square of land on the map. The Land and Water classes have a member called "colour", which defines the colour of that square on the map. Each square on the map has a side of length 1. So the map is just a load of squares all joined together.

Ok, so I now want to display this map on a form. To do this, I created a pictureBox on the form, and then created a graphics object, g, from this pictureBox. Next, I performed the following operations:

for (int i = 0; i < 1000; i ++)
{
for (int j = 0; j < 1000; j ++)
{
g.FillRectangle(new Pen(Map[i, j].colour).Brush, new Rectangle(i, j, 1, 1));
}
}

This basically colours in each square at coordinates (i, j) with the colour corresponding to whether it is land, or water, (green, or blue), at that location.

Essentially, this works. However, it is soooo slow to draw, and takes about 3 seconds just to draw the map. The map sweeps across the pictureBox over a period of 3 seconds, rather than just instantly displaying the map. This is not acceptable for the purpose of the program.

Therefore, I am wondering what the best way would be to display this map. I have 2 ideas, but I wouldn't know how to implement them. They are :

* Using graphics buffers, which I have heard about, but have no idea how they work. Can anybody tell me how to use them?
* Using DirectX rather than the basic graphics I am using (is it called GDI?)

Please could anybody advise on how to improve the performance of this program, so that I can just display the map instantly.

Thank you for your help Smile | :)

Ed.
GeneralRe: Displaying Graphics in Windows Form Pin
Luc Pattyn15-Dec-08 9:45
sitebuilderLuc Pattyn15-Dec-08 9:45 
JokeRe: Displaying Graphics in Windows Form Pin
DaveyM6915-Dec-08 10:20
professionalDaveyM6915-Dec-08 10:20 
GeneralRe: Displaying Graphics in Windows Form Pin
Dave Kreskowiak15-Dec-08 10:49
mveDave Kreskowiak15-Dec-08 10:49 
AnswerRe: Displaying Graphics in Windows Form [modified] Pin
Think-A-Tron15-Dec-08 23:31
Think-A-Tron15-Dec-08 23:31 
AnswerRe: Displaying Graphics in Windows Form Pin
User 665815-Dec-08 9:45
User 665815-Dec-08 9:45 
Questiongetting a file type's icon location (SHGetFileInfo??) Pin
mirko8615-Dec-08 8:30
mirko8615-Dec-08 8:30 
AnswerRe: getting a file type's icon location (SHGetFileInfo??) Pin
Giorgi Dalakishvili15-Dec-08 8:45
mentorGiorgi Dalakishvili15-Dec-08 8:45 
GeneralRe: getting a file type's icon location (SHGetFileInfo??) Pin
mirko8615-Dec-08 8:59
mirko8615-Dec-08 8:59 
QuestionDateTime Parse. Pin
postonoh15-Dec-08 6:21
postonoh15-Dec-08 6:21 
AnswerRe: DateTime Parse. Pin
Wendelius15-Dec-08 6:39
mentorWendelius15-Dec-08 6:39 
GeneralRe: DateTime Parse. [modified] Pin
postonoh15-Dec-08 6:47
postonoh15-Dec-08 6:47 
GeneralRe: DateTime Parse. Pin
Wendelius15-Dec-08 6:52
mentorWendelius15-Dec-08 6:52 
QuestionSleep thread but not current Pin
Xmen Real 15-Dec-08 6:00
professional Xmen Real 15-Dec-08 6:00 
AnswerRe: Sleep thread but not current Pin
User 665815-Dec-08 6:38
User 665815-Dec-08 6:38 
GeneralRe: Sleep thread but not current Pin
Xmen Real 15-Dec-08 6:43
professional Xmen Real 15-Dec-08 6:43 
GeneralRe: Sleep thread but not current Pin
User 665815-Dec-08 6:48
User 665815-Dec-08 6:48 
GeneralRe: Sleep thread but not current Pin
Xmen Real 15-Dec-08 6:50
professional Xmen Real 15-Dec-08 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.