Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. Here's a thought. Are you going to need to be able to expand or modify these images between software releases? If so, resources might not be the way to go. Perhaps you could get some cryptography (System.Security.Cryptography) involved. Maybe verify files with a hash or use asymmetrical encryption to make your data tamper-resistant.
  2. Activator.CreateInstance can take a System.Type, which can be created from an assembly-qualified type name. If you have an assembly-qualified type name in the DB, you can pull it and instantiate it without having to worry about which assembly it belongs to (assuming that the assembly is loaded). If the forms are all in the same assembly and you know which assembly they are in then make life easier and just use PD's suggestion.
  3. No need to invalidate. Just draw. int lastX = 0; int lastY = 0; // Demonstrate drawing given a pair of coordinates // You can adapt this for whatever input device you may be using public void OnThisMouseMove(Object sender, MouseEventArgs e){ this.CreateGraphics.DrawLine(Pens.Black, e.X, e.Y, lastX, lastY); lastX = e.X; lastY = e.Y; } If you are using a bitmap as a backbuffer, it might be more efficient to draw twice, once to the buffer and once to the screen, instead of drawing to the buffer and then invalidating the screen to reflect the changes. // Adapted for backbuffer public void OnThisMouseMove(Object sender, MouseEventArgs e){ gBackBuffer.DrawLine(Pens.Black, e.X, e.Y, lastX, lastY); this.CreateGraphics.DrawLine(Pens.Black, e.X, e.Y, lastX, lastY); lastX = e.X; lastY = e.Y; }
  4. As far as .Net Game Programming With DirectX, I feel your pain. Some of the code in the book isn't even compatible with newer versions of managed DirectX. Nothing but headaches. Fifty dollars that could have been better spent. Of the two programming books I've bought in my lifetime, that one was by far one of the worst.
  5. What version (version number and standard/express/professional) of what language(s) are you using? There are lots of tutorials around, but in the newest versions of C# and VB.Net (not sure about C++) there is a designer to generate code to access resources.
  6. Guessing by the lack of semi-colons, I'd say VB, in which case the escaped backslashes would not be required.
  7. Assuming that you are using 2005, if the project has added them to the resources pseudo-folder for you, you should be able to access them like following: DefaultNamespace.Properties.Resources.ResourceName
  8. I'm sure it will. Sorry. I forgot about that problem when I posted my solution. It doesn't happen in C# 2005.
  9. There is, but it isn't nearly as simple to write as it would be using GetPixel/SetPixel. You'll need to understand image manipulation (I'm sure you do) and binary math. Simply put, you would create an array, use the Marshal class (not sure which namespace) to copy the raw pixel data to the array, modify the raw pixel data, and finally copy it back to the bitmap. First create an array (Int32s and UInt32s are ideal, especially with 32-bit ARGB images) with the appropriate size to hold pixel data. For a 32-bit bitmap, the size of the array would simply be the width of the image multiplied by the height of the image. Next you would lock the bitmap. The object returned by the Lock function contains a pointer to the raw pixel data (named Scan0). Call Marshal.Copy to copy the data from Scan0 to your array. For the length argument, pass the length of the array. Now you can modify the raw pixel data. For example, to view only blue data (exclude red, green, and alpha), use could use code akin to the following: // storing raw image data in img[] // IM NOT SURE ABOUT THE BYTE ORDER int fullAlpha = 0xFF << 24; int blueMask = 0xFF; for(int i = 0; i < img.Length; i++) { img[i] = img[i] & blueMake // Extract blue data | fillAlpha; // and make it fully opaque. } Lastly, you would use Marshal.Copy to copy the image data back to the bitmap and unlock the bitmap. Some people might tell you to forget the whole Array/Marshal.Copy thing and use pointers, but that requires unsafe code (more permissions), can only be done in C#, and in my experience, actually seems to be slower than using the Marshal class. If you run into any problems coding, I'll be glad to give you a hand
  10. Assuming that you are looking for a managed solution, are you using managed extensions for C++ (version 7) or C++/CLI (version 8)? This code should work in VC++ 8. int i; System::Windows::Forms::MessageBox::Show(i.ToString()); If you were using VC++ 7 the only difference that I can think of is that you might have to box the integer before calling ToString.
  11. Are the cursors on the screen or within a window? Assuming that the answer is within a window, I would use the Invalidate(Rectangle) overload. It is very simple: you call it on a specific control, specifying a rectangle that needs to be redrawn. The control will redraw only that rectangle. I don't see how a timer could come into play, unless you want to redraw at a given framerate, and even then, the two solutions aren't mutually exclusive. The signifigance of the difference between drawing to the screen versus to a window is that the Invalidate method can only work on a window that belongs to a .Net application.
  12. You guys are something else. There is more to a person than their looks. It's what's on the inside that counts. Marbles!
  13. Many collection types work like this. This isn't a .Net thing. This is a C# thing (and it is available but not necessary in VB since the Item property is also available). In C# it's referred to as an indexer. In VB it is an indexed property that is also the default property. If you were using J# you would be using the get_Item function. It's all a matter of how the language presents the underlying IL.
  14. I have a feeling that this will depend on whether you program C# or VB, but... I'm sure most C# programmers have noticed that C#'s for syntax is a bit more involved that that of VB. If a new, more VBish loop structure was introduced, which of the following would you prefer, and why? I'd appreciate other suggestions, too, but understand that the basic idea is to compliment VB's simple "For blah = blah To blah" syntax. loop(controlVariable, start, lastValueIterated){} [color=DarkGreen]//Compare[/color] loop(i, 5, 10) {} for(int i = 5; [color=Red][b]i <= 10[/b][/color]; i++) {} [color=Blue]5, 6, 7, 8, 9, 10[/color] [/Code] [Code] loop(controlVariable, start, terminatingValue){} [color=DarkGreen]//Compare[/color] loop(i, 5, 10) {} for(int i = 5; [color=Red][b]i < 10[/b][/color]; i++) {} [color=Blue]5, 6, 7, 8, 9[/color] [/Code] [Code] loop(controlVariable, start, iterationCount){} [color=DarkGreen]//Compare[/color] loop(i, 5, 10) {} for(int i = 5; [color=Red][b]i < 5 + 10[/b][/color]; i++) {} [color=Blue]5, 6, 7, 8, 9, 10, 11, 12, 13, 14[/color] [/Code] And just in case anyone really wants to know why I'm asking, I am working on a command interpreter, and for immediate execution, small and simple goes a long way.
  15. I swear I posted the same answer yesterday. I must have closed the window too fast or something... I had used VB7 for quite a while before I discovered the anchor property, and since then I don't think I've written a single line of form resize code. You can use anchor to center something, anchor it to a single edge, or anchor it to two edges to make it stretch with its container. Very handy.
  16. What would you be using this for? Where is the string coming from? You may find a select case to be the easiest route. If you need to be a little more dynamic, the Assembly class is probably the solution. Things can get tricky if you aren't sure which assembly the type belongs to, so if you are using this for some sort of plug-in system or anything along those lines, a System.Type might be a little more approprite. And then, if you need to serialize type info, the Type.AssemblyQualifiedTypeName and Type.GetType functions come in handy.
  17. I'd be glad to start. I guess I'll have to post it here since the new bikini forum isn't open yet. This is one of me back in my younger days.
  18. Does it raise the Navigating event before a download begins? That might be a good starting point.
  19. Here is the big problem that I encounter, which is the reason that I don't post questions here. When I run into a problem, first thing I do is run to the Object Browser. If that fails, I spend a couple of minutes in the MSDN docs. Next I go to google. Using this method, 99 percent of my questions are answered without wasting anyone else's time with something trivial. With the remaining one percent of my questions, I used to make posts on this forum. They tend to be advanced questions, hence my difficulty finding an answer in the first place, and of the few questions I've posted, few have been answered. Worst yet, I'm usually the one to post the answer, after doing research over a period of a week or so. As far as the "merger" idea, well... that's a bit iffy. I used to answer questions on both forums. The sister forum has its fair share of noobs too. What they don't have is a boatload of maturity. Too many people who don't know what they are talking about try to jump in and answer and the result is misinformation and unnecessary workarounds and hacks. And arguments over whose ideas or methods are better (here, more often people state their opinions and their reasons and agree to disagree, or open a new thread for a mature discussion of the topic [that's you mskeel]). I'm sure that there are plenty of nice and intelligent people over there. I'm just not sure that I want to deal with what seems to be the majority there, which is why I don't post there any more. As far as the idea of making the forum more of an active thing, as opposed to something passive, I'd be all for it. Some sort of intellectual discussion or collaboration would probably bring a little more traffic through.
  20. What very limited DirectDraw experience I have is rusty, but there is probably some way to bring alpha transparency into the situation. Would it be possible to draw semi-transparent black rectangles over the whole screen at different alpha levels to create the fade effect. If DirectDraw doesn't directly support ARGB colors, I'm pretty sure that it can at least support ARGB PNG files.
  21. It can be a little difficult to diagnose the problem with only a very simple description of the symptoms. It would be best if you could provide some code, but you should at least give some sort of details (What are you putting in the ComboBox's collection? Does it happen every time? What do you get when you call the .ToString method? etc., etc., etc.).
  22. Having users turn down their graphics acceleration is hardly a realistic solution. Unless there is a real good reason, this should always be set to full. Otherwise, it can adversely affect the performance of some other applications. With this kind of drawing, the most likely suspect, as Cags pointed out, is redrawing that is happening that you don't want and don't realize is happening. Override painting events. Change attribute flags. Intercept messages. Maybe in this particular situation it isn't a big deal, but your solution should, if at all possible, not require that a user change advanced settings, and preferably, not require that any settings be changed.
  23. I have to say that that wouldn't be a very reliable solution. It depends on the user using the classing windows theme. I think you need to either resize the track bar or its container. The unfortunate fact is that the track bar stinks at fitting the handle and the tick marks within its window properly.
  24. Another place multi-threading might help: suppose you were to download a file and perform some other additional operation. A file download isn't particularly CPU intensive, which means that you can use two threads to use all that extra CPU power and do both at once instead of waiting for the download to finish. Also, in the event that a user has a pentium with hyperthreading, theoretically an operation may perform faster if done using multiple threads, but I certainly wouldn't base a program around that.
  25. 1. Yes. Embed it in a ToolStripContainer. You won't get floating toolbar functionality but the rest is there. 2. Because it is. If you are programming in C# chances are that it is declared as private anyways, but even if it isn't, the (often unfortunate) fact is that designer doesn't allow editing of inherited controls. It would be nice if we had a template form with a toolbar with the basic buttons where we could add task-specific buttons at design-time, but we don't. It bothers me too, but what are you going to do about it. The next best thing would be to expose a collection of ToolStripButton objects to the designer through a form-wide property that would add buttons at runtime, but that might be a little easier said than done.
×
×
  • Create New...