Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. Nope. Why don't you just load the image as an attachment?
  2. Would it be unacceptable to display the hint below the text?
  3. You can get the font used for ToolTip. It might be in the SystemInformation class. If not, it should be get-able from the Windows API. That is still an iffy way to find a ToolTip size. Why, if you don't mind my asking, are you looking to find the size of a ToolTip?
  4. I wish there was an option for the textbox to do that. I think you have the right idea with your solution, though. My only recommendation is that you might want to subclass the combo box to make this solution easier to implement. Public Class BetterComboBox Inherits ComboBox 'Track the selection when the user leaves the combo box Dim LastSelection As Integer Public Overrides Sub OnLostFocus(e As EventArgs) LastSelection = SelectionStart End Sub 'If the option is enabled, use the same selection 'that was had when focus was lost Public Overrides Sub OnGotFocus(e As EventArgs) If _DontSelectEverything Then Select(LastSelection, 0) End If End Sub 'Present the developer with an option to override 'default selection on focus Private _DontSelectEverything As Boolean Public Property DontSelectEverything As Boolean Get Return _DontSelectEverything End Get Set(Value As Boolean) _DontSelectEverything = Value End Set End Property End Class I didn't test the code, but it should give you the idea.
  5. When using your most recent suggestion the load time for the textures is exceptionally long. My current solution is to draw tiles onto a tile sheet, load the tile sheet, use GDI+ to chop it up, create an array of textures, save the textures to a single file, and load textures from that file at runtime. It sounds like a difficult process but I have it automated for the most part and the load time is significantly smaller. I will try your recommendation of using a single texture and fractional coordinates, but I am a little uneasy about the fact that tile data is stored in the vertex buffer, which adds a layer of complexity to the whole operation. When doing something such as animating a particular tile, instead of simply changing a tile index each frame, I will have to lock the buffer, update the texture coordinates, then unlock the buffer.
  6. The idea has already occurred to me, but I am reluctant to use that method. In my experience, tile-based operations with bitmaps tends to be very slow in GDI+. But right now my options are either that or the use of texture coordinates.
  7. That is up to the end user. Microsoft owns the copyright to wmp.dll and they are in charge of distributing it. If your application depends on that library then the user must install the application to which it belongs. All you can really do is add the application as a system requirement and/or provide a link to Microsoft.com where the user can download and install the application.
  8. I understand that rendering multiple textures without changing the texture or, better yet, with a single call to DrawPrimitives is faster than setting the texture and rendering each tile, but what I am programming is intended to be a re-usable engine with capabilities similar to that of the NES or SNES (if you are familiar), in which case said optimizations are difficult to implement. Another concern is that older hardware will have issues with the larger textures and fractional texture coordinates that would be used for sprite sheets. I have heard of similar problems on older hardware using MDX. I would hate to get far into the process of creating an application only to find that there was a graphical issue with a fundamental aspect of my rendering engine. I know I sound awfully stubborn, but don't get the wrong idea. I'm just voicing my thought process. I am considering using your proposed solution.
  9. I have 1 gig of ram and a 2 Ghz AMD on my personal pc and I usually have one or two instances of C# Express and/or VS 2003 open, but lately I've had three or four open at a time. There is a short lag, 5 to 10 seconds, sometimes a little longer, when I switch from one to another that hasn't been used for a while, but that's it. I also usually have Photoshop and FireFox (with a dozen or so open tabs) open. Having less virtual memory might speed things up a little because Visual Studio will be less lazy about garbage collection, but if you cut the virtual memory back too much you (obviously) might start running out of memory. Interestingly enough, my virtual memory usage tends to stay very close to the initial allocation I specified in the control panel.
  10. What I have right now is a grid of vertices where vertices are stored in a single vertex buffer and shared between tiles. That is, the right two vertices of the tile at (10,10) are the two vertices that are used for the left of (11, 10). In order to do this I need to have tu/tv coordinates that correspond to the grid. In other words, the vertex at 7, 4 has value of tu = 7, tv = 4. It seems like a more efficient (albeit less dynamic) way to use memory. If it becomes necessary, though, I will define four vertices per tile. My other concern then is that it would be difficult to ensure that the texels align with the screen pixels when using fractional texture coordinates. Is this common practice? If I am off by even a tiny amount, wouldn't it cause the texture to be stretched and bilinearly (or anisotropically or whatever) filtered?
  11. I don't understand the question. You specify the location when you call DrawString. What specific aspect of the rendered text do you want to measure?
  12. I'm really into old school video gaming (i.e. NES/SNES/Genesis). I'm getting into DirectX, using Direct3D to make 2D games. Given a bitmap that contains a number of tile images (i.e. a tile sheet, aka sprite sheet), does anyone have any tips for loading up the bitmap and chopping it into textures (one texture per tile)? Or any other relevant recommendations while we are at it? I've only started learning yesterday, so any advice would be helpful, and it seems to be pretty difficult to find specific, helpful information on the topic.
  13. That is all a matter of how often this will be happening. I think it will be perfectly acceptable for this operation to happen once and a while, but if you are looking at a busy server and this is a common function then it could slow things down. Maybe running the code on a low-priority thread could help prevent things slowing down, but I'm really not sure about that. The best way to find out, I would think, is to actually test it and see what the impact is.
  14. It becomes a little more complicated if you want to choose the quality that the jpeg will be saved with, which, of course, has a big impact of file size (and equally important, appearance). This is the code I used in one of my apps to specify the quality to save a jpeg with. Dim Quality As Integer = 40 ' Medium/High quality 'Get a list of codecs Dim Codecs As Imaging.ImageCodecInfo() = _ Imaging.ImageCodecInfo.GetImageEncoders Dim JpegCodec As Imaging.ImageCodecInfo 'Find the jpeg codec For Each codec As Imaging.ImageCodecInfo In Codecs If codec.MimeType = "image/jpeg" Then JpegCodec = codec End If Next 'If not found, throw an exception If JpegCodec Is Nothing Then _ Throw New Exception("Jpeg codec not found."); 'Use an EncoderParameters to specify quality Dim Prams As New Imaging.EncoderParameters Prams.Param(0) = New Imaging.EncoderParameter(Imaging.Encoder.Quality, Quality) 'Save Image MyImage.Save(cdgSave.FileName, JpegCodec, Prams)
  15. I don't think that time spent constructing strings should be included in the processing time period. That is a whole different thing and a whole different process of optimization. Data should probably be stored, whether in an array of ints or a List<int> or what, during the course of calculation. If you include string construction in the loop then the results become distorted, and as you optimize it can be difficult to tell how much the optimization helped which part (calculation or presentation) and where you could optimize more. A big benefit to separating the two tasks is that the prime calculation code will be more centralized and cut down on things like page faults and branch mis-predictions. In other words, just separating calculation and presentation, without otherwise optimizing, could give you a small boost.
  16. There is one difference between the two methods: If Object.ReferenceEquals(obj.GetType(), MC1.GetType()) Then 'obj is an instance of MyClass1 End If If TypeOf obj Is MyClass1 Then 'obj is instance of MyClass1 or a derived class End If
  17. Updated Reflector class to climb inheritance hierarchy to find private members of base classes.Reflector.zip
  18. FlattenHierarchy actually refers only to static members. I did not realize this at the moment I posted it, though. It provides access to protected and internal static members of base classes. As far as internal members being technically public in terms of reflection, that is hard to either agree with or disagree. Yes, I can declare a field with the same name as a private field in the base class, but can't my deriving type defined in a separate assembly declare a field with the same name as the base class' internal field? Note the VB keyword used to declare a member internal: Friend. This modifier is meant to indicate that a member is not actually part of a classes interface at all. Maybe they are "more public" than private members, but I would say that the same "non-public" protection principal still applies. At the same time, I understand where you were going with what you said. It makes some sense that inheritance plays no role in visibility with internal members but does with private members and that that difference is manifest in reflection, but I am still troubled by the fact that ultimately private members are accessible yet you have to loop through System.Type.BaseType properties to get the right class. They are protected, but they aren't. It is kind of a paradox, I suppose. The behavior supports the spirit of OOP, but it does not support the spirit of private reflection. The two are mutually exclusive. If it were up to me, though I would have chosen to support the latter when it came to implementing reflection.
  19. I knew I must have been missing something obvious. Unfortunately, the documentation isn't at all clear on accessing private/internal members. This is what it has to say about BindingFlags regarding nonpublic members:
  20. I was working with my Reflector class when I ran into a little problem, and after a couple of hours of debugging and toying around and researching I can't seem to make any progress. What I am trying to do is access a private field (dialogResult) on an instance of a class that derives from Windows.Forms.Form. I found it very interesting that I could access the dialogResult field from a System.Type that refers to System.Windows.Forms.Form, but not a System.Type that refers to the actual runtime type of my derived form. I found it even more interesting that while I could access the _message field of an exception with a System.Type that refers to System.Exception, I could also access it with a System.Type that refers to the derived System.UriFormatException. How very inconsistent... The code I was using was the following: [/color][Color=DarkRed]Exception [/Color]ex = [Color=Blue]new [/Color][Color=DarkRed]UriFormatException[/Color]("Moo"); [Color=DarkRed]Reflector [/Color]Rex = [Color=Blue]new [/Color][Color=DarkRed]Reflector[/Color](ex); Rex.PrivateAccess = [Color=Blue]true[/Color]; [Color=DarkRed]MessageBox[/Color].Show(Rex.GetField("_Message").ToString()); [Color=DarkRed]Reflector [/Color]Me = [Color=Blue]new [/Color][Color=DarkRed]Reflector[/Color]([Color=Blue]this[/Color]); Me.IgnoreCase = [Color=Blue]false[/Color]; Me.PrivateAccess = [Color=Blue]true[/Color]; [Color=DarkRed]MessageBox[/Color].Show(Me.GetField("dialogResult").ToString()); [Color=Green]// I also tried the following InvokeMember equivalent and got the same result: [/Color][Color=DarkRed]Exception [/Color]ex = [Color=Blue]new [/Color][Color=DarkRed]UriFormatException[/Color]("Moo"); [Color=Blue]object [/Color]exMessage = ex.GetType().InvokeMember( "_message", [Color=DarkRed]System.Reflection.BindingFlags[/Color].Instance | [Color=DarkRed]System.Reflection.BindingFlags[/Color].FlattenHierarchy | [Color=DarkRed]System.Reflection.BindingFlags[/Color].NonPublic | [Color=DarkRed]System.Reflection.BindingFlags[/Color].GetField, [Color=Blue]null[/Color], ex, [Color=Blue]null[/Color]); [Color=DarkRed]MessageBox[/Color].Show(exMessage.ToString()); [Color=Blue]object [/Color]thisDialogResult = [Color=Blue]this[/Color].GetType().InvokeMember( "dialogResult", [Color=DarkRed]System.Reflection.BindingFlags[/Color].Instance | [Color=DarkRed]System.Reflection.BindingFlags[/Color].FlattenHierarchy | [Color=DarkRed]System.Reflection.BindingFlags[/Color].NonPublic | [Color=DarkRed]System.Reflection.BindingFlags[/Color].GetField, [Color=Blue]null[/Color], this, [Color=Blue]null[/Color]); [Color=DarkRed]MessageBox[/Color].Show(thisDialogResult.ToString());[/Code] The reason that I used [Font=Courier New]UriFormatException[/Font] is because it is defined in a different assembly than [Font=Courier New]System.Exception[/Font] (I thought that the issue might have had to do with the fact that [Font=Courier New]System.Windows.Forms.Form[/Font] is defined in a different assembly than my form class). I am stumped. Can anyone think of anything?
  21. It just so happens that I have already written the code for you, and it can be found right here within Xtreme .Net Talk. Look.
  22. Maybe I'm missing something, but why can't you store the original RTF? When the application closes or a new document is opened compare the current RTF to the original RTF and if they are not equal ask the user if he would like to save.
  23. I believe that all GUI components must be run on the same thread. Windows sends messages only to the thread that is running the message pump and these messages are all dispatched on that thread. It might be possible to call Application.Start(someForm) on your second thread, but I'm not too sure that windows would allow an application to have two message pumps.
  24. Call the SendToBack() method of the toolbar. The order in which the docking of controls is processed depends on their z-order.
×
×
  • Create New...