Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. There are two ways to wire events at runtime: WithEvents and AddHandler. WithEvents looks neater in code and VB takes care of most of the work, but it requires a special pre-defined variable. It would be done like so: Private WithEvents PictureBox SomePictureBox Sub SomeEventHandler(sender As Object, e As EventArgs) Handles SomePictureBox.Click 'Do some stuff End Sub Sub ExampleCode() 'When we assign a picturebox to this variable the event is automatically wired. SomePictureBox = new PictureBox() 'The event is automatically unwired when another picture box or Nothing is assigned to the variable Controls.Add(SomePictureBox) End Sub The AddHandler method can be much more dynamic and is more consistent with other languages, but takes more work and is less structured. Sub SomeEventHandler(sender As Object, e As EventArgs) 'Do some stuff End Sub Sub ExampleCode() Dim SomePictureBox As New PictureBox() Controls.Add(SomePictureBox) 'We manually wire the event here. AddHandler SomePictureBox.Click, AddressOf SomeEventHandler 'To unwire the event, we would use the RemoveHandler statement. End Sub You can use either method to wire any event to a handler declared in your form. In your case you probably want to go with AddHandler.
  2. Why not have a base class that plugins can inherit that implements a settings system (the base class can pass itself to the host to be used as a key for a settings node), or just require that the plugin class pass itself to the host to be used as a key. Either way, the host can obtain the type of the object that has passed itself and store the settings by that type so that they will be persisted between instances.
  3. I highly doubt it exists. I believe you can right-click an identifier and select "Find all references" which will bring up all instances of that identifier in the project.
  4. Couldn't you just display a thoughtfully positioned context menu when a button is clicked, or is the some more sophistocated functionality that I'm missing?
  5. Re: Threads with ads Huh. I hadn't seen any of those until just now, but there they are. Well, I certainly find that to be a problem.
  6. Do you need to compress the files? If not, it is as simple as writing all of the file data into a filestream with a small amount of header data to be used to find the offset of an embedded file.
  7. I personally would use PadLeft, like Jaco, but the first parameter should be a two (for a total minimum of two characters), not a one, and there is no need to check the length of the string. All of this is assuming that your string contains a single, properly formatted integer.
  8. I've never seen one of these ads before. All I'm getting is the banner up top and the box on the right (the same when I'm logged in and not).
  9. For simple scenarios where I want the user to be able to scroll around a large picture, I display the picture in a PictureBox that is sized to contain the entire image and embed the picturebox in a Panel with AutoScroll set to true.
  10. The icon is duplicated because the MDI child icon always appears on the left edge of the menubar when the MDI child is maximized. The fact that it is scaled, I'm guessing, is caused by a menubar that is larger than the default size. You could consider setting the Icon property to null when the child is maximized and restoring it when the form is restored.
  11. One option would be to use regions to (re)implement the transparency key yourself while avoiding using layered windows.
  12. The problem is I've never done it before. I understand the concept and I hoped it would point you in the right direction, but I don't know the individual steps. I'm guessing you have to seek through the GraphicsStream or Array returned by LockRectangle and examine the raw pixel data to do your collision detection.
  13. First you need to get the System.Type object that represents the class' type. Then you can either use the Activator class to create objects, or you can use reflection on the System.Type object to get a constructor (or a MethodInfo object, to be more precise) and call that to create the object (you may also be able to use the InvokeMethod function of the System.Type object). Note that unless you are dealing with parameterless constructors things are going to get very tricky very fast.
  14. From what I can tell, the TransparencyKey is implemented using layered windows. I can't find any documentation that says so, but this page makes that claim, and it would be a reasonable explaination for why the program exhibits the same symptoms using semitranparency as when using a TransparencyKey. Also, seeing as this article states that TransparencyKey only works on Windows 2000 and later (when layered windows were introduced) and that I can't think of another reasonable way in which the TransparencyKey could be implemented, I would guess that that's how it's implemented.
  15. Not sure exactly what is going on, but try something along the lines of: vals = "".Split(New Char() {Chr(13), Chr(10)}, StringSplitOptions.RemoveEmptyEntries) Some software and OS's will use a carriage return (13) for a newline, others use a line feed (10), and others (including windows) use a carriage return followed by a line feed. Fun, huh?
  16. Well, if you are using MDX, it looks like the thing to do would be to call Device.GetBackBuffer() on your Direct3D device, which will return the rendering surface. You could then call Surface.LockRectangle to access raw data. It doesn't look like much fun, though. Like I said, raw raster data formats could vary. Info: http://www.geocities.com/foetsch/d3d8screenshot/d3d8screenshot.htm http://msdn.microsoft.com/en-us/library/bb153344(VS.85).aspx
  17. For per-pixel collision detection I would think the approach should be examining texel data for the sprite textures to identify overlapping opaque texels. I don't understand how examining the backbuffer should help in collision detection except in uncommon and very simple situations (such as a monochromatic graphics or solid-color backgrounds). But since I don't know the nature of of the application I thought I'd ask.
  18. Why do you specify a transparency key? Is this to support irregular shapes? The reason I ask is that I changed the constructor in skinnedForm.cs to... C# Code[HorizontalRule]magic hidden text[/HorizontalRule]············BackColor = SystemColors.Control; ············FormBorderStyle = FormBorderStyle.None; ············//TransparencyKey = Color.Lime; [HorizontalRule]Why are you quoting me?[/HorizontalRule] The important thing is the third line. This seemed to solve the problem. It might be related to layered windows. Or it might not. I'm not sure how DotNet implements the transparency key. [Edit]P.S. I tried running the app with no transparency key and with partial opacity and the ugly blackness came back. It looks like layered windows combined with the way that DotNet does its painting and its double buffering could be the culprit.[/Edit]
  19. Maybe you should post your calls to SpriteBatch.Draw. I'm not really sure what could be going wrong. It may be that there is some misunderstanding on how scale/origin/rotation works. I know it took my a lot of tinkering with them to get a good understanding of how to render sprites that properly rotate and scale with the correct source rectangle. I've been working on a game that uses sprite sheets for quite a while and haven't run into problems once I got things sorted out. I'm using a scale of 1.0 which renders as expected. Also, one thing that has caused me issues in the past (with MDX, but I don't think it matters) is changing my graphics card settings to override application settings (forcing anti-aliasing, mip-map levels, etc).
  20. I'm just throwing this out there, but shouldn't there be a way to get the surface for the back buffer and examine the pixel data? I couldn't really tell you where to begin and pixel formats could probably vary, but it's a thought. What is the collision testing for? It sounds like an odd way to implement collision testing.
  21. Do you want to scale the image? If you specify a scale of 1.0 or use an overload that does not accept a scale the texture should be drawn at actual size and there will be no interpolation residue. Specifying a scale of 0.5 is telling XNA to scale and not just use what's there. How are you drawing the sprites? I'm assuming you are using the SpriteBatch class.
  22. Yes, the scale you specify is a scaling factor, i.e. the size in texels is multiplied by the scale you specified to get the final size in pixels. If it is not 1.0 (100% scale) then the texture doesn't match the screen pixels 1 for 1 and has to be filtered. The default is usually linear filtering, which is medium quality. For higher quality, you could try changing the filter, like... deviceManager.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.GaussianQuad; Nearest neighbor (TextureFilter.None) would be the least blurry, but tends to look blocky.
  23. Try this. For X = 1 to 100 TextBox1.Text += "Text" + ControlChars.NewLine TextBox1.SelectionStart = TextBox1.Text.Length [i] TextBox1.ScrollToCaret()[/i] Next [/Code]
  24. There are problems with checking Control.DesignMode for modified design-time behavior. I believe, but I'm not certain, that only the Form and top-level controls will have this property set to true (meaning it won't work as expected for controls contained in controls). I know I've had problems in the past with this. Detecting design time has a few solutions.
  25. The background worker component is a good solution for simple multi threading operations. However, if you already have another multi threading solution in place, it does not make sense to convert over to the background worker component. What's more, a background worker component can't perform more than one task at once, and it has limited functionality compared to other threading classes. If your problem is more complex then a solution using System.Threading would be more appropriate. You can use separate background workers for different tasks as long as each task will never need to run multiple times concurrently. Also, the sender parameter is the object that directly raises an event. In this case, it would be the BackgroundWorker object itself. Simplicity. The background worker component is designed to handle simple multi threading situations. It was probably created in response to the extremely common problem of a GUI freezing while the program does processing. All you have to do is set a few properties and handle a few events. It has events for progress updates and completion and supports cancellation. For progress updates, you simply set WorkerReportsProgress to true, call BackgroundWorker.ReportProgress() from the background thread to report progress changes, and handle the ProgressChanged event in the UI thread.
×
×
  • Create New...