Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. Google says... Yes you can! Be glad to help if you have any issues with the details.
  2. Perhaps a more "dynamic" method would be in order then. Rather than creating and compiling various classes and properties, some sort of collection class to hold the values would be more appropriate. The collection can contain other collections to accomodate arbitrary data structures, and since access to values would all be through a small number of functions it would be easy to implement lazy initialization. Sometimes using a language's object-oriented constructs isn't the best way to go. You are trying to use the DotNet type system in a way that it just isn't meant to be used. FYI, when I said you were using a "hack", I didn't mean that what you were doing is morally suspect. I meant "hack" as in a less-than-ideal shortcut or workaround to make something work. Also, (I know you may not be able to divulge many details, but) just what are these properties doing that the base class won't know when it needs to initialize? Are these objects being deserialized from a direct representation in the database? Usually a subclass can implement it's own properties and the base class won't need to lazy-initialize until the subclass accesses a member on the base class. That works fine except in the rare situation where a base class is responsible for initializing a subclass in a late-bound manner. I'm impressed by your determination to make this work the way you would like it to, but I just can't imagine any possible scenario where there isn't an easier way. Do as you'd like (or as your boss would like), of course, but I suggest you (or your boss) reconsider the approach.
  3. What have you got so far? You'll need one for loop within another. Also, from the posting guidelines:
  4. So... you are injecting code into functions that have yet to be written whose details you know nothing about? Pardon the expression, but that has a very bad "code smell." Based on the little we know it sounds like a monster of a hack to compensate for a glaring problem in your object model.
  5. It sounds like you would like to implement some sort of lazy initialization. Assuming that's the case... When a class defines it's own new member as in your example, the base class can't compel any subclass to do anything. One option would be for the base class to implement a protected member (can only be accessed by subclasses) that your subclasses would be expected to call. In this case you base class would be something along the following: Public Class CommonBase ''' <summary> ''' Subclasses should call this method to ensure that the object is ''' initialized before using the base class. ''' </summary> Protected Sub EnsureInitialized() 'Do stuff End Sub End Class And a subclass would look like this: Public Class SubclassA Inherits CommonBase Dim _a As Object Public Property A() As Object Get ' Our lazy initialization, not compulsory EnsureInitialized() Return _a End Get Set(ByVal value As Object) ' Should something go here? _a = value End Set End Property End Class If your code example is any kind of indication of what the actual code will look like, it might be more appropriate to use a whole different approach to access the data/values. I have no idea what the code will do or why, but there are other designs that might suit your needs better. For example, if these properties are something that could be indexed then the base class could expose a public sealed property that accepts one parameter (the index) and performs the lazy initialization, then calls an overridable protected function that a subclass can override to implement its own logic and return its own value based on the index. Not knowing anything about your app, I have no idea what, specifically, could work for you.
  6. XNA can be great for developing 2D or 3D games, but you are going to want a really solid tutorial for beginners. Game programming is a whole different world, and there are lots of concepts that are anywhere between subtly different to radically different from what you might be used to, depending on what you are doing. I found this tutorial on Google. It looks pretty decent.
  7. Well, first of all, let's take the picture box out of the equation. What you're really after is a part of the image it contains, rather than the picture box itself (which has a border and could be obscured by another window), right? First you would want to create a new Bitmap object, then create a Graphics object for that Bitmap. The Graphics object permits you to draw to the new Bitmap. Get the image that is hosted in the picture box and use Graphics.DrawImage to draw a portion of the original image to the new Bitmap. Now you can save the Bitmap. Make sure to dispose of the Bitmap and Grapdhics when you no longer need them. I recommend using MSDN or Google to look up the documentation on these classes for the specifics.
  8. It's a bit hard to understand what you are after. Are you looking to detect when a property is retrieved from an object and perform some logic before the result is returned? Is it a class you wrote or have access to the code for? And will the logic that occurs be part of the class that the property belongs to, a class that uses said class, or a different class altogether?
  9. The name DrawImageUnscaled is very misleading. It doesn't draw the image pixel-for-pixel. It tries to draw them at their "correct physical dimensions." In other words, it takes the image's DPI and the display's DPI and scales the image to get the correct physical size. I don't know where your images are coming from, but if their resolution (DPI) varies, they will be rendered differently. The best way to actually draw an image unscaled is with one of the DrawImage overloads that accepts a source rectangle, destination rectangle, and what kind of unit to use. You would want to specify GraphicsUnit.Pixel. If the source rectangle and destination rectangle are the same size, the output won't be scaled.
  10. DirectDraw could work, but it is discouraged because it is considered obsolete. GDI+ is too slow for smooth animation or scrolling. I have no experience with Direct2D, but from what I can see it might do the trick. For a platformer I might recommend looking into XNA. It seems to be the simplest game development platform, but deployment can become difficult. The end user needs to have the right versions for DirectX, DotNet, and XNA. I couldn't tell you what's involved in deployment of a Direct2D app, but it does not appear to support Windows Xp. It's really a matter of what your specific needs are.
  11. Do you mean the map variable? I don't even see where it is used. Regardless, I would stay away from static variables. It's a holdover from VB6 and amounts to a class-level variable that can only be accessed from one method. Instead, if a variable is to be used later by the same class, I'd recommend declaring the variable as a class member rather than in the function. Also, I see you sizing the array with ReDim. This does work fine, but a DotNet purist might whine about it. Just FYI, the alternative would be: map = New ElementType(map_width, map_height) {} 'Don't know the type; don't see it used I would recommend creating one and re-using it each time. Also, unless the image needs to become larger, there is no reason you can't reuse the Image too. This is a good question. DotNet does do automatic garbage collection. The problem is that it can only collect what it creates. Objects or memory allocated by Windows or other unmanaged (non-DotNet) code won't be garbage collected. Eventually, a discarded DotNet object will be garbage collected, and if the object was thoughtfully coded it will free up unmanaged resources when it is collected, but when it comes to unmanaged resources it is best to free them up deterministically via their Dispose method. (Some objects use a different name. For instance, a Stream has a Close method instead of a Dispose method. The point is that objects that implement IDisposable should be released.) This applies to Controls, Images, Streams, and more. As your program is written now, the picture boxes and the images they directly contain are still all present on the form and can never be garbage collected. If you re-use the PictureBox (and, preferably, the Image when possible), this problem goes away anyways.
  12. A couple of things: It seems you are creating a new control and image each time you render. Unless the map changes size (or, more specifically, becomes larger than the current buffer), I don't see the need for a new image, and unless you need two maps shown simultaneously, there is no need for more than one picturebox. It also doesn't look like you are disposing the images. If possible, it would be best to re-use the control and image. Also, you should probably break the code up into more functions. You have numerous subtasks thrown into the single function and it makes it much harder to understand. Also, if you are done with the images in unique_images at the end of the sub, you should dispose of them there and then (before exiting the sub). As is, it looks like you never dispose of them. Finally, I believe that when you add a control to a form, by default it appears beneath all other controls (this is standard Windows behavior). That being the case, since you are creating a new control each time, it will be concealed beneath the previous picturebox. So, you can either re-use the existing picturebox or remove the old one.
  13. SetWindowPosition, along with WindowLeft and WindowTop, specify the location of the "view window" within the console's buffer. In other words, this seems to deal with scrolling within the console, and not the actual window on the desktop. As far as I can see, the console class does not provide what you are looking for. This code project article appears to address this need, among many others.
  14. Do you need a particularly specific graphic? Windows includes a crosshair cursor by default, which you could specify as the contianing control's cursor. someControl.Cursor = Cursors.Cross;
  15. Is the output to the print preview DC what is printed? Or will the printer have it's own DC? I don't see any code drawing to either here. I don't know how much I can really help you here, seeing as I have no experience.
  16. I have no experince with this, but shouldn't there just be a DC for the print preview image? Or do you not have access to this? Also, I'm confused by this statement:
  17. There are two ways you could do this. This first is to handle the MouseDown/Move/Up events and react to those. This is method is pretty simple. You can also skin the border "the right way", which is much more work but makes your skinned title bar/border 100% in tune with standard Windows behavior.
  18. Noob or not, stupid mistakes are a part of programming. Once in a while I'll find myself spending a solid hour trying to debug a problem only to realize that i just typed a file path wrong or something along those lines.
  19. You need to add an event handler to the Process object's Exited event. Use AddHandler or declare the variable at class-level as WithEvents and add a handler.
  20. MySql.Data is not the same as System.Data. On my machine, System.Data.Dll (2.0) is located at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll.
  21. I think the Object Test Bench would be best suited to drop-in components, such as those designed to be reusable. There is an ideal that some programmers strive for, sometimes referred to as an "orthogonal" style or model. Essentially, the point is to reduce coupling and interdependence. Generalize classes or narrow their scope and they become more re-usable and easier to modify without things blowing up. In terms of the Object Test Bench, if you code with an orthogonal style, it would certainly be easier to test your components independently.
  22. It sounds like you are a little wiser than those whiny Java fanboys. Each language has its advantages and disadvantages, and each programmer and company has its own preference. It's fine to prefer one over another, but that doesn't mean that you should boycott any.
  23. Where exactly are you calling WaitForExit? The consructor? The OnLoad method? The Load event? Also, regardless of where you call the method from, if you are doing it on the main thread it is going to freeze the UI. That means the application can't respond to user input, Windows events, or draw itself (which can lead to artifacts like those in your screenshot).
  24. Have you looked into any tutorials about this sort of subject? There really shouldn't be many controls involved. You might consider using XNA. It is surprisingly easy to make a 2D game with (it even comes with a decent sample platformer). If you want something simpler, you can make a WinForms-based game using GDI+, just don't expect much in terms of performance. Either way you want to be drawing everything into a single image and showing that on-screen in a single control or directly on a form. When you say you dan't want to make a 2D game using tiles, what do you mean? You are opposed to a tile-based game, or a specific implementation?
  25. This is already explained in this thread that you are grave-digging. If you have a more specific question, such as "what is a linefeed?" by all means, ask, but in a new thread please.
×
×
  • Create New...