
rbulph
Avatar/Signature-
Posts
398 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by rbulph
-
Is it possible to have a reference to a generic type independent of the Type used for its declaration. e.g: Dim r as new List(Of String) Dim k as List = r 'Editor won't allow this And if there is a way of doing this, how can you find out what the relevant Type for k is?
-
OK, thanks, that all seems fair enough.
-
Is it good programming practice to declare a variable with the same name as the name of the class it belongs to? i.e. Dim Employee as Employee I suppose if you use a different name you can use the class name to get a drop down showing just the shared methods and properties, which is a small argument against doing this. Otherwise, are there any issues?
-
PathPoints.SetValue appears to have no effect.
rbulph replied to rbulph's topic in Graphics and Multimedia
Re my first question I suppose that the path is stored as a series of arcs and lines etc., not as points so the points are just something that's calculated for my use to get some understanding of the path. The PathPoints property seems to be more like a function than a readonly Property. For the second question, perhaps I didn't express myself very clearly. I don't simply wish to add a point, but I want to extend the path from its end to that point. I'm just querying whether there isn't an inbuilt method to allow me to do this which would save me getting hold of the value of the last PathPoint each time before I do it. I'm surprised that there appears not to be, but if this is indeed the case, it's not a problem. -
Maybe, if I get round to it. Otherwise I think I might just put the menu items below the separator in italics to show that they are logically something different to those above it.
-
Why does the SetValue method of GraphicsPath.PathPoints appear to have no effect? e.g.: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim h As New Drawing.Drawing2D.GraphicsPath h.AddLine(New PointF(0, 0), New PointF(10, 10)) Debug.Print("Before" & vbTab & h.PathPoints(1).ToString) h.PathPoints.SetValue(New PointF(20, 20), 1) Debug.Print("After" & vbTab & h.PathPoints(1).ToString) 'remains 10,10 End Sub End Class And, in a similar vein, can I not just add a point to the end of a GraphicsPath without having to resort to a procedure like this: Protected Shared Sub ExtendPath(ByRef P As Drawing2D.GraphicsPath, ByVal PNew As PointF) 'I just want to add a point at the end of the path, but it seems I always have to add a line. If P.PathPoints.Length > 0 Then P.AddLine(P.PathPoints(P.PathPoints.Length - 1), PNew) End If End Sub?
-
Got it. Just need to specify the argument for the culture parameter - Nothing will do.
-
I still get the error "Constructor on type 'WindowsApplication1.x1' not found."
-
I'd like to use Activator.CreateInstance with a non-public constructor for a class of mine. Here's my code: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Activator.CreateInstance(GetType(X1), Reflection.BindingFlags.NonPublic, Nothing, New Object() {8}) Dim j As New X1(8) End Sub End Class Public Class X1 Friend Sub New(ByVal p As Long) MsgBox(p) End Sub End Class but in spite of the use of the NonPublivc flag, I get the message that the constructor is not found. Maybe I need to set the binder parameter to something, but I've no idea what. Anyone know how to go about this?
-
Thanks, have installed it. It took an eternity to install, including 15 minutes while it displayed the message "Time remaining: 0 seconds", but the VS does now seem to be a bit more responsive. I didn't need to install the pre-patch patch.
-
I'm running Visual Studio 2005. Does anyone have any views on whether it's worth downloading the service pack available here http://www.microsoft.com/downloads/details.aspx?FamilyId=BB4A75AB-E2D4-4C96-B39D-37BAF6B5B1DC&displaylang=en? I was prompted to look for the service pack because I just reloaded my application only to find that all of the toolbar buttons had disappeared and I now have to reinsert them. I wonder if the 6GB of the service pack will help to avoid this sort of thing in future or if it will simply create more problems. I know this thread relates to a different service pack, but it has got me worried - http://www.xtremedotnettalk.com/showthread.php?t=100811&highlight=service+pack
-
Ah! I was adding ToolStripButtons rather than ToolStripMenuItems. Correcting that has fixed it. Any thoughts about the separators?
-
I have a context menu that has a few items added at design time and further ones that I add at run time. For the former ones the whole row is highlighted when the cursor passes over it, but for the latter, just the word that it contains is highlighted. This doesn't look very good. Any idea what's causing it? Also, I'd like to have two different levels of menu separators, one more pronounced than the other. Is there any easy way to achieve this? If one could just be twice as thick as the other that would do.
-
Thanks, I knew it had to be there somewhere. I see this forum now has some sort of contextual advertising. My use of the word "long-winded" seems to have led to an offer for $300 free at CaesarsPalace.com. How kind of them!
-
Is there a built in function that will take two rectangles and return the smallest rectangle that contains them both? I've looked under the Rectangle object and can't find anything. I can do: With Rectangle2 R = Rectangle.FromLTRB(Min(R.Left, .Left), Min(R.Top, .Top), Max(R.Right, .Right), Max(R.Bottom, .Bottom)) End With But it's a bit long-winded.
-
Hadn't noticed that you could add inherited forms and controls in this way, so thanks for pointing it out.
-
Interestingly there is a case here where the autogenerated warning: 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. would not seem to be valid. If you have a container control in Form1 and want to add a control into it in Class1 then you cannot do this with the Windows Form Designer. It seems you're best doing this by adding code in the InitializeComponent sub of Class1.
-
OK, if I create Class1 by adding a standard form to the project and having that inherit from Form1 rather than Form, everything works as expected. So by comparing the code in that form and in Class1 I can see that Class1 needs the following tag: <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>. That fixes the problem. Maybe Class1 also needs this code from the form, although I confess I don't know what it does: 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer
-
I want to inherit from a form. When I try this I find that I can add controls to the inheriting class easily through use of the Toolbox and that class's designer, and all looks OK. The code for the new controls appears in an InitializeComponent method for the inheriting class. But when I want to create an instance of the inheriting class at run time, nothing that I have done to its designer is apparent. It seems that the InitializeComponent sub of the inheriting class is not happening. An example might make this clearer: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f As New Class1 f.Show() End Sub End Class Public Class Class1 Inherits Form1 Private Sub InitializeComponent() Me.CheckBox1 = New System.Windows.Forms.CheckBox Me.SuspendLayout() ' 'CheckBox1 ' Me.CheckBox1.AutoSize = True Me.CheckBox1.Location = New System.Drawing.Point(69, 173) Me.CheckBox1.Name = "CheckBox1" Me.CheckBox1.Size = New System.Drawing.Size(81, 17) Me.CheckBox1.TabIndex = 1 Me.CheckBox1.Text = "CheckBox1" Me.CheckBox1.UseVisualStyleBackColor = True ' 'Class1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.CheckBox1) Me.Name = "Class1" Me.Text = "C1" Me.Controls.SetChildIndex(Me.CheckBox1, 0) Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox End Class Make sure that Form1 and Class1 are in different modules in the Explorer window so that the designer of each can be seen. If you look at Class1 in its designer you will see a checkbox and its title is "C1". But when you run the project it looks exactly like Form1. So should I simply remove all the code from Class1's InitializeComponent method and put it into the Class1_Load event?
-
Like this Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With Me.PictureBox1 Dim b As New Bitmap(.Image.Width, .Image.Height) b = .Image Dim s As Integer For n As Integer = 1 To .Image.Width For m As Integer = 1 To .Image.Height Dim q As Color = b.GetPixel(n - 1, m - 1) If q.G = 0 And q.R > 250 Then s = s + 1 'plan had red infill. Check for no green as well so white is excluded. Next Next MsgBox(s) End With End Sub
-
The image has been produced by scanning a diagram, maximising the contrast, and then using the fill function in MS Paint to fill in all the internal areas in green. So I'm simply interested in the area that MS Paint has filled in. So the answer to your question is simply "whatever green MS Paint has provided." I've found that it doesn't take my computer more than a minute to check each pixel in the diagram, and it's easy to code, so that's what I've now done in fact.
-
How can I calculate the green area in the attachment? Or simply the number of green pixels it contains would be enough to get me there.
-
It seems to me that the BindingFlags.FlattenHierarchy flag has no effect. Public fields of parent class types are returned by the GetFields method whether you have this flag or not. Can anyone shed any light on this? For my purposes I'd prefer not to have any inherited fields since I really want the private ones, and I can only get these by looping through the parent classes. Sample code below: Imports System.Reflection Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim j As New aclass Convert(GetType(bclass), j) End Sub Friend Sub Convert(ByVal t As Type, ByVal OldInstrument As Instrument) 'Facility to simulate conversion of an instrument of one type into another. 'Loop to find the first shared parent type of t and source. Dim sharedbaseclass As Type = t Do Until sharedbaseclass.BaseType Is Nothing Or OldInstrument.GetType.IsSubclassOf(sharedbaseclass) sharedbaseclass = sharedbaseclass.BaseType Loop 'This is the new object, which is an instance of the base class. Dim NewInstrument As Instrument = Activator.CreateInstance(t) 'initialisation code, like setting parent child properties 'should be in the New event. Setting default properties should not because I don't want it done here. 'Loop through each field in the shared base class and copy the value from 'the source object to the new object. 'If sharedparenttype is t there will be no fields to loop through. For Each field As FieldInfo In sharedbaseclass.GetFields( _ BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.FlattenHierarchy Or BindingFlags.Instance) field.SetValue(NewInstrument, field.GetValue(OldInstrument)) MsgBox(field.Name) 'gives two messages - "PInstProp" and "BaseProp" whether BindingFlags.FlattenHierarchy is included or not. Next End Sub End Class Public Class cBase Private pName As String Public BaseProp As Date End Class Public Class Instrument Inherits cBase Private pInstProp As String End Class Public Class aclass Inherits Instrument Private intrate As Single End Class Public Class bclass Inherits Instrument Private denom As Long End Class
-
It could get complicated to do an undo/redo function if, as NeuralJack says, internal variables are changing with the dataset too. Is there any scope for saving different versions of the data and variables that he has as files, using serialization say, and just jumping to older versions of the relevant file when the user calls the undo function? Otherwise I feel that the code for the undo/redo is going to be scattered throughout the program, and be quite a hassle to maintain.
-
Yes, I appreciate that there's no actual conversion of one object to another going on here. But I'm trying to simulate it, as Microsoft does with toolstrip items. The only question is whether it's better to do it with Reflection or by working through every property that I have, line by line. I think the former.