Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. Just a warning about this code: the unsespecting user will lose the data he has stored on the clipboard. Possible solution: grab what is on the clipboard and restore it after your screen capture operation.
  2. Unfortunately, this is the basic situation: at run time components do not have a name. Controls have a Name property which stores the name in memory during runtime. The designer uses the same name for both the identifier used in code and the Name property, however if you don't use the designer it is very possible for your identifier and your Name to differ. The two are generally, but not necessarily, the same. Components do not have a Name property. The name you enter into the designer only determines the identifier to be used in code. The name you put into the designer does not exists in the jitted code. It essentially becomes nothing more than a memory offset. Depending on your needs, the best solution will vary, but something like this might suit your needs: Dim Franky As Component 'At some point assign a reference Dim Jules As Component 'At some point assign a reference Public Function NameOf(Item As Component) As String If Item Is Franky Then Return "Franky" If Item Is Jules Then Return "Jules" End Function 'Example: MessageBox.Show (NameOf(Jules)) Excuse my very rusty C# System.ComponentModel.Component Franky; //At some point assign a reference System.ComponentModel.Component Jules; //At some point assign a reference String NameOf(System.ComponentModel.Component Item) { if (Item = Franky) return "Franky"; if (Item = Jules) return "Jules"; } //Example MessageBox.Show(NameOf(Jules));
  3. Ultimately, performing very similar tasks with different types of data is a difficult situation to handle elegantly. If you are creating the functions that will be called through a delegate, a possible solution to this situation (one that I believe can be seen in places in the .Net framework) is to create a base class which contains the bare minimum or none of the data that needs to be passed, and then derived class(es) that can hold additional data. Instantiate the base class, or to pass more information instantiate a derived class, then pass it to the delegate which accepts your class and acts based on the type of the object. I know you are coding in C# but I'm sure that you can figure out the jist of this VB: 'This is our one and only delegate signature, MessageBoxFunction Public Delegate Sub MessageBoxFunction(ByVal Info As MessageBoxInfo) 'This class encapsulates information to be passed to a delegate 'Here we only have a message Public Class MessageBoxInfo Public Message As String Public Sub New(ByVal Message As String) Me.Message = Message End Sub End Class 'Derived classes can vary or extend the information 'Here we add a title to the message Public Class DetailedMessageBoxInfo Inherits MessageBoxInfo Public Title As String Public Sub New(ByVal Message As String, ByVal Title As String) MyBase.New(Message) Me.Title = Title End Sub End Class Class TestClass 'This is the function we will be passing different sets of data to via delegates Public Sub ShowMessageBox(ByVal Info As MessageBoxInfo) 'Act based on the type of object passed If TypeOf Info Is DetailedMessageBoxInfo Then MessageBox.Show(Info.Message, DirectCast(Info, DetailedMessageBoxInfo).Title) Else MessageBox.Show(Info.Message) End If End Sub 'Here we call the same delegate twice, sending only a message the first ' time, and a message and title the second Public Sub DoTheDelegate() Dim MyFunction As MessageBoxFunction = AddressOf ShowMessageBox Dim Info1 As New MessageBoxInfo("Passing Data!") Dim Info2 As New DetailedMessageBoxInfo("With Style!", "Passing Data") MyFunction(Info1) 'Send message MyFunction(Info2) 'Send message and title via the same delegate End Sub End Class You can use a similar solution for return types if you need to return different kinds of data through the delegate.
  4. Considering the nature of the task, I can't see how this can be done without loops. I think that your method is as straightforward as possible.
  5. I know that I am not DiverDan, but anyways... CType is a more general purpose casting/converting statement. It will convert strings to integers, integers into strings, either of those into objects... any valid cast or conversion. DirectCast is a simple type cast, it does no converting. The cast must be valid without conversion, or an error will occur. You can DirectCast a Form to a Control; since Form derives from Control, all forms are controls. If you have a variable of type control that points to a Form, you can DirectCast to a Form. Your problem is not whether you used CType or DirectCast. You were, somewhere in your code, trying to convert from a string ("chkSelected") to an integer and the conversion is not valid. You could swap CType for DirectCast in the code above and it will still work fine.
  6. Have you tried explicitly loading textures into the managed pool? I don't know if that is the problem, but I have seen similar issues. [Vb] m_TextureHash[ imageName ] = Texture.FromBitmap( m_Device, theImage, 0, Pool.Managed); [/code]
  7. They are not controls, they are components, but they are not found in the ToolBox by default. You can instantiate them in code. [Vb] Dim X As New System.Net.WebClient Dim Y As System.Net.WebRequest = System.Net.WebRequest.Create(MyUri) [/code]
  8. You can't dynamically name variables like that. It wouldn't really work. The names often dissapear during compilation anyways. Disassemble some IL and you will find variables named Int1, Int2, Int3 instead of their original names. So, if you want to access data by name, you might want to consider using a hash table. If you want to access it by index, simply use an array. The easiest way to do what it looks like you want to do would be the array. Dim simon As String() '... simon = New String (myArray.Count - 1) {} 'Create new array 'We now have variables: simon(0), simon(1), simon(2), simon(3)... simon(myArray.Count - 1) Using either a hash table or array you should be able to dynamically allocate and access data the way you need to, but this is pretty basic stuff, so you might want to look into MSDN or search google for some tutorials.
  9. Are you looking for a code editor or an IDE? There are lots of free code editors with syntax hilighting for dozens of languages. As far as regions and intellisense/autocomplete, that is far less common. SharpDevelop allows you to set up your own syntax hilighting (but setting it up hurts my head). I don't know if you will be able to use regions with anything besides VB and C#.
  10. snarfblam

    Sleep

    If you don't want to use a timer, you can also make your own pause loop. Sub Pause(ByVal Milliseconds As Integer) Dim EndTime As Long = Environment.TickCount + Milliseconds Do While EndTime > Environment.TickCount Application.DoEvents() Loop End Sub
  11. You can create a graphics object and use the Graphics.MeasureString method, which allows you to specify a width (which should be the width of the label). It will return the rectangle that would contain your text, whose height could be divided by the height of a single line to determine the line number. (I haven't tested this) Function LineCount(ByVal Label As Label) As Integer Dim g As Graphics = Label.CreateGraphics Dim LineHeight As Single = g.MeasureString("X", Label.Font).Height)) Dim TotalHeight As Single = g.MeasureString(Label.Text, Label.Font, Label.Width).Height Return CInt(Math.Round(TotalHeight / LineHeight)) End Function
  12. A maximized window's bounds will be close to the desktop working area, but slightly larger (because of borders?). The discrepancy could be recorded when the program starts and used whenever you want to examine the working area, but, still, there is no event or anything that I know of for when the working area has changed.
  13. The fact of the matter is that we really don't know what is going on inside of your control and it is hard to give advice. The best one can do is tell you that you are trying to use an object you haven't created. The control probably tries to access something that isn't created until LoadValues is called. Check you're Resize event handlers, Invalidate event handlers, etc. to see if they access an object that wouldn't be initialized at design time (since the LoadValues function probably won't get called at design time). Check any initialization code that will be called at design time. Throw in some message boxes, or debug output or something.
  14. Besides the fact message boxes aren't really the VB6 way (we did have Debug.Print in VB6, no?), MessageBox can be better; it pauses execution and you are certain to see the information, and you can break execution if the data doesn't seem right. Of course, it also requires removal or conditional compilation, and most of what you can do with a messagebox can also be done with breakpoints. Ultimately a matter of preference, I suppose.
  15. To be honest, I got it, and as admittedly blunt as the response was, I didn't detect any anger, so lets not start slinging insults. Anyways, if you need to display HTML in an RTF box, perhaps there is some way to open the HTML in a WebBrowser control, copy it, and paste it into the RTF box. The RichTextBox class supports pasting of images and formatted text. As to exactly how you would go about that, I don't know.
  16. This is happening in the designer when you drag it out from the toolbox? It sounds like an error is occuring inside the control. Is it .Net? VB6 ActiveX? If it is something of your creation, you might want the control's source code for errors or debug it. If not, you might want to check and ensure compatability.
  17. Yes, I bought ".Net Game Programming with DirectX 9.0, VB.Net Edition." Steer away from it. It is a purchase that I regret.
  18. A while ago I watched a video on microsoft.com (I think this is it, but I don't have time to watch). It was one of Microsoft's "shows." A game (perhaps Half-Life, but I'm not sure), which was written for unmanaged C++, was compiled as managed code. Note that this required no code changes at all and the end product did not use garbage collection and certain other managed features, just MSIL, i.e. managed code. The managed code version ran at 50 fps vs. 60 fps native code, but you also need to take into consideration that the code was optimized for a native code compiler and not an MSIL compiler. Also, the ATI Catalyst software requires the .Net Framework.
  19. Instead of copying the arraylist to a new array, you can create a strongly typed array from the arraylist (I think that this is easier), by using the ToArray() function. Also, like the Replace() function, the Join() function is static (Shared in VB), and does not change the string that you call it from, but rather, returns a new string. Watch out for functions like that. That would mean that you should be using allroles2 = allroles2.Join("|", allroles1) '-or- allroles2 = String.Join("|", allroles1) Both are equivalent but the second syntax is considered better practice because it makes it clear that the function being called is static, i.e. it is not associated with any instance. Function JoinRoles(Roles As ArrayList) As String 'Have the ArrayList create the array for you Dim RolesArray() As String = DirectCast(Roles.ToArray(GetType(String)), String()) 'Use the [b]shared[/b] Join() method to concatenate all the strings Dim AllRoles As String = String.Join("|", RolesArray) 'Output results for debug Debug.WriteLine("AllRoles = " & AllRoles) Return AllRoles End Sub
  20. I tried the attatched code and it worked, but it was buggy.
  21. In VB? C#? I think that this question goes into syntax specific, although I think that VB and C# have similar delegate syntax. If VB you do delegates like this: 'Define the delegate (return type, if function, and parameter types) Delegate Sub MyDelegate(ByVal Value As Integer, ByVal Message As String) Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click 'Get function pointer (delegate) to Delegadoo Dim G As New MyDelegate(AddressOf Delegadoo) 'Call Delegadoo G(4, "The number after 3 is ") End Sub 'Function we will create a pointer to Private Sub Delegadoo(ByVal Param1 As Integer, ByVal Param2 As String) MessageBox.Show(Param2 & Param1.ToString) End Sub In other words, you pass the arguments the same way you do to a normal function. What code are you using? Or, what is the difficulty?
  22. Ah... I could have sworn there was a way to create a gradient pen, but no matter how hard I looked, I couldn't find a GradientPen or LinearGradientPen, so I concluded that I was wrong. I guess not; I was just looking for a different class when all I needed to do was look at the pen's constructors.
×
×
  • Create New...