snarfblam
Leaders-
Posts
2156 -
Joined
-
Last visited
-
Days Won
2
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by snarfblam
-
Add new properties/methods to existing classes
snarfblam replied to tipudelacablu's topic in General
If you have a member of a class that is a string that is always used for a url, rather than extending System.String, you could always create a url class that contains a string. Just to demonstrate: Public Class URL Dim _URL As String Public Sub New(Address As String) Me.Address = Address End Sub Public Property Address As String Get Return _URL End Get Set(Value As Integer) 'Validate _URL = Value End Set End Property Public Sub Launch() System.Diagnostics.Process.Start(_URL) End Sub Public Function Domain() As String Dim Start As Integer = _URL.IndexOf("//") + 2 Dim Len As Integer = _URL.SubString(Start).IndexOf("/") Return _URL.SubString(Start, Len) End Function End Class -
This behavior is there for two reasons that I can think of. Firstly, for backwards compatability. Secondly, nullable types are great for database purposes where values can be null (even though their .Net equivalent can't be), but for the most part, nullables are little more than a minor convinience. It takes an extra 16 or 32 bits for .Net to store the status of whether the value is null or not (the underlying boolean is stored in 16 bits and marshaled as 32), my guess is that it is slower performance-wise (access to value is done through properties/functions), and it is easy enough for one to create a boolean to indicate the validity of a value on his own. I wouldn't expect nullables to play a large role in the .Net framework classes.
-
If a game uses fullscreen exclusive mode it is intended specifically to not have anything drawn over it. I have seen this question asked a few times, and never seen a decent answer. Honestly, the best advice I can give you is to stick your clock on top of the monitor because, otherwise, the best you will probably get for results is an extremely flickery, miscolored clock. It is not a matter of "strongest" draw methods. Your game draws itself 60 (give or take) times a second, and the only way for your clock to be visible would be to draw itself after the game draws, but before the monitor refreshes.
-
The option for this is in Tools>Options\Text Editor\Basic\VB Specific. There are two relevant options: "Automatic insertion of end constructs," (what you specifically asked about) and "Automatic insertion of Interface and MustOverride members." P.S. "Pretty Listing" is the option for automatic formatting.
-
Why not find the width of the string, and if it is greater than the size available, do some simple division and multiplication to find the size needed. [Vb] 'Limit how small the font can be Const MinSize As Single = 8.0F Dim MeasuredWidth, AvailableWidth, FontSize As Single 'Get some values FontSize = Me.Font.Size() AvailableWidth = Me.Width ' minus border width? MeasuredWidth = e.Graphics.MeasureString(Me.Text, Me.Font).Width 'Take either the current font size, or the sized-to-fit size, whichever 'is appropriate FontSize = Math.Max(FontSize, FontSize * AvailableWidth / MeasuredWidth) 'Make sure that we are at least the minimum size FontSize = Math.Max(FontSize, MinSize) 'Create The Font MyFont = New Font(Me.Font, FontSize, Me.Font.Style, GraphicsUnit.Point) [/code] That might need some tweaking, but I think it is the jist of what you need. It will also probably work better when a user has font anti-aliasing on, which allows for fractional character widths and therefore more percise sizing.
-
Wouldn't a singleton sort of approach work just fine here? [u][i][color=Blue]Private[/color][/i][/u] Sub New() '... End Sub Dim _Instance As MyForm Public Shared ReadOnly Property Instance As MyForm Get 'Create a new instance if there isn't one already or there is 'one but it's disposed If _Instance Is Nothing OrElse _Instance.Disposed Then _Instance = New MyForm End If 'Return the instance Return _Instance End Get End Property
-
Just a recommendation: you could create a second thread to wait for a process to end in order to not freeze up your app.
-
Any time a keyword is used as an identifier (not just in the declaration), the brackets are necessary to tell the compiler that the word is an identifier, with one exception: the brackets are optional for an identifier following a dot using dot notation, since the compiler can easily infer that it is being used as an identifier. ' Right Console.WriteLine([Dim].For.Next.Select.Case.Class & " and good day!") ' Wrong Console.WriteLine(Dim.For & " and good day!") ' Not necessary Console.WriteLine([Dim].[For] & "Boogity boo") ' You'll also notice that you can throw brackets where ' ever you want, whether or not they are necessary. [Console].WriteLine([MyObject].Member)
-
A quick google gave me this C# example.
-
Yes, your vbscript will definitely look for an ActiveX component. I recommend doing research on creating COM wrappers for your .Net classes (I believe, but am not sure, that you can create an ActiveX compliant wrapper). I don't know much about this, but I think studio .net comes with tools to do this.
-
RadioButton event _CheckedChanged running funtion twice [C#]
snarfblam replied to Shaitan00's topic in Windows Forms
-
Releasing generic collection memory for garbage collection
snarfblam replied to DimkaNewtown's topic in General
The garbage collection works by reference tracing. It starts with "roots" (for example, a UI element, namely a form, would be a root since the user can interact with it and raise events or trigger function calls), and traces all the references. Any isolated objects (objects that do not have any delegates or references pointing to them, and therefore can not possibly interact with any other code or UI) or isolated groups of objects are collected. When you release an entire collection, as long as nothing else (that can be traced to from a root) has a reference to the items in the collection, they are available for garbage collection. -
how to get those little lines that break up a form
snarfblam replied to fguihen's topic in Windows Forms
The shape controls from VB6 don't exist in .Net, probably since they were lightweight controls (a feature that does not exist in .net), and, although handy, were not indispensable. Two alternatives: -A label with a 3-d border style that is two pixels tall to create a 3-d separator -Implement your own painting code for the form -
How to set the Starting Index on a combobox (or similar) control?
snarfblam replied to Denaes's topic in Windows Forms
The combo box has a text property which can be set at design time to anything you would like, not necessarily from the list. Just as an example of what I mean, also note that the Text property does not work entirely as one might expect (i.e. quirky) when the combo box's drop down style is DropDownList. You can type whatever you like, but when you hit enter, the text you entered disappears. -
Exposing Functions to COM in VB.NET
snarfblam replied to 95se5m's topic in Interoperation / Office Integration
Information -
To elaborate on DiverDan's post: It is recommended that EnableVisualStyles be called before your main form's constructor, to ensure that absolutely no controls are created before the call to EnableVisualStyles (otherwise, some controls may be bounds to the wrong version of Common Controls and display incorrectly). [Vb] 'In your main form's code Public Shared Sub Main() Application.EnableVisualStyles() Application.DoEvents() Application.Run(New Form1) 'Replace with your form's name End Sub [/code]
-
Capture Active Window in VB .NET(Help me)
snarfblam replied to Wilson's topic in Graphics and Multimedia
What is the problem you are having? -
How to set the Starting Index on a combobox (or similar) control?
snarfblam replied to Denaes's topic in Windows Forms
One reason is with any style other than DropDownList, it is not only possible but very likely that what the combo box contains for text does not match any items in the list and has no index. You can't add/remove a property based on the value of another property. Either it is there or it isn't, and if it is, the behavior of the SelectedIndex property would be quirky in the event that the combo box isn't a DropDownList. It's not a very good reason to not expose the SelectedIndex to the property grid, but it's the only one that I can think of. I certainly agree that you should be able to modify it at design time without inheriting the class and overriding or shadowing the property, but Microsoft appearently doesn't. -
If you are the person writing the class then you could supply a System.ComponentModel.DescriptionAttribute for a class and extract that attribute from the DLL with reflection. [vB] 'Supply a description <System.ComponentModel.Description("A class that I made.")> _ Public Class My_Class 'This function will load and display the description Public Shared Sub LoadAndDisplayAttribute Dim ClassType As System.Type = GetType(My_Class) 'Get a list of description attributes Dim Attributes As Object() = ClassType.GetCustomAttributes( _ GetType(System.ComponentModel.DescriptionAttribute), False) If Attributes.Length > 0 Then 'Only one description attribute may be applied to a class definition, 'so we will assume that our description is Attributes(0) MessageBox.Show(CType(Attributes(0), System.ComponentModel.DescriptionAttribute).Description) End If End Sub End Class [/code]
-
Not really weird. In most applications, it is not necessary to declare all the controls as friend; I seldom access a form's controls from another class, and even when I need to, it is only one or two controls I need to access, and I make a public function to do it. Not to mention, listing all the controls with the form's members gives you twice the headache with intellisense. It clutters things up. My best guess is that the only reason that VB declares all the controls as Friend by default is for backwards compatability.
-
[Vb] 'Create an image to persist Dim MyBitmap As New Bitmap(MyPictureBox.Width, MyPictureBox.Height) 'Persist, Image. Goooood image. MyPictureBox.Image = MyBitmap 'Now we can manipulate Image. Dim MyGraphics As Graphics = Graphics.FromImage(MyBitmap) [/code] Chances are you will want the Graphics object, and maybe the Bitmap object, to be of class scope.