Overriding Default Property Values In .Net, WinForms?
Jan 9, 2010
I create a class "Planet" that can be inherited. One of the purposes of inheriting is to create a template with different default property values. Eg:
Public Sub New
MyBase.New
MyBase.ForeColor = Red
[code]....
Now, to stop the defaults serializing in the InitializeComponent method, there are 2 ways:If I've implemented the properties using the 'DefaultValue' attribute, and made them overridable, the attribute can be overriden with the new value.The problem with this is, there's no way to just make just the attributes overridable, as opposed to the whole property.I could implement every property with protected Reset'PropertyName' and ShouldSerialize'PropertyName' methods. However, this is a bit of a pain in the arse.Is it, generally, an important consideration to ensure that someone who overrides your base class has the ability to change the default values of a property?
View 1 Replies
ADVERTISEMENT
Aug 19, 2010
In a VB.NET Winforms application, I have a form that contains both a datagridview and a textbox. I have some menu item entries that have shortcuts of Ctrl + X, Ctrl + C, and Ctrl + V that operate on the datagridview. However, these override the default cut, copy, and paste shortcuts for the textbox. How can I make the menu shortcuts only apply when the datagridview has focus?
View 2 Replies
May 28, 2010
Is it possible to set a project default for VB.NET winforms projects so that the default Modifier for controls added to winforms is Private (not Friend)?I know there's a "modifiers" property in the properties window so I can set it for each individual control however I would like to change the project so from now on myself and other developers have to specifically decide to change from friend to private. (Which I would strongly discourage them from doing).I believe there is no way of doing this, but on another forum a while ago someone mentioned it would be possible with an add-in (but didn't name the add-in or where to get it).
View 1 Replies
Jan 12, 2010
What is the difference between these two methods for defining property value defaults? [code] Is there a reason to use one method over the other for defining the default property values in a class?
View 24 Replies
Jun 1, 2012
I have a custom version of a label control (built using a user control). While working in the designer, I want to intercept the setting of the Name property (in the properties panel) and use it to generate the Text property. That is, if I enter "lblFirstName" into the Name property of the properties panel I want to immediately see that the Text property is set to "First Name". Parsing the Name property is not the issue; I can do that.
I have tried to overload/shadow the Name property (since "Overrides" is not allowed) to essentially add this "aspect" to our custom label control but it doesn't seem to hit the Shadowed method at design time. It does hit the Shadowed method at run time if manipulated via code. The point is to avoid double the work as the label text and the label name are essentially the same. The only difference is one is formatted to be human friendly and the other machine friendly.
<System.ComponentModel.Browsable(True),
System.ComponentModel.ParenthesizePropertyName(), System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Visible)>
Public Shadows Property Name As String
[Code] .....
This may be a matter of picking the right attributes. Conversely, if it's an easier alternative, we could allow setting the Text property to set the Name property. I doubt this would be easier since it should also reflect the new name in the Designer.vb code, not just in the label's Name property itself.
View 1 Replies
Mar 24, 2010
I am using a Hashtable which stores unique names and objects associated with those names. Now those objects have a property called "IsDynamic" and some of them have it set to false whie some of them have it set to true. So when I retrieve any object using the key property, it goes to find me that object. How do I override that find method?
[Code]...
View 6 Replies
Nov 3, 2011
I am trying to use a custom colour scheme for painting my menustrips, toolstrips etc. To do this, I am implementing a custom ToolStripProfessionalRenderer.
Normally i would simply set the renderer of each toolstrip etc. to a new instance of a ToolStripProfessionalRenderer instantaniated with a custom ColorTable i.e.
Dim myRenderer As ToolStripProfessionalRenderer = New ToolStripProfessionalRenderer(New MyColorTable)
View 3 Replies
Jan 5, 2009
I believe that the correct way to give a property a default value is to use the Default Attribute on the Property.[code]In the property window, the value that's displayed in a grid's property bag when it's newly dropped onto a form is False, not True. It does recognise that the default value should be True because it shows the value as bolded and then de-bolds it when we manualy set it to true - but it doesn't respect the default as the initial value. Is there any way of getting the property bag to respect the default value?
View 4 Replies
Aug 26, 2009
i would like to be able to set the change the default file location. for example if i do a filestream on a "file.txt", i want it to look by default in the desktop. is there somewhere in the settings of vb.net express 2008 where i can change this default location of working with files?
View 1 Replies
Jan 1, 2011
where can I find the default constructor of a windows form? I mean:
Public Sub New()
End Sub
I should say that I Use Visual Studio 2008 as my editor.
View 3 Replies
May 4, 2011
What is the best way to bind a property to a control so that when the property value is changed, the control's bound property changes with it.So if I have a property "FirstName" which I want to bind to a textbox "txtFirstName" text value. If I change FirstName to "Stack" the txtFirstName.Text also changes to "Stack".
View 1 Replies
May 3, 2012
I'm used to webdeveloping, and when I work with databases, I usually use some text for the Text-property of a radio button, and the row's ID as Value-property. This makes it very easy to save to databases.
Is the an equivalent in winforms for the Value-property, or will I have to identify rows based on the text in the control?
View 2 Replies
Feb 28, 2011
I have the following code on a form:
Public Sub Init(ByVal SelectedItems As List(Of Cheque))
Items = New BindingList(Of Cheque)(SelectedItems )
BindingSource1.DataSource = Items
[code]....
This code gets called like so:
...
fmEdit.Init(myList)
fmEdit.Show()
All variables are populated etc, it seems to go through the DataBindings.Add ok but when the form appears I get the error about unable to bind to a property or column called Id. I tried replacing the DataBindings.Add code to use the BindingSource1 instead of Items but I get a similar error.The names of the properties in the class match that of the name in the Databindings.Add code.
UPDATE: Here is my class:
Public Class Cheque
Public Id As String
Public Status As Byte
[code]....
View 1 Replies
May 5, 2011
I'm trying to create a button that will hide the panel that I have docked at the centre of my user control. [code]This works to an extent. However, when the bottomPanel is set to Fill it seems to fill the entire control, and not just up to toolStrip1. Can anyone tell me why this is happening, and how to correct it?
View 1 Replies
Jun 1, 2009
I have a WinForms dialog box that contains 3 radio buttons. I am using ApplicationSettings to bind the Checked property of each of these RadioButton controls, but it doesn't do what I am expecting it to do. Now I have to click each radio button twice before it gets checked and the selected radio button is not being persisted.Is there a line of code I need to execute when the form is closed that saves the user settings?How do I eliminate the need for 2x clicking on the radio buttons?Is there a better way to persist this type of user setting? I do have a public property on the dialog box class that gets/sets an enum value based on which radio button is checked, but I didn't see an easy way of binding that property to a user setting. Should have specified that I'm using vb.net. I think that means My.Settings instead of Properties.Settings.
View 4 Replies
Oct 7, 2010
For a given class, with a default property of list, you can access an instance object in the list by doing myClass.defProperty("key"). You can also achieve the same results by typing myClass.defProperty!Key.
I have been told that using the parenthesis and quotes is faster for the way the runtime accesses the Property, but I'd like to understand what is the difference and how do each work...
I understand C# has a similar behavior by replacing the parenthesis with square brackets.
View 1 Replies
Sep 27, 2011
Is there anyway to have a class that can return a default type without specifying the property.
If I had a class that had a few properties and one property returned a string value and others returned additional types, could I do the following?
Dim StudentGrade as new StudentGradeClass
'call and get default property
Dim CurrentGrade as string=StudentGrade
'instead of this
Dim CurrentGrade as string=StudentGrade.Current
The reason I am asking this is when I have classes that have other classes as properties and would like to just get a default return value,.
View 2 Replies
Mar 8, 2011
I'm attempting the following:Default Public Property Data(Of dataType)(ByVal key As String) As dataType
Get
Return DirectCast(values.Item(key), dataType)
End Get
Set(ByVal value As dataType)
values.Item(key) = value
End Set
End Property
[Code]...
It made more sense to make it a property, and it would be the default property of the class. The data type can not be specified on instantiation of the class, because it can contain multiple objects of different data types.
View 2 Replies
Oct 15, 2009
I'm attempting the following:
Default Public Property Data(Of dataType)(ByVal key As String) As dataType
Get
Return DirectCast(values.Item(key), dataType)
[code].....
View 2 Replies
Jan 5, 2012
I have a FontFamily property, but I don't know how set the default value:
Public UnitsFontFamilyProperty As DependencyProperty = DependencyProperty.Register("UnitsFontFamily", GetType(FontFamily), GetType(ValueAndUnit), New FrameworkPropertyMetadata(New
[Code]....
View 2 Replies
Jun 13, 2011
I'm converting Visual Basic.Net code to C# in my project. But I have some doubts on how to convert Visual Basic default property to C#. The first option that comes to me are the indexers. Lets imagine the next code in Visual Basic
Public Class MyClass
Dim MyHash as Hashtable
Public sub New()
[Code]....
View 2 Replies
Feb 19, 2010
I have a custom collection, lets says COL, that derives from ObjectModel.Collection. I have my own collection editor that works fine when a property, of type COL, is Read and Write enabled. However, if I change the property to ReadOnly, the open editor button stops showing in the property grid. As a test, I override my custom editor with the CollectionEditor, and that worked fine. So, my question is, what check is the property grid making, that CollectionEditor passes but my collection editor fails?
View 2 Replies
Dec 22, 2011
The following XAML produces an AmbiguousMatchException. The DataContext for myText is a DataTable consisting of > 1 row which contains a DataColumn named "test":
<TextBox Name="myText" Text="{Binding Path=Rows[0].Item[test]}"/>
When I modify the binding path syntax to the below example, the binding works as expected:
<TextBox Name="myText" Text="{Binding Path=Rows[0][test]}"/>
Given that the name of the DataTable is "myData", both of the following lines of code reference the contents of the column "test" on row 0:
myData.Rows(0)("test")
myData.Rows(0).Item("test")
Why doesn't the syntax that explicitly names the Item property appear to work in a binding scenario?
View 1 Replies
Jan 12, 2012
I am inheriting my own DataGridView (say MyDataGridView) from the standard DataGridView control. What I want is that certain properties of MyDataGridView should have a different default value than what its base have. For example, AllowUserToAddRows, AllowUserToDeleteRows, AllowUserToResizeRows properties should have the default values of False; so that when I drag MyDataGridView into a form in the IDE, the default values shown in the properties grid should be False. Later on, if I want to change them to True from the grid, they will be set accordingly.
View 1 Replies
Apr 2, 2010
I am new to classes, and I am new to Visual Basic in general, but I am working on a multi class program. The code seems to be correct, but I am trying on instantiate a class oject with the code:
View 3 Replies
Jul 4, 2012
I am making a new class that requires a lot of input information. Some of the properties need to be set to a default value, however I do not want to hard code them into the class.
What do you think would be the most efficient way to populate these properties?
I've been thinking of making a new class to hold all the default props and pass them as one object into the new class as a single argument but it seems kind of clunky.
View 2 Replies
Sep 16, 2009
Given a simple class like this:
Public Class clsOB
Implements System.ComponentModel.INotifyPropertyChanged
Private _Frequency As Double
Private _Value As Double
Public Event PropertyChanged(ByVal sender As Object, ByVal e As
[Code] .....
And then I'd like to do something like this:
Dim
o As
New
clsOB(50, 30)
o = 31
View 11 Replies
Mar 3, 2010
I have a class that has a readonly collection property - Its a list of extender providers that have been applied to the control.I've implemented a simple property descriptor for the collection so that the property can be expanded in the property grid to examine each entry.
When I select an extender provider and set it to false, I remove it from the collection. The GetProperties method of the type converter is requeried and the property grid refreshes.However, when I set an extender provider to true, and thus add it to the collection, GetProperties is not requeried.
Somehow, the property grid is making a distinction between adding to and removing from the collection. Or alternativly, its refreshing when an extender provider is added, but not when one is removed.
[Code]...
View 1 Replies
Mar 11, 2010
(I've answered the question below with a hack. I'm fairly confident in it unless MS change the way that codedom serializers the designer code.)ETA2:I've worked out what is going on. I wondered why sometimes it would work and not others. It boils down to the name that I give to the internal property and the collection.If I rename the property 'Annoyance' to 'WTF', it will serialize correctly because 'WTF' is, alphabetically, after the name of the collection - 'InternalAnger'.It looks like the serializer is creating instances of objects alphabetically and needs my internal property to be created by the time it comes to create the collection.I can fix this with a rename, but that's a hack and I fear that writing a custom serializer is a big job - which I've never done before.ETA: Jesus, I'm sick of this. This problem was specifically about persisting an interface collection but now on further testing it doesn't work for a normal collection. Here's some even simpler code:
Public Class Anger
End Class
Public Class MyButton
[code].....
View 4 Replies
Oct 19, 2009
I have a custom control with a bindable property:-
Private _Value As Object
<Bindable(True), ... > _
Public Property Value() As Object
Get
[code]....
Also, here, I'm adding a handler to the DataBindings.CollectionChanged event.This is the second place that I retrieve the type:-
Private Sub DataBindings_CollectionChanged(ByVal sender As Object, ByVal e As System.ComponentModel.CollectionChangeEventArgs)
If e.Action = CollectionChangeAction.Add Then
Dim b As Binding = DirectCast(e.Element, Binding)
[code]....
I need the first place, because the BindingContextChanged event is not fired until some time after InitializeComponent.The second place is needed if the binding field is programatically changed.Am I handling the correct events here, or is there a cleaner way to do it?
Note: My GetValueType method uses the CurrencyManager.GetItemProperties....etc, to retrieve the type.
View 1 Replies